next up previous
Next: About this document ... Up: lab_temp Previous: lab_temp


Solving Equations and Systems of Equations

Solving Equations

The best method for solving equations is to use Maple's solving capabilities. First, a plot of the function or expression is useful then you can use the Maple solve command. The following illustrates how to find the roots of a function.

f(x) = 2x^3-5x^2-2x+5

> f := x-> 2*x^3-5*x^2-2*x+5;
> solve(f(x)=0,x);
If you forget to type in an equation and only type in an expression without setting it equal to something, Maple automatically sets the expression to zero. In the examples below, you can see some of the solving capabilities of Maple.
> plot({x^2+2*x-1,x^2+1},x=-2..2);
> solve(x^2+2*x-1=x^2+1,x);
Unfortuately, many equations cannot be solved analytically. For example, even the relatively simple equation sin(x) = x/2 has no analytical solution. In this case, the only possibility is to solve it numerically. In Maple, the command to use is fsolve. When the solve command is used the output looks like:
> solve(sin(x)=x/2,x);
This is not incorrect, as some of the zeros of a function may be imaginary and others may be real. However, it is much better to solve numerically as shown below:
> fsolve(sin(x) = x/2, x);
A plot of both equations on the same graph will show that this solution is not complete. There are two other intersection points that the fsolve command did not output. The fsolve command allows us to solve the equation in a range of x values by replacing the second argument with what looks like a plot range. This method only works for the fsolve command and not for the solve command.
> plot({sin(x),x/2},x=-2*Pi..2*Pi);
> fsolve(sin(x)=x/2,x=-3..-1);
> fsolve(sin(x)=x/2,x=-1..1);
> fsolve(sin(x)=x/2,x=1..3);
Once you have solved an equation, you may want to use the output or the solution later. In order to label the output to a solution, you need to assign a label in the same line as the solve or fsolve command. For example:
> expr2:=x^2+2*x-5;
> answer:=solve(expr2=0,x);
> evalf(subs(x=answer[1],expr2));
Here an expression was defined first and then the solution was assigned to the label ``answer''. Note that there was more than one solution. In order to substitute tha answer that was listed first back into the expression, the subs command was used and [1] was added onto the variable name to distinguish the first solution from the second.

Solving Systems of Equations

Maple can solve systems of equations using the solve command. The equations listed within the command are enclosed by curly brackets. The variables to be solved are also enclosed in curly brackets. As an example:
> solve({3*x+5=y,7*x+9*y=14},{x,y});
As an additional example, suppose you wanted to find the equation of the parabola that went through the points (-3, 2), (19, -19), and (0, -2.397). The first step is to set up a general equation for a parabola. the idea is to find the values of a, b, and c.
> p:=y=a*x^2+b*x+c;
The next step is to set up your three equations by using the three points on the parabola.
> eq1:=subs({x=-3,y=2},p);
> eq1:=subs({x=19,y=-19},p);
> eq1:=subs({x=0,y=-2.397},p);
The next step is to solve for a, b, and c.
> solution:=solve({eq1,eq2,eq3},{a,b,c});
We can get an equation for our parabola with the following substitution:
> parabola:=subs(solution,p);
> with(plots):implicitplot(parabola,x=-20..80,y=-20..35);

Solving Systems Numerically

Some systems of equations may have more than one solution or no solution. In most cases it is important to plot the equations on the same graph to first know the number of intersection points. The plot command can be used if the equations are explicit and the implicitplot command can be used if they are implicit. (In this case remember to load the plots package in Maple).

Also, recall that not all the equations can be solved analytically. When the solve command yields a strange looking answer, it does not necessarily mean that there are no solutions. You may have to solve the equations numerically by using the fsolve command. However it does not always yield all solutions at once. If your plot indicates that you have more intersection points than what the fsolve command has shown, then you must solve for each solution separately using ranges of x and y to tell Maple where to look for the solutions. Suppose we want to find the intersection points of $y = x^2-4x-2$ and $y = 3\sin(x)$. You would find that if you try to use the solve command you would get an answer involving Root of.... One way to get around this complex output is to solve numerically in Maple using fsolve.

> plot(x^2-4*x-2,3*sin(x)},x=-5..5);
The plot shows that there are two intersection points. The fsolve command finds them:
> fsolve({y=x^2-4*x-2,y=3*sin(x)},{x=-2..0,y=-10..10});
> fsolve({y=x^2-4*x-2,y=3*sin(x)},{x=0..5,y=-10..10});
Note the ranges used for the x and y values in the second argument of the fsolve command. Each time the fsolve command is used the x and y ranges are adjusted so that one of the intersection points is within the range.

This last example shows a similar procedure using the implicit equations. Suppose we want to know where the graph of the equation $xy-y^2+2=2x^2-1$ intersects with the graph of $x/y+y=xy$. First a plot would be necessary to determine the number of intersection points, then the fsolve command can be used with ranges specific to x and y.

> with(plots):
> implicitplot({x*y-y^2+2=2*x^2-1,x/y+y=x*y},x=-5..5,y=-5..5);
> fsolve({x*y-y^2+2=2*x^2-1,x/y+y=x*y}, {x=-2..0, y=0..1});


  1. For the functions

f(x) = 7\sin(\frac{x}{2})+3

g(x) = x+2

    1. First enter the two as functions.
    2. Plot the two on the same graph using an x-domain that clearly shows all the intersection points.
    3. Find the x-values of the intersection points assigning a label to each.
    4. Find the y-values of the intersection points. Check that both functions give you the same y-values for a single x-solution.
    5. What are your intersection points?
  2. The general equation of an ellipse is


    Find the equation of the ellipse that pases through the two points $(-3.56, -2)$ and $(0,5)$. Use the implicitplot command to plot the ellipse. (Hint, all four of the solutions that you get will give the same equation due to the squaring in the equation). What is the equation of the ellipse that you found?

next up previous
Jane E Bouchard