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

Subsections


Solving Equations with Maple, Part II

Introduction

The purpose of this lab is to learn how to solve systems of equations using the Maple solve and fsolve commands.

Solving equations

Suppose we want to find the intersection point of two lines in the plane. If the lines are given in standard form: $Ax+By=C$, one way of finding their intersection point is to solve each equation for $y$ as a function of $x$, set them equal to each other and solve. Consider the two lines $2x+3y=7$ and $3x-y=1$. Below is how we can use the method described above in Maple.
> y1 := solve(2*x+3*y=7,y);
> y2 := solve(3*x-y=1,y);
> x_value := solve(y1=y2,x);
> subs(x=x_value,y1);
> subs(x=x_value,y2);
When asked to find an intersection point, you must remember not to just give the $x$ value, but you must also find the corresponding $y$ value. Note in the last two Maple lines above, the $y$ values were the same as they should be since it is a point of intersection. This same problem can be solved in a much simpler way using Maple's capabilities of solving more than one equation simultaneously. Assuming that we have the same number of unknowns as equations, the syntax for the solve command when solving systems of equations is the following:
> solve({equation1,equation2,equation3,...},{variable1,variable2,variable3,...});
The first argument of the solve command is the set of equations to be solved and the second argument is the set variables to be solved for. So, using the example above, we can find the $(x,y)$ coordinates of the intersection point of the two given linear equations as follows:
> solve({2*x+3*y=7,3*x-y=1},{x,y});
As you can see, this method only required one Maple command to get both the $x$ and the $y$ coordinates.

Solving multiple equations numerically

In the example above, we knew that there was only one intersection point since two lines can only intersect at a single point. More complex systems of equations may have more than one solution or no solutions at all. 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 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. The fsolve command has the same syntax as the solve 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$ values.
Suppose we want to find all 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 ... which means that it cannot be solved analytically. To solve numerically in Maple, you can try the following Maple procedure.

> plot({x^2-4*x-2,3*sin(x)},x=-5..5);
The plot shows that there are two intersection points. The commands below show how we can find both.
> 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 use of the ranges for the $x$ and $y$ values in the second argument of the fsolve command. If you do not use this command twice with different ranges, Maple will only yield one of the two solutions.

This last example shows a similar procedure using 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 specified for $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});
> fsolve({x*y-y^2+2=2*x^2-1,x/y+y=x*y},{x=-2..0,y=-1..0});

Exercises

  1. Find the intersection point of the two lines $-3x-10y=4$ and $x-6y=15$
    1. By first solving each equation for $y$.
    2. By solving them as a system of two equations and two unknowns.
  2. Find all points where the graph of $y=x+1$ intersects with the graph of $y=x^3/4-2 \sin(x)$.
  3. Find all points where the graph of the hyperbola $(x-2)^2-(y+1)^2=1$ intersects with the graph of the circle $x^2+y^2=4$.


next up previous
Next: About this document ... Up: lab_template Previous: lab_template
Dina Solitro
2001-10-30