# CS310 Team Lab #12Solving Systems of EquationsSymbolic Computing

## OBJECTIVES

• Learn how to use Maple's solve command to solve a system of equations (solve n equations for n unknowns).
• Learn to use Maple's implicitplot command to plot equations.
• Learn syntatic and the semantic difference between a set and a list in Maple.
• Learn the advantages of grouping equations under one name.
• Learn how to plot in 3D space.

## INTRODUCTION

In this lab we study Maple's ability to solve systems of algebraic equations. Solving systems of algebraic equations (either linear equations or non-linear equations) is fundamental to engineering science. There are often circumstances where only two or three equations with two or three unknowns are used to describe a problem. In this case, the solutions can be conveniently interpreted graphically. Each equation describes either a line, a curve, or a surface and the solution to the set of equations is the point(s) of intersection.

## Problem 1: Two equations and two unknowns

3x + 4y = 5
y = x2 - 3x

1. Enter these into Maple as eq1 and eq2.

2. Use the implicitplot command (after using with(plots)) to plot the two equations over the range x = -1..3, y=-3..2. From the graph you should be able to see that there are two points of intersection.  What is the graphic interpretation of each equation?

3. Use the solve command to determine the points of intersection, (x1, y1) and (x2, y2). What happened?  Does using the allvalues command help? What are the two intersection points? Place the coordinates for the left-most intersection point in a variable named leftPoint and coordinates for the right-most point in a variable named rightPoint.

4. Enter this new equation and name it eq3: y = x2 - 3x - cos(x+2)

5. Plot equations eq1 and eq3. You should notice two points of intersection.

6. Symbolically solve the new system (eq1 and eq3) of equations for (x, y) to find the points of intersection. Try allvalues if solve alone doesn't work.

7. Numerically solve for the two points of intersection and label them leftPointNum and rightPointNum.

Show a Lab TA your symbolic solution (1.f) and your numeric solution (1.g) to this problem.
What's the difference between the two solutions?

## Problem 2: 3D graphical solutions and plotting

Now let's move on to planes in space. Planes can be described by linear equations with one, two, or three unknowns. Three different planes are described by these three linear equations when they are interpreted and thus plotted in 3-D space:

x + y = 2z
x = 2
y + x = 1

1. Clear your Maple worksheet variables by entering the restart command. The commands and their results will still be visible, but the defined variable set that Maple understands will have been cleared.  Enter the three equations above into Maple as eq1, eq2, and eq3.  Group the three equations together as a sequence (do not include group( ), set { }, or list [ ] notation) and call them eqs.

2. Use the implicitplot3d command (after using with(plots)) to plot the three equations (planes) and visualize the intersection. Use the left mouse button to rotate the figure.

Read the help information for the implicitplot3d command.  Can you color each plane a different color? Hint: use a list of equations and a list of colors in the command. Use the right button on the mouse to explore displaying axes and the different projections. Type options into the plot command if you don't want to lose them when the worksheet is re-executed (e.g., axes = boxed, color = [red,green,blue]).

3. Find the (x, y, z) point of intersection.

## Problem 3: Three quadratic equations and three unknowns

Now we will investigate the solution of three quadratic equations and three unknowns. The three quadratic equations represent three different curved surfaces in 3D space.

1. Enter these equations and assign names to each.

x2 + y2 + z2 = 4
(1/3)x2 + (1/2)y2 - z2 = 1
x2 - y2 + z2 = 1

The three quadratic equations have eight solutions (eight sets of (x, y, z) triplets). That is, there are eight points that are on the intersection of these three surfaces.

2. Plot each of these curved surfaces by itself.

3. Plot all three surfaces on the same figure.  Use a range of -3 to 3 for each variable. Change the color scheme to make it easier to see the points of intersection. Try plotting each surface using a different color.  Use a list of colors as you did with the plot command. Making one of more of the surfaces a little transparent may also help, (e.g. transparency = [0, 0.5, 0]).

4. Find the exact values for the eight intersection points.  Be sure to solve symbolically to see the pattern to the eight roots. What is the pattern to the roots? Does this pattern make sense? Hint: You might need to use the allvalues command to get a final answer.

Show your solution for the exact values of the intersection points to a Lab TA.

## Problem 4: Contour plots and density plots

Often it is useful to plot mathematical functions to better understand their properties. This is particularly important when the function has more than one independent variable.

1. Use plot3d to plot the following expression. A good range would be -π to π for both x and y.

expr1 := cos(x) * cos(y)

2. Plot the expression using the densityplot command and the contourplot command.

3. Read the on-line help for plots and densityplot (avoid the Statistics, DensityPlot version of help). At the bottom of each description in the on-line help are examples of how the command can be used.  Use these examples to guide you as you experiment with options for color and grid for plot3d, colorstyle for densityplot, and coloring and filled=true for contourplot.  Discuss what each plot command is doing.

## Problem 5: Animate your plot

You can add a variable to your plot commands and then animate the plot based on that variable. Try commands like this to animate ranges of the plots from Problem 4:

animate(plot3d, [expr1, x=-P..P, y=-P..P], P=0..-Pi, axes=box)

To run the animation: click somewhere in the plot, then locate and try out the animation control buttons that appear at the top of the worksheet.

# Other Interesting 3D plots

## Problem 6: Mapping onto three-dimensional surfaces

Look at the plot by entering and executing the commands below:

surface := [ u*sin(u)*cos(v) , u*cos(u)*cos(v), u*sin(v) ]:
plot3d(surface, u=0..10, v=0..Pi)

What it does is map a rectangular region in (u, v) space (the region with u between 0 and 10 and v between 0 and π) into (x, y, z) space to form a surface.  The list surface gives the three-dimensional point that is the image of (u, v).   Be sure to rotate the plot to see the spiral shape.

By changing the limits (for example, to u=0.5..10 or v=0.5..Pi) you can find where the sides of the (u, v) rectangle map into the spiral surface. This command will animate the range of v. See if you can change it to animate the range of u

with(plots): animate(plot3d, [surface, u=0..10, v=A..Pi], A=0..Pi)

Another thing you can do is to add color=u or color=v to see how u and v map to the surface.

Also consider the following plots, modified from an example on the help pages for plot3d. The two plot commands show the uses of sets and lists.

tube1 := [ cos(u) - 2*cos(0.4*v), sin(u) - 2*sin(0.4*v), v  ] :
tube2 := [ cos(u) + 2*cos(0.4*v), sin(u) + 2*sin(0.4*v), v  ] :
tube3 := [ cos(u) + 2*sin(0.4*v), sin(u) - 2*cos(0.4*v), v  ] :
tube4 := [ cos(u) - 2*sin(0.4*v), sin(u) + 2*cos(0.4*v), v  ] :

plot3d( {tube1, tube2, tube3, tube4}, u=0..2*Pi, v=0..12, grid=[25, 15], style=patch, color=sin(u+v) )

plot3d( [tube1, tube2, tube3, tube4], u=0..2*Pi, v=0..12, grid=[25, 15], style=patch, color=[blue, green, yellow, magenta], plotlist )

Change the color specifications and other parameters to see how they work.  The style can be changed to patchnogrid and wireframe to get different views of the surface.

## Problem 7: Create your own interesting functions z = f(x, y) and plot them

Create your own interesting functions z = f(x, y) and plot them using the plot3d, contourplot, and densityplot commands.  Here are a couple to get you started:

expr2 := cos(x*y/2) * sin((x^2 - y^2)/2)
expr3 := sin(x)^2 + cos(y)^2