Section 4: Solving Equations

© 2000 Seattle Central Community College. Reproduced with permission

In this section you will learn how to apply Maple's solve( ) command to find the exact solutions of equations (when this is possible). You may recall from Precalculus that we are not able in many cases to find exact solutions to equations and so we rely on numerical solvers to find approximate solutions. Later in this section you will use Maple's fsolve( ) command to find decimal approximations for solutions. The solution to linear systems of equations will also be discussed.

> restart:

> with(plots):

Warning, the name changecoords has been redefined

Entering and Manipulating Equations: The lhs( ) and rhs( ) commands

Example 1:

Recall that we can give a name to an entire equation just as we have done for expressions.

On the next line we enter the equation x^3-5*x^2+23 = 2*x^2+4*x-8 and give it the name "eqn1" .

> eqn1:=x^3-5*x^2+23=2*x^2+4*x-8;

eqn1 := x^3-5*x^2+23 = 2*x^2+4*x-8

Example 2:

We can isolate the left-hand and right-hand sides of the equation by using the lhs( ) and rhs( ) commands.

> lhs(eqn1);

x^3-5*x^2+23

> rhs(eqn1);

2*x^2+4*x-8

Example 3 :

Use the lhs( ) and rhs( ) commands to find an equation that is equivalent to the original equation eqn1 but has zero on the right-hand side. Label the new equation eqn2.

> eqn2:=lhs(eqn1)-rhs(eqn1)=0;

eqn2 := x^3-7*x^2+31-4*x = 0

Finding Exact Solutions: The solve( ) command

We first consider polynomial equations. Algorithms exist for calculating the exact solutions for polynomial equations up to degree 4 . Maple's solve( ) command implements these algorithms.

Example 1:

To find the exact solutions to the polynomial equation 3*x^3-4*x^2-43*x+84 = 0 use the solve( ) command.

Note that the second argument of the command tells Maple that x is the unknown variable that we are solving for.

> solve(3*x^3-4*x^2-43*x+84=0,x);

3, -4, 7/3

Here Maple has found all three solutions and listed them for you.

Example 2:

Sometimes you will want to select one solution from the list of solutions and use it in another computation. You can do this by first assigning a name (we use the letter N in this case) to the output of the solve( ) command. Then N[1] is the first number in the list, N[2] is the second number and so on. Note the square brackets.

> N:=solve(x^2-5*x+3=0,x);

N := 5/2+1/2*sqrt(13), 5/2-1/2*sqrt(13)

> N[1];

5/2+1/2*sqrt(13)

Example 3:

When working with the solve( ) command it is often convenient to begin by giving a name to the equation.

Note we use " := " to assign the name and just "=" for the equation itself.

> eqn1:=7*x^3-11*x^2-27*x-9=0;

eqn1 := 7*x^3-11*x^2-27*x-9 = 0

Next we solve the equation using the solve( ) command assigning the name H to the output.

> H:=solve(eqn1,x);

H := -1, 3, -3/7

For practice let's check that each of these values satisfies the equation. This is easy to do using the subs( ) command.

> subs(x=H[1],eqn1);

0 = 0

> subs(x=H[2],eqn1);

0 = 0

> subs(x=H[3],eqn1);

0 = 0

Example 4:

Sometimes the "exact" solutions are too cumbersome to be of much use. In the next two lines we solve the equation x^3-34*x^2+4 = 0 .

> eqn1:=x^3-34*x^2+4=0;

> H:=solve(eqn1,x);

eqn1 := x^3-34*x^2+4 = 0

H := 1/3*(39250+6*I*sqrt(117831))^(1/3)+1156/3/((39...
H := 1/3*(39250+6*I*sqrt(117831))^(1/3)+1156/3/((39...
H := 1/3*(39250+6*I*sqrt(117831))^(1/3)+1156/3/((39...

As you can see, reading these exact solutions is quite a challenge! Note that the I stands for sqrt(-1) . When a solution is this complicated it is more useful to look at the approximate solutions using evalf( ) : .

> evalf(H);

33.99653909+0.*I, -.3412885417+0.*I, .3447494457+0....

A good alternative to the solve( ) command in a situation like this is the fsolve( ) command which will be discussed in the next section.

The solve( ) command can also be used to find the exact solutions for non-polynomial equations. Some simple examples are listed below. However if the equations are at all complicated, for example combining exponential, polynomial and trigonometric expressions, then an exact solution will typically not be available. Again the fsolve( ) command is an alternative.

Example 5:

Solve the equation: 5*exp(x/4) = 43

> solve(5*exp(x/4)=43,x);

4*ln(43/5)

Example 6:

Sometimes Maple does not display all of the solutions. How would you use the result below to write down the entire set of solutions to the equation?

> solve(sin(x)=1/2,x);

1/6*Pi

Exercise 4.1

Solve the equation x^3-11*x^2+7*x+147 = 0. Why does Maple produce only two distinct solutions for this cubic equation? Why is one of them written twice? (HINT: Factor the left hand side of the equation.)

Student Workspace 4.1

>

>

>

>

>

Answer 4.1

> solve(x^3-11*x^2+7*x+147=0,x);

-3, 7, 7

> factor(x^3-11*x^2+7*x+147);

(x+3)*(x-7)^2

The fact that x - 7 is a repeated factor results in the cubic equation having only two distinct roots, -3 and 7. We say that root 7 has a multiplicity of 2 , meaning there are two factors of (x - 7) in the factored polynomial.

Finding Approximate Solutions: The fsolve( ) command

Maple's fsolve( ) command can be used to find approximate solutions for any equation. For polynomial equations fsolve() produces a complete list of all of the real solutions in one step (see Example 1). For other equations fsolve( ) can be used to get one solution at a time (see Examples 2 and 3).

Example 1:

Maple's fsolve( ) command will compute a numerical approximation for each of the real solutions of a polynomial equation. Approximate all real solutions for the equation: x^4-x^3-17*x^2-6*x+2 = 0 .

> eqn:=x^4-x^3-17*x^2-6*x+2=0;

eqn := x^4-x^3-17*x^2-6*x+2 = 0

> fsolve(eqn,x);

-3.414213562, -.5857864376, .2087121525, 4.79128784...

The four solutions listed above provide us with a complete list of the solutions to the given polynomial equation.

Example 2:

Find all real solutions of the equation x^3+1-exp(x) = 0 using the fsolve( ) command.

> eqn:=x^3+1-exp(x)=0;

eqn := x^3+1-exp(x) = 0

> fsolve(eqn,x);

0.

Maple returns one real solution. This time Maple has not given us the whole story. Are there any other solutions? How do we find them? A systematic procedure for finding the remaining solutions is presented in Example 3.

Example 3:

Find the other real solutions for the equation x^3+1-exp(x) = 0 .

The first step in finding the other solutions is to plot a graph of the left-hand side of the equation.

Key Concept : Recall that the x-intercepts of y = x^3+1-exp(x) correspond exactly to the solutions of the equation x^3+1-exp(x) = 0 .

> plot(x^3+1-exp(x),x=-3..5,y=-5..15);

[Maple Plot]

The graph shows four x-intercepts. One of these corresponds to the solution we found in Example 2. Which one?

The x=0 solution is also easy to spot. How do we find the other three?

We can extend the fsolve( ) command to look for a solution in a particular interval. For example to find the negative solution we ask Maple to search on the interval [-1, -.2] since we can see from the graph that there definitely is one (and only one) solution on that interval.

> fsolve(eqn,x=-1..-.2);

-.8251554697

To find the other two solutions we use fsolve( ) again, this time with search interval [1,2] and then with interval [4,5].

> fsolve(eqn,x=1..2);
fsolve(eqn,x=4..5);

1.545007279

4.567036837

What happens if you ask Maple to search for a solution on an interval where no solution exists ?

Let's try it out. From the graph it is clear that there are no x-intercepts (and therefore no solutions) between 2 and 4.

> fsolve(eqn,x=2..4);

fsolve(x^3+1-exp(x) = 0,x,2 .. 4)

Notice that Maple simply returns the original input line unchanged when it cannot find a solution on the given interval.

Are there any other solutions? For example, are there any solutions larger than 5 ? We can check this out by expanding the interval over which the graph is plotted. On the next line we expand the interval to [-3,50]. No other x-intercepts appear. The graph confirms what we should expect by looking at the terms of the expression, namely the exponential term dominates and causes the graph to go down in the long run.

> plot(x^3+1-exp(x),x=-3..50,y=-10..15);

[Maple Plot]

Alternatively we can use the fsolve( ) command, now searching over this larger interval.

> fsolve(eqn,x=5..50);

fsolve(x^3+1-exp(x) = 0,x,5 .. 50)

As expected no solutions are found by Maple.

In a similar way we can check for solutions to the left . Here we search for solutions over the interval [-50,-1] .

> fsolve(eqn,x=-50..-1);

fsolve(x^3+1-exp(x) = 0,x,-50 .. -1)

None there either !

We now have a complete list of the four solutions of our original equation x^3+1-exp(x) = 0 . They are: -.8251554597 , 0 , 1.545007279 and 4.567036837

Example 4:

Use fsolve( ) to find the approximate solutions of the equation : x^2/20-10*x = 15*cos(x+15)

Just as in the last example we will use a graph to help us determine the number and approximate location of the solutions. Our task is simplified if we start by converting the given equation to an equivalent one that has zero on the right-hand side.

So we will solve the equivalent equation : x^2/20-10*x-15*cos(x+15) = 0

If we now graph the left-hand side of this equation we once again will find solutions at each of the x-intercepts.

> eqn:=x^2/20-10*x-15*cos(x+15)=0;

eqn := 1/20*x^2-10*x-15*cos(x+15) = 0

> plot(lhs(eqn),x=-10..10);

[Maple Plot]

From the graph it appears that there is a solution on the interval [1,2].

We now direct Maple to search for a solution on this interval.

> fsolve(eqn,x=1..2);

1.274092075

Have we found all of the solutions to this equation? In fact there is another solution! To find it start by expanding the interval over which the graph is drawn. Then use fsolve( ) to find a numerical approximation for this second solution.

Exercise 4.2

Find all the solutions to the equation x^5-4*x^3+3*x^2+7*x-1 = 0 . Begin by looking at a relevant graph.

Student Workspace 4.2

>

>

>

>

>

Answer 4.2

We begin by graphing the left-hand side of the equation.

> eqn:=x^5-4*x^3+3*x^2+7*x-1=0;

eqn := x^5-4*x^3+3*x^2+7*x-1 = 0

> plot(lhs(eqn),x=-5..5,y=-5..5);

[Maple Plot]

This picture indicates that there are solutions near -2 , -1.5, and 0. We next try the unrestricted fsolve command to see which solution(s) Maple finds.

> fsolve(eqn,x);

-1.848049540, -1.293392663, .1363327046

Since this is a polynomial equation the fsolve( ) command gives us a complete list of the real solutions.

Exercise 4.3

Find all the solutions to the equation x^2-2 = ln(x+5) . Use the graph of one expression to locate the solutions. Check each solution by substituting it back in the original equation.

Student Workspace 4.3

>

>

>

>

>

>

>

Answer 4.3

First we put the equation in "standard form" , i.e. with zero on one side.

> eqn:=x^2-2-ln(x+5)=0;

eqn := x^2-2-ln(x+5) = 0

Now we can graph the right-hand side equation.

> plot(lhs(eqn),x=-10..10);

[Maple Plot]

There appear to be two solutions. One near -2 and the other near 2. Use fsolve with a restricted domain to find the two solutions you've located more precisely.

> soln1:=fsolve(eqn,x=-5..0);

soln1 := -1.780253527

> soln2:=fsolve(eqn,x=1..3);

soln2 := 1.985924818

Check by subsituting back into the original equation.

> evalf(subs(x=soln1,eqn));

-.1e-8 = 0.

> evalf(subs(x=soln2,eqn));

-.2e-8 = 0.

Notice that the original equation is only "approximately" satisfied by each of our solutions. The slight discrepancy is a result of round-off error in the approximate solutions.

Check that there are no additional solutions.

Exercise 4.4

The graphs of y = 10-x^2 and y = 4*sin(2*x)+5 intersect twice on the interval [-5,5].

a) Graph the two equations together and estimate the intersection points using the mouse.

b) Write an equation that can be solved to find the x-coordinates of the intersection points.

c) Use fsolve( ) to solve this equation.

d) Use the results from part c) to estimate the y-coordinates of the intersection points.

e) It appears that the curves may intersect at a third point near (1,9). Use fsolve( ) and/or a relevant graph to demonstrate that there is no intersection point at that location.

Student Workspace 4.4

>

>

>

>

>

>

>

Answer 4.4

> y1:=10-x^2;

y1 := 10-x^2

> y2:=4*sin(2*x)+5;

y2 := 4*sin(2*x)+5

Here is a plot of the two equations.

> plot([y1,y2],x=-5..5);

[Maple Plot]

Intersection points are located approximately at: (-1.8, 6.6) and ( 2.75, 2) .

b) The equation to solve is y1=y2.

> eqn:= y1=y2;

eqn := 10-x^2 = 4*sin(2*x)+5

c) We now find the two solutions using fsolve( )

> x_soln1:=fsolve(y1=y2,x=-4..0);

x_soln1 := -1.799064462

> x_soln2:=fsolve(y1=y2,x=0..4);

x_soln2 := 2.772938765

d) We can use the subs( ) command to find the corresponding y-coordinates.

> y_soln1:=subs(x=x_soln1,y1);

y_soln1 := 6.763367062

> y_soln2:=subs(x=x_soln2,y1);

y_soln2 := 2.310810606

So the points of intersection are : (-1.800,6.763) and (2.773,2.311)

e) Here is a closer look at what is happening near x=1.

> plot([y1,y2],x=.5..1.5);

[Maple Plot]

Alternatively we can use fsolve( ) to confirm that there is no solution near x=1.

> fsolve(y1=y2,x=.5..1.5);

fsolve(10-x^2 = 4*sin(2*x)+5,x,.5 .. 1.5)

Solving Literal Equations

> restart:

Often Maple can solve literal equations for any one of the variables.

Suppose we want to solve for the variable g in the equation: 4-v = 2*T-k*g .

The solve command works well here.

> solve(4-v=2*T-k*g,g);

(-4+v+2*T)/k

Here is a little nicer way of displaying the same result:

> g=solve(4-v=2*T-k*g,g);

g = (-4+v+2*T)/k

Exercise 4.4

Edit the last command to solve for each of the other letters T, k and v.

Student Workspace 4.4

>

>

>

>

>

Answer 4.4

> T=solve(4-v=2*T-k*g,T);

T = 2-1/2*v+1/2*k*g

> k=solve(4-v=2*T-k*g,k);

k = (-4+v+2*T)/g

> v=solve(4-v=2*T-k*g,v);

v = 4-2*T+k*g

Exercise 4.5

Solve the equation x^2+y^2 = 9 for y . Assign the set of solutions to a variable named S. How are the two solutions S[1] and S[2] related ?

Student Workspace 4.5

>

>

>

>

>

Answer 4.5

> S:=solve(x^2+y^2=25,y);

S := sqrt(25-x^2), -sqrt(25-x^2)

> S[1];

sqrt(25-x^2)

> S[2];

-sqrt(25-x^2)

The solution S[1] is the negative of solution S[2].

Solving a Linear System of Equations using the solve( ) command

Please execute the next two lines before proceeding:

> restart:

> with(plots):

Warning, the name changecoords has been redefined

The solve( ) command can also be used to solve a system of m linear equations in n variables. We call these m by n linear systems for short.

Example 1:

Solve the 2 by 2 system: 3*x+2*y = 3 and x-y = -4

> solve({3*x+2*y=3,x-y=-4});

{y = 3, x = -1}

A graph of the two underlying functions shows the solution corresponds to the point of intersection at (-1,3). But we first need to find the explicit form for each of the linear functions before we can graph them. So we solve each equation for y.

> y1:=solve(3*x+2*y=3,y);

y1 := -3/2*x+3/2

> y2:=solve(x-y=-4,y);

y2 := x+4

Now we construct a picture made up of two parts: "part1" contains the graphs the two equations and "part2" plots the solution point that we found. This point should be the intersection point of the two lines. Is it ?

> part1:=plot([y1,y2],x=-5..5):

> part2:=plot([[-1,3]],style=point,color=blue,symbol=circle):

> display([part1,part2]);

[Maple Plot]

Example 2:

Here is an example of the solution of a 3 by 3 system with variables x, y, and z.

Solve the 3 by 3 system: {x+y+z = 1, 3*x+y = 3, x-2*y-z = 0}

> solve({x+y+z=1, 3*x+y=3, x-2*y-z=0});

{y = 3/5, z = -2/5, x = 4/5}

Exercise 4.6

Find the solution to the system:

4*x+3*y = 12 and 5*x-7*y = 35

Check by subsitituting the solution pair in both equations in the system

Student Workspace 4.6

>

>

>

>

>

>

Answer 4.6

> eqns:={4*x+3*y=12, 5*x-7*y=35};

eqns := {4*x+3*y = 12, 5*x-7*y = 35}

> ans:=solve(eqns);

ans := {x = 189/43, y = -80/43}

> subs(x=189/43,y=-80/43,eqns);

{12 = 12, 35 = 35}

Linear Systems with an Infinite Number of Solutions (Optional)

When a system has more variables than equations we often get not one, but an infinite number of solutions.

Here is an example.

Example 1:

Solve the system : {x+y+z = 1, 3*x+y = 3} .

> solns:=solve({x+y+z=1, 3*x+y=3});

solns := {y = y, x = 1-1/3*y, z = -2/3*y}

Notice this time we do not get a single set of numerical values for x, y and z. Instead Maple tells us how the values of x, y and z must be related to construct a typical solution.

In particular the expression x = x in the output above indicates that x can be any number. We refer to it as the "free" variable in the solution. To find any particular solution (among the infinte number possible) pick any value for x and use this to calculate the corresponding values for y and z. For example let x = 4.

> subs(x=4,solns);

{y = y, z = -2/3*y, 4 = 1-1/3*y}

So one solution is : x=4 , y= -9 and z=6. Take a minute and check by hand that these three numbers do in fact satisfy our original equations : x+y+z = 1 and 3*x+y = 3 .

Now let's look at the solution that is generated when we take x=2.

> subs(x=2,solns);

{y = y, 2 = 1-1/3*y, z = -2/3*y}

So two of the infinitely many solutions are: (x,y,z) = (4, -9, 6) and (2, -3, 2).

Exercise 4.7

Solve the system : {x+2*y+z = 2, 3*x+y = 1} and find at least three particular solutions.

Student Workspace 4.7

>

>

>

>

>

Answer 4.7

> eqns:={ x+2*y+z=2 , 3*x+y=1 };

eqns := {3*x+y = 1, x+2*y+z = 2}

> soln:=solve(eqns);

soln := {y = y, x = 1/3-1/3*y, z = 5/3-5/3*y}

Here are the solutions for x = 1, 2, 3, and 4 :

> subs(x=1,soln);

{y = y, z = 5/3-5/3*y, 1 = 1/3-1/3*y}

> subs(x=2,soln);

{y = y, 2 = 1/3-1/3*y, z = 5/3-5/3*y}

> subs(x=3,soln);

{y = y, z = 5/3-5/3*y, 3 = 1/3-1/3*y}

> subs(x=4,soln);

{y = y, z = 5/3-5/3*y, 4 = 1/3-1/3*y}

 

Table of Contents

Section 5: Functions: Defining, Evaluating and Graphing

Maple Quick Reference Card

Notes on the Maple Worksheet Interface