You are on page 1of 37

(extret de Maple Essentials, a: http://www.math.fsu.edu/%7Equine/IntroMathBio_04/Maple_essent_tut/CourseStart.

html )

Introduction to the Tutorial


2000 Seattle Central Community College reproduced with permission

This Tutorial has been designed by the Mathematics Department at Seattle Central Community College, to give you a complete hands-on introduction to the basic commands that you will need to use Maple effectively. The six sections of the tutorial will step you through each topic with many opportunities for you to practice and experiment with Maple. Note: This tutorial was developed to provide a thorough and efficient introduction to Maple for students about to enter a Calculus course. Therefore the tutorial only assumes familiarity with mathematics at the precalculus level. Each section of the tutorial has the same basic outline: Examples : a sequence of short, completely worked out examples that illustrate each new command. Exercises : short practice problems based on the material from the section. When you have worked through Sections 1-6 continue on to the Practice Problems. These problems will give you an opportunity to try out the full range of Maple commands that you have learned in the Tutorial. By the time you complete these problems you will be ready to use Maple effectively in your math class. At the end of the tutorial you will find a section entitled "Maple Quick Reference Card" . You may find it convenient to print out the contents of this section so that you can have a convenient reference to the syntax of the commands that you will learn in the tutorial. The Sections 1 - 6 of the tutorial focus on essential Maple commands. For details on the worksheet interface see the last section Notes on the Worksheet Interface.

Table of contents
Section 1: Section 2: Section 3: Section 4: Section 5: Section 6: Numerical Calculations Algebraic Calculations Graphing Solving Equations Functions: Defining, Evaluating and Graphing More on Graphing

Practice Problems Maple Quick Reference Card

Section 1:Numerical Calculations


In this section you will use Maple to do some standard numerical calculations. Maple's ability to produce exact answers in addition to numerical approximations gives you more options in solving problems.

Doing Exact Arithmetic with Maple


Using Maple to do numerical computations is very straightforward. Just enter the numerical expression and end the line with a semicolon. Pressing [Enter] will then execute the line and the result will be displayed in blue in the center of the screen. Example 1: A simple calculation has been entered on the next line. Click anywhere in the red line and press [Enter]. > 2+4; > 12*34567890; Each red input line is "live" and can be modified at any time. Change the "4" in the line above to an "8" and press [Enter]. Notice how the blue output is automatically updated to display the new result. Example 2: For our next example let's calculate . > 134^39; > Unlike your calculator, Maple gives you the exact answer to this problem, all 83 digits worth! Example 3: Maple can calculate with fractions without converting to decimals: > 3/5 + 5/9 + 7/12; > Example 4: To enter the square root of a number use sqrt( ) : > sqrt(24); but has left the answer in exact form. In the next Notice that Maple has simplified section you will learn how to get a decimal approximation for this number. Example 5: Maple has all of the important mathematical constants built in. To enter

type Pi.

Notice that an asterisk * is required to indicate multiplication. > 4*(3+Pi); Again Maple carries out the calculation but leaves the answer in exact form.

Example 6: Unlike your calculator, Maple gives you the exact answer when applying trigonometric functions. > sin(5*Pi/3); > sec(Pi/4); To get the inverse sine of a number use the arcsin( ) function: > arcsin(-1); If you ask Maple to calculate a value that is undefined it will respond with an error message: > tan(Pi/2); Example 7: in Maple type: exp(x) . To enter the natural exponential function > exp(x); And to get the number e by itself type: exp(1) . > exp(1); > Example 8: To enter the absolute value function in Maple type: abs(x). Note that Maple gives the correct, exact answer for the third line since: > abs(x); > abs(-3); > abs(exp(1)-Pi); Example 9: Maple has many special purpose commands for working with numbers. You will learn these as you need them in your math course. Here is one last example for now. If we have an integer and want to factor it into primes we can use Maple's ifactor( ) command. Feel free to experiment by changing the number. > ifactor(31722722304); > Example 10: There may be times when you want to enter more than one command on a single line. This is okay to do in Maple, just be sure to end each command with a semicolon. It also helps to put spaces between the commands. When you press [Enter] all of the expressions are executed and the results are listed, in order, in a single output field. > sin(Pi/3); cos(Pi/3); tan(Pi/3); > Example 11: To calculate and display a sequence of numbers use the seq(..) command. Here we calculate the squares of the first 100 natural numbers. > seq(k^2,k=1..100); >

Numerical Approximations using the evalf( ) command


Recall that in the previous section we asked Maple to add three fractions and the result was also displayed as a fraction. This sort of exact arithmetic is very useful but there are times when we prefer an answer in decimal form. The Maple command evalf( ) performs this task for us. Example 1: Compare the results of the next two lines. > 3/5+5/9+7/12; > evalf(3/5+5/9+7/12); > Example 2: Assigning a name to the result of a calculation makes it easier to use that result in a subsequent calculation. To assign a name we use a colon followed by an equal sign ( i.e. name := result ; ) . On the next line we have assigned the letter k to the original output to k. above. Then we apply > k:=3/5+5/9+7/12; > evalf(k); > Important Maple Note: Maple is case sensitive. So for example Maple considers k and K to be different variables.. > k; > K; By the way you can also use words as variable names. > joe:=2^5; > sqrt(joe); Example 3: If we want fewer or more digits of accuracy than the default number which is 10 digits we can add an extra argument to the evalf( ) command as shown below. > w:=4*(3+Pi); > evalf(w); > evalf(w,4); > evalf(w,45); > Example 4: If you enter numbers with a decimal point Maple automatically gives decimal results. Compare the results of the two lines below. > sqrt(34); > sqrt(34.0); Here is another example: > 4-1/3; > 4.0-1/3; >

Example 5: We can apply the evalf( ) command to a sequence of numbers. Below we first generate the exact square roots of the first 10 natural numbers, then apply evalf to get decimal approximations. > result:=seq(sqrt(k),k=1..10); > evalf(result); > Maple Shortcut: Quick reference to last output There will be many times when using Maple that you will string together a sequence of computations. Rather than giving a name to each result as you go along, you can use the percent sign ( % ) to refer to the last expression computed by Maple. Here are some examples of how it works. > 3/5+5/9+7/12; > evalf(%); > Pi; > evalf(%); > %+5; > For more on using the ditto symbol see Exercise 1.4 below. Exercise 1.1 Use Maple to calculate the number Answer 1.1 > 37^43; .

Exercise 1.2 to 18 digits. Calculate Answer 1.2 > m:=sqrt(34); > evalf(m,18); > Exercise 1.3 Find a numerical approximation for the expression : Answer 1.3 > answer:=(3+Pi)/(7-sqrt(13)); > evalf(answer);

Exercise 1.4 The percent sign ( %) is a handy shortcut but it can occasionally lead to some unexpected results. Here is an example. First execute each of the next three lines. You should be able to predict the result in advance. > 4+Pi; > evalf(%); > %+10; > Now go back and re-execute the last line (i.e.%+10;). Note that the output changes from to Can you explain why? Answer 1.4 The ditto symbol (%) represents the last number calculated by Maple. So after you executed the first three lines %= . The second time you executed the line %+10; Maple added 10 to . To avoid this sort of confusion assign names to each output: > a:=4+Pi; > b:=evalf(a); > b+10; >

Clearing Variables
Once you have defined a variable, Maple will remember its value during your entire working session. If you want to overwrite the variable with a new value, you can simply make a new assignment. For example each assignment below redefines the value of the variable h. (Note: to check the current value for a variable just type it followed by a semicolon.) > h; > h:=56; > h; > h:=sqrt(Pi); > h; Sometimes you will want to "clear" a variable in memory so that you can use it in a new situation. Here is an example. First we assign x the value 65. > x:=65; Now assume that we start a new problem and want to enter the general algebraic expression and assign it the name w. If we just enter this, Maple automatically substitutes the previous value for x.

> w:=x^2-4*x+7; In order to get x to be a general variable again we must first "clear" (i.e. erase from Maple's memory) our earlier value for x. This is accomplished by entering x:='x'; Note that we use single quotes here. Execute the next two lines to see how this works. > x:='x'; > w:=x^2-4*x+7; Clearing all variables at once: the restart command. The restart command will clear Maple's memory of all definitions that you have made. It is like starting a new Maple session. If you are starting a completely new problem you can use the restart command to guarantee that there are no leftover definitions from your earlier work. Before you execute the second line below, quickly predict the output. > p:=4; > p; x; h; You probably remembered that p was 4 and x had been reassigned to be the variable x, but you may not have remembered that h was assigned the value . That's why it's a good idea to use restart to remove all definitions at once. (As you work through this tutorial you will notice that we start most new sections with a restart command.) > restart; > p; x; h; >

Section 2: Algebraic Calculations


Maple is a "C.A.S" , i.e. a Computer Algebra System. This means that Maple knows every rule of algebra that you know. As you progress through Calculus, Differential Equations and Linear Algebra you will find that Maple also has the essential operations from those subjects built into its large command set. In this section you will learn how to enter an algebraic expression and substitute values in for the variables. Then you will learn the commands that allow you to expand, factor and simplify expressions. > restart; >

The subs( ) command


Example 1: For our first example let's start with the expression and assign it the name W. > W:=3*x^2+8; Suppose now that you want to substitute the value 4 for x in the expression . The quickest way to do this is to use Maple's subs( ) command. Here's what it looks like: > subs(x=4,3*x^2+8); Alternatively you can apply the subs( ) command to W. > subs(x=4,W); Example 2: The subs( ) command works equally well with symbolic values: To replace x by in the expression execute the following line. In this case we label the result M. > W:=3*x^2+8; > M:=subs(x=5+2*u,W); And now to get Maple to "multiply out" this expression we use the expand( ) command. > expand(M); Example 3: The subs( ) command is very versatile. You can use it to evaluate expressions involving more than one variable. Here we replace by 7 and y by 12 in the expression . > U:=(2/5)*x^2+3*y; > subs(x=7,y=12,U); > evalf(%);

Example 4: You can also use the subs( ) command to substitute a value into an equation. This is the sort of thing you might want to do to test whether a particular value "satisfies" the equation. In the next few lines we substitute different values into the equation . Are any of these values a solution to the equation? Note we use " := " to assign the name and just "=" for the equation itself. > eqn:=x^3-5*x^2+7*x-12=0; > subs(x=3,eqn); > subs(x=4,eqn); > subs(x=5,eqn); > Exercise 2.1 Assign the name k to the expression expression . . Then assign the name M to the

Finally have Maple calculate . Note: to get Maple to multiply the expression out use the expand( ) command. That is enter: expand(3*M+6); You will learn more about the expand command in the next subsection. Answer 2.1 > k:=x^2+4*x-3; > M:=k^2-9; > 3*M+6; > expand(3*M+6); > Exercise 2.2 Expand using the expand( ) command. Answer 2.2 > w:=(1+x)^4; > expand(w); or we can do this all in one step with: > expand((1+x)^4); > Exercise 2.3 Let . Answer 2.3 > P:=a*x^3+b*x^2+c*x+d; > subs(x=0.01,a=-1/5,b=2/5,c=0,d=13/15,P); . Find P if x = 0.01 , a = , , , and

Exercise 2.4 Use the subs( ) command to check if any of the numbers: 1,2 or 3 is a solution to the equation: Answer 2.4 > eqn:=x^3-16*x^2+51*x-36=0; > subs(x=1,eqn); > subs(x=2,eqn); > subs(x=3,eqn); > Therefore x=1 and x=3 are solutions of the equation. (In Section 5 you will learn how to solve equations using Maple.)

The expand( ) command


The principal use of the expand( ) command is to "multiply out" products of polynomial expressions. It can also be used to expand trigonometric and other more general functions. Example 1: Use the expand( ) command to multiply out > k:=(x+2)^2*(3*x-3)*(x+5); > expand(k); Example 2: Maple applies some familiar trigonometric identities to expand and . > expand(sin(2*x)); > expand(cos(2*x)); Try expanding the sine and cosine of some other integer multiples of x. For example: , , etc. Example 3: Here is a final example. Have Maple multiply out the expression: > h:=x^(1/2)*(x^(3/2)+x^(-1/2)); > expand(h); > Exercise 2.6 Expand for n =2,3 and 4.

Answer 2.6 > expand((x+1)^2); > expand((x+1)^3); > expand((x+1)^4);

The factor( ) command


Example 1: Factor the expression: > w:=3*x^2-10*x-8; > factor(w); Or you can do it all on one line: > factor(3*x^2-10*x-8); Example 2: First expand the expression

. Then apply the factor( )

command to the result. Can you explain why the final result looks different than the original expression ? > H:=2*(x-2)*(2*x^2+5*x+2)*(x+4); > ans:=expand(H); > factor(ans); Example 3: Maple can factor expressions with more than one variable. Factor the expression: > h:=x^2*y+2*x*y+y; > factor(h); Example 4: If Maple can't factor an expression using rational numbers (i.e. integers and fractions) then it returns the input unchanged. > factor(3*x^2-10*x-9); Example 5: The factor command is not limited to polynomials. It can be used to factor other forms. . Factor > factor((sin(x))^2-(cos(x)^2)); Example 6: If the factor command is used with a rational expression, the numerator and denominator are each factored and common factors are cancelled to simplify the expression: > A:=(x^3-7*x^2+15*x-9)/(x^2+4*x+4); > factor(A); > B:=(x^3-7*x^2+15*x-9)/(x^2-4*x+3); > factor(B); The next example allows you to see the factored form without cancellation.

Example 7: Maple's numer( ) and denom( ) commands allow you to isolate either the numerator or denominator of a fraction. Here we use these commands to examine the factors of the numerator and denominator separately (i.e. before cancellation of common factors). > B:=(x^3-7*x^2+15*x-9)/(x^2-4*x+3); > factor(numer(B)); factor(denom(B)); Exercise 2.8 Factor the expression Answer 2.8 > factor(3*x^4-2*x^3+22*x^2-18*x-45); Exercise 2.9 Factor the expression Answer 2.9 > ww:=x^(1/2)-x^(3/2); > factor(ww); > expand(%); and then use the expand command to check the result. .

The simplify( ) command


Example 1: Consider the expression . Maple can

apply identities to simplify many lengthy mathematical expressions, such as trigonometric expressions. > V:=cos(x)^5 + sin(x)^4 + 2*cos(x)^2 - 2*sin(x)^2 cos(2*x); > simplify(V); Example 2: Trigonometric expressions with arguments in multiples of some angle will be simplified to trig functions in the single angle if possible: > simplify(sin(5*t)+sin(3*t)); Example 3: The simplify( ) command can be used to add rational expressions. Rewrite the sum as a single fraction.

> M:=(1/(x+1))+(x/(x-1)); > simplify(M); > Exercise 2.11: Simplify the expression

Answer 2.11 > simplify(7/(x+2)+(3*x)/(x+2)^2); Exercise 2.12 How does Maple simplify ? Whether or not this "simplified" form is of use to you will depend on what you plan to do with it. Answer 2.12 > h:=sin(3*t)-sin(7*t); > simplify(h); >

Section 3: Graphing
In this section you will learn how to plot the graph of a function defined by an expression. Other topics covered include: combining the graphs of several expressions into a single plot, plotting points, and combining different plot structures into a single picture. > restart;

Plotting an Expression: the plot( ) command


Example 1: We use the plot( ) command to plot the graph of > plot(3*x^2-8,x=-5..5); for x between - 5 and 5 .

> Notice that Maple scales the y-axis automatically, choosing a y-scale that shows the entire graph corresponding to the specified domain. You can override automatic y-scaling by specifying a range for y as well as x. On the next line we have limited the y-range to the interval [-20,40]. > plot(3*x^2-8,x=-5..5,y=-20..40); > If you click on a graph with the left mouse button, the graph is selected and the bottom toolbar options are changed. See the reference diagram below. Now when you click on the graph, the point coordinates of its location are shown. The 1:1 button makes the x-scale and y-scale equal. Scroll back up to the previous graph and experiment with these features. Try the other graph options as well.

Example 2: Automatic scaling is a useful feature but there are times when you may want to set the y range manually. For example automatic scaling isn't appropriate for graphs with vertical asymptotes. Compare the next two graphs. Notice how we have set the limits for y to the interval [20,20] in the second plot command. > plot(x/(x-2),x=-5..5); > plot(x/(x-2),x=-5..5,y=-20..20); Example 3: Plot the graph of to see the four x-intercepts.

over the domain [-8,8]. Choose a y-range that allows you

First let's take a look at the plot with automatic scaling of y. > plot(x^3+1-exp(x),x=-8..8); The large negative values for y near 8 have forced the vertical scale to be too large to see the x-intercepts clearly. A better view is achieved by setting limits on the y-range. > plot(x^3+1-exp(x),x=-8..8,y=-5..15); Exercise 3.1 Plot y = sin(x) over two complete periods. Answer 3.1 > plot (sin(x),x=-2*Pi..2*Pi); Exercise 3.2 Plot over the domain [-10,10] with automatic y scaling. After observing the

graph, edit the domain and range so that you can see the x-intercepts clearly. Estimate the x-intercepts with the mouse cursor. Answer 3.2 > plot(3*x^4-6*x^2,x); Notice how large y becomes when x = -10 or x = 10; with automatic y scaling it is difficult to see how the function behaves for x between -2 and 2. In the next plot we restrict the y scale in order to better observe the behavior for small y outputs. > plot (3*x^4-6*x^2,x=-3..3,y=-5..15); The x-intercepts are about -1.4, 1.4 and 0.

Plotting Several Expressions


To show more than one graph in the same picture list them in square brackets [ ] separated by commas. > plot([cos(x),x^2],x=-1..4,y=-4..4); Notice that each of the graphs is displayed using a different color. You can specify the colors for each function by adding a color option at the end of the command. The colors are assigned in the same order as the functions. Note that the colors must also be listed in a square bracket [ ] . Here is an example. > plot([cos(x),x^2],x=-1..5,y=-4..4,color=[blue,black]); Here are the colors available in Maple.
aquamarine brown magenta sienna yellow black gold maroon tan blue green orange turquoise navy gray pink violet coral grey plum wheat cyan khaki red white

Exercise 3.3 Graph the functions and together. Experiment with different

y ranges so that complete pictures of both graphs are shown. Answer 3.3 > y1:=x^2-5*x+6; > y2:=1/(x-2)^2; > plot([y1,y2],x=-3..8,y=-1..6);

Plotting points
The plot command can also plot one or more points. Example 1: Plot the point (2,3) . Note in the following line that we use two sets of square brackets. > plot([ [2,3] ],style=point); Example 2: We can control the size of the x and y ranges shown by adding these to the command as in the next line. > plot([ [2,3] ],x=-7..7,y=-7..7,style=point); Example 3: To graph more than one point list them in the plot command. Note the commas. Remember square brackets for each point and an extra pair of square brackets surround the list. > plot([ [2,3],[-2,5],[1,-4] ],x=-7..7,y=-7..7,style=point); Example 4: Changing style to "line" connects the points in the order listed. > plot([ [2,3],[-2,5],[1,-4] ],x=-7..7,y=-7..7,style=line); Example 5: Optional extensions can be used to specify point color and symbol (e.g. diamond, circle, cross is default) to indicate the points. > plot([[3,2],[-2,3],[2,1]],style=point,color=blue,symbol=circle); Exercise 3.4 Plot the following points using the color red and the diamond symbol: [1,4] , [-2,-3], [4,-5] and [-6,5] . Then connect the points with lines in a separate plot command. Answer 3.4 > plot([[1,4],[-2,-3],[4,-5],[6,5]],style=point,color=red,symbol=diamond);

> plot([[1,4],[-2,-3],[4,-5],[6,5]],style=line,color=red,symbol=diamond);

Combining Graphs of Expressions and Points: the display( ) command


A special plotting package called plots contains many additional graphing features. To use these commands, you need to execute the following line which loads plots. Recall, the colon at the end of the statement allows this line to be executed without displaying any distracting output. To see the contents of plots you can change the colon to a semicolon. > with(plots): The display( ) command allows you to combine graphs of expressions and points in the same picture. The first step is to name the individual picture components. IMPORTANT: Be sure to use a colon at the end of the line to suppress output (see first three lines below). The display( ) command is then used to do the actual plot (this ends with a semicolon). > > pict1:=plot([-3*x+5,9-x^2],x=-3..5,color=[green,red]): > pict2:=plot([[-1,8],[4,7]],style=point,color=blue,symbol=circle): > display([pict1,pict2]); Alternatively we can list these three related plot commands in a single execution group by typing SHIFT-ENTER at end of each line. > pict1:=plot([-3*x+5,9-x^2],x=-3..5,color=[green,red]): > pict2:=plot([[-1,8],[4,7]],style=point,color=blue,symbol=circle): > display([pict1,pict2]); For more on this see "Execution groups with more than one command" in the section Notes on the Maple Worksheet Interface at the end of this tutorial. Exercise 3.5 Display a graph that contains both the function and its x and y intercepts,

marked with circles. Answer 3.5 > pict4:=plot(x^2+x-6,x=-5..4,y=-8..8): > pict5:=plot([[0,-6],[3,0],[2,0]],style=point,symbol=circle, color=blue): > display([pict4,pict5]);

Section 4: Solving Equations


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):

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 and give it the name "eqn1" . > 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); > rhs(eqn1); 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;

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

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); 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[1]; 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; Next we solve the equation using the solve( ) command assigning the name H to the output. > H:=solve(eqn1,x); 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); > subs(x=H[2],eqn1); > subs(x=H[3],eqn1); Example 4: Sometimes the "exact" solutions are too cumbersome to be of much use. In the next two lines we solve the equation . > eqn1:=x^3-34*x^2+4=0; > H:=solve(eqn1,x); As you can see, reading these exact solutions is quite a challenge! Note that the I stands for . When a solution is this complicated it is more useful to look at the approximate solutions using evalf( ): . > evalf(H); 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: > solve(5*exp(x/4)=43,x); 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);

Exercise 4.1 Solve the equation 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.) Answer 4.1 > solve(x^3-11*x^2+7*x+147=0,x); > factor(x^3-11*x^2+7*x+147); 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: . > eqn:=x^4-x^3-17*x^2-6*x+2=0; > fsolve(eqn,x); 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 > eqn:=x^3+1-exp(x)=0; > fsolve(eqn,x);

using the fsolve( ) command.

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

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 correspond exactly to the solutions of the equation .

> plot(x^3+1-exp(x),x=-3..5,y=-5..15); 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 since we can see from the graph that there definitely is one (and only one) solution on that interval. > fsolve(eqn,x=-1..-.2); 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); 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); 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); Alternatively we can use the fsolve( ) command, now searching over this larger interval. > fsolve(eqn,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); None there either ! We now have a complete list of the four solutions of our original equation They are: -.8251554597 , 0 , 1.545007279 and 4.567036837 Example 4: Use fsolve( ) to find the approximate solutions of the equation :

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 :

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; > plot(lhs(eqn),x=-10..10); 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); 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 . Begin by looking at a

relevant graph. 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; > plot(lhs(eqn),x=-5..5,y=-5..5); 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); 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 . Use the graph of one expression to

locate the solutions. Check each solution by substituting it back in the original equation. 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; Now we can graph the right-hand side equation. > plot(lhs(eqn),x=-10..10); 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); > soln2:=fsolve(eqn,x=1..3); Check by subsituting back into the original equation. > evalf(subs(x=soln1,eqn));

> evalf(subs(x=soln2,eqn)); 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 and 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. Answer 4.4 > y1:=10-x^2; > y2:=4*sin(2*x)+5; Here is a plot of the two equations. > plot([y1,y2],x=-5..5); 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; c) We now find the two solutions using fsolve( ) > x_soln1:=fsolve(y1=y2,x=-4..0); > x_soln2:=fsolve(y1=y2,x=0..4); d) We can use the subs( ) command to find the corresponding y-coordinates. > y_soln1:=subs(x=x_soln1,y1); > y_soln2:=subs(x=x_soln2,y1); 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); Alternatively we can use fsolve( ) to confirm that there is no solution near x=1. > fsolve(y1=y2,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: The solve command works well here. > solve(4-v=2*T-k*g,g); Here is a little nicer way of displaying the same result: > g=solve(4-v=2*T-k*g,g); Exercise 4.4 Edit the last command to solve for each of the other letters T, k and v.

Answer 4.4 > T=solve(4-v=2*T-k*g,T); > k=solve(4-v=2*T-k*g,k); > v=solve(4-v=2*T-k*g,v); Exercise 4.5 Solve the equation for y. Assign the set of solutions to a variable named S. How are the two solutions S[1] and S[2] related ? Answer 4.5 > S:=solve(x^2+y^2=25,y); > S[1]; > S[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): 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: and > solve({3*x+2*y=3,x-y=-4}); 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); > y2:=solve(x-y=-4,y); 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]); 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: > solve({x+y+z=1, 3*x+y=3, x-2*y-z=0}); Exercise 4.6 Find the solution to the system:

Check by subsitituting the solution pair in both equations in the system Answer 4.6 > eqns:={4*x+3*y=12, 5*x-7*y=35}; > ans:=solve(eqns); > subs(x=189/43,y=-80/43,eqns);

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 : . > solns:=solve({x+y+z=1, 3*x+y=3}); 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 in the output above indicates that 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); So one solution is : x=4 , y= -9 and z=6. Take a minute and check by hand that these three and . numbers do in fact satisfy our original equations : Now let's look at the solution that is generated when we take x=2. > subs(x=2,solns); So two of the infinitely many solutions are: (x,y,z) = (4, -9, 6) and (2, -3, 2). Exercise 4.7 Solve the system : solutions. Answer 4.7 > eqns:={ x+2*y+z=2 , 3*x+y=1 }; > soln:=solve(eqns); Here are the solutions for x = 1, 2, 3, and 4 : > subs(x=1,soln); > subs(x=2,soln); > subs(x=3,soln); > subs(x=4,soln); and find at least three particular

>

Section 5: Functions: Defining, Evaluating and Graphing


In this section you will learn how to define a function f(x) in Maple. The remainder of the section covers evaluating functions, solving equations with functions, and graphing functions. > restart;

Defining and Clearing a Function in Maple


To distinguish a function from an expression, Maple requires special notation when is defined as: defining a function. For example, the function f(x) = > f:=x->cos(Pi*x)+3; Take note of the syntax here. It is absolutely necessary to type the "arrow" - > made by typing a "minus sign" and a "greater than" symbol. Maple will not define a function if you type f(x):=cos(Pi*x)+3 ; Below is a comparison of an expression and a function. Note the difference in syntax and how Maple returns the output for each. > y:=(x + 2)/(x^3 + 5*x + 2); > f:=x->(x + 2)/(x^3 + 5*x + 2); Functions always require an arrow when typing in; Maple should also have an arrow in its output. Always check the output for the arrow to confirm that you have in fact defined a function. Exercise 5.1 Enter the function h(x) = Answer 5.1 > h:= x-> x^3*sin(2*x+1);

in the workspace below.

Once you have defined a function, Maple will remember that function during your entire working session. If you want to overwrite the function with a new definition, you simply retype the definition. For example, if you want to replace the function f(x) above with ln(cos 5x), type: > f:=x->ln(cos(5*x)); We can confirm the current value for the function f(x) : > f(x); If you want to clear the function f(x) without redefining it, type: > f:='f'; It's always a good idea to clear your functions when you start a new problem. Alternatively you can use restart to clear everything from memory.

Evaluating a Function

Once a function has been defined, you can evaluate it at various values or literal expressions using function notation. It's always a good idea to clear the function name first before entering a new function. > f:='f'; > f:=x->3*x+x^2; > f(-1); > f(2+sqrt(5)); > evalf(f(2+sqrt(5))); > f(x+4); > simplify(%); > (f(x+h)-f(x))/h; > simplify(%); If more than one function is involved, composing functions is easy to do. > g:=x->cos(x)+1; > f(g(Pi/3)); > j:=x->g(f(x)); > j(x); Exercise 5.2 Exercise 2 : Define the function then have Maple calculate

s(2),and s(t-3) and s(t) - s(3) and simplify your results. Don't forget the arrow notation! Answer 5.2 > s:= t-> (3 + t^2)/(sqrt(3*t+1)); > s(2); > s(t - 3); > simplify (%); > s(t) - s(3); > simplify(%); Notice that if you define a function, there is no need to evaluate the function using the "subs" command like you do with expressions.

Solving Equations involving Functions


Once your function is defined, you can solve equations with functions either exactly or approximately: > g:='g'; > g:=t->t^3-6*t^2+6*t+8; > solve(g(t)=0,t); > fsolve(g(t)=0,t);

Graphing a Function
The plot function works the same for functions: > h:='h'; y:='y'; x:='x';

> h:=x->x*exp(-x); > plot(h(x),x=-1..4,y=-2..1); Several functions can be graphed simultaneously just at we did for expressions. Consider the function horizontal shifts , . Below we graph this function along with the and . Can you identify each ?

> f:=x->2/(x^2+1); > plot([f(x),f(x+1),f(x-3),f(x-6)],x=-5..10,y=-1..3); Exercise 5.3 Define the function then answer the following questions.

a) Find the value of f(6.5) b) Simplify the expression f(z-4) where z is a variable c) Plot a graph of f(x) d) Find all values of x such that f(x)=0. Answer 5.3 > f:=x->2*x-abs(x^2-5); > f(6.5); > simplify(f(z-4)); > plot(f(x),x); > fsolve(f(x)=0,x=0..2); > fsolve(f(x)=0,x=3..4); Exercise 5.4 Define the functions and then do the following.

a) Plot a graph that shows both functions g(x) and h(x). Experiment with different values for domain and range. b) Estimate the coordinates of the point of intersection of these two graphs by using left mouse-button click. c) Use fsolve( ) to solve the equation g(x)=h(x). How does the solution of this equation relate to your answer to part (b). > Answer 5.4 > g:=x->5*exp(-0.5*x); > h:=x->x+1; > plot([g(x),h(x)],x=-5..5,y=-20..20); > plot([g(x),h(x)],x=1..2,y=1..4); > xval:=fsolve(g(x)=h(x),x);

The solution to g(x)=h(x) is the x-coordinate of the point of intersection of g(x) and h(x). To find the corresponding y-coordinate of the intersection point evaluate either g(x) or h(x) at this value. > g(xval); > h(xval); Exercise 5.5 Define the function , then do the following: a) Plot the graph of this function on the domain [-1,8] . b) Modify your plot from part (a) to include the horizontal line y=4. Use this new plot to estimate the number and approximate values for x such that k(x)=4. c) What single function could you graph that would give you the same information as in part (b) d) Use Maple's fsolve( ) command to approximate all solutions to the equation k(x)=4. Answer 5.5 a) > k:=x->x+3*sin(2*x); > plot(k(x),x=-1..8); b) > plot([k(x),4],x=-1..8); There appears to be three intersection points at x=3.25 ,4.825 and 5.95 . > c) We could graph k(x) - 4 and look for x-intercepts. These will correspond to x-values found in part (b). > plot(k(x)-4,x=-1..8); Here are the solutions using fsolve( ) : > fsolve(k(x)=4,x=2 .. 3.5); > fsolve(k(x)=4,x=3.5 .. 5); > fsolve(k(x)=4,x=5 .. 7); >

Section 6: More on Graphing


> restart;

Parametric Equations
Maple's plot( ) command can also be used to graph curves described by parametric equations. To graph the parametric curve corresponding to the pair of parametric equations: x=f(t) and y=g(t) on the parameter interval [a,b] use the command: plot( [ f(t) , g(t) , t=a..b] , x=xmin..xmax, y=ymin..ymax); There are two things to take careful note of here. First note that there are three entries in the square brackets : the two parametric expressions for x and y and the parameter domain. Also note that the viewing window for the plot is separately specified by the x and y ranges (i.e. x=xmin..xmax, y=ymin..ymax ) . Example 1: Plot the parametric curve determined by . > plot([t^2-t,2*t-t^3,t=-2..2],x=-2..5,y=-5..5); Exercise 6.1

and

over the t interval [-2,2]

Implicit Plots
Maple can plot curves that are implicitly defined by an equation in the variables x and y. Example 1: To plot the graph of the hyperbola given by the equation: use the implicitplot(

) command. To use this command we must first load the "plots" library using the "with" command. > with(plots): Note the syntax for this command on the next line. > implicitplot(x^2/4-y^2/4=1,x=-5..5,y=-5..5); > Example 2: Graph the equation using the implicitplot( ) command.

Recall that this is the equation of an ellipse with the lengths of major and minor axes equal to 10 and 6 respectively. Our first attempt at getting the expected graph comes up short ! > implicitplot(x^2/25+y^2/9=1,x=-5..5,y=-5..5);

Why did we get a circle instead of an ellipse ? The problem here is that the x and y scales are not equal. To force equal scaling add "scaling=constrained" . > implicitplot(x^2/25+y^2/9=1,x=-5..5,y=5..5,scaling=constrained); > Exercise 6.2

Polar Graphs (optional)


Graphs of polar equations are handled by the polarplot(..) command, which is part of the plots library accessed using with(plots). Here are some examples. Note that we include the option scaling=constrained to get geometric perspective. > polarplot(1+cos(theta),theta=-Pi..Pi,scaling=constrained); > polarplot(sin(3*theta),theta=-Pi..Pi,scaling=constrained);

Plot Options
There are many options available when you use the plot command. To see a list execute the next line to go directly to Maple's Help Page on this command. Skip this if you wish. > ?plot[options]; >

Practice Problems
Problem No. 1
Assign the name w to the number approximation for the following: and then find the exact value and a decimal and .

Problem No. 2
Factor .

Problem No. 3
Enter the function Then find the approximate value of

Problem No. 4
Find the approximate value of T in the formula when a=4.6 , b= -3.8 and c=2.9

Problem No. 5
If , find and simplify , .

Problem No. 6
When multiplied out the expression What is the coefficient of the term ? equals a fifth-degree polynomial.

Problem No. 7
Plot the expressions and . on the interval . Then plot these same expressions on the interval

Problem No. 8
Plot the function on the interval . Automatic scaling does not produce a useful picture. Specify a y-range that gives a good view of this function on this interval.

Problem No. 9
Recall that if a rational number has an infinite decimal expansion then somewhere in the expansion the digits must repeat. A familiar example is the decimal expansion of the fraction = .33333... where we have the digit 3 repeated. A bit more interesting is the = 2.3571428571428... with the repeating digits 571428. Now . Can you identify the repeating sequence.

decimal expansion for

look at a decimal expansion of the fraction

Check yourself by looking at one thousand decimal places.

Problem No. 10
a) Plot the following points on a graph: ( 1, 0.53) , (1.5, 0.65) , (2, 0.91) , (2.5 , 0.95) and (3, 1.10 ) b) Create a single picture that has the points above plus graphs of the functions : and .

Use your picture to decide which of these two functions most closely fits this set of points ?

Problem No. 11
Approximate all real solutions of the equation .

Problem No. 12
Approximate all real solutions of the equation .

Problem No. 13
The graphs of and intersect at one point. Use the numerical solving capabilities of Maple to approximate the coordinates of this intersection point. Start by entering an appropriate equation to solve.

Check your answer by creating a picture that shows the graphs intersecting.

Problem No. 14
Solve for r in the equation : . Be sure that you have

entered the equation correctly. In particular check that you have used an * for every mulitplication.

Maple Quick Reference Card


denom( ) display( ) evalf(expr) digits (10). evalf(expr,n) expand(expr) factor(expr) fsolve(eqn) Selects the denominator of a fraction Combines graphs of functions and points (require with( plots) ) Numercially evaluates the given expression to the default number of

Numercially evaluates the given expression to n digits Expands the given expression Factors the given expression Finds numerical (approximate) solutions to equations. fsolve(x^2=cos(x)+4,x=0..5) ifactor(n) Gives prime integer factorization for a given integer lhs(eqn ) Selects the left hand side of an equation implicitplot( ) Plots implicitly defined functions implicitplot(x^2/25 +y^2/9=1 , x=-5 . . 5,y=-5 . . 5,scaling=constrained); numer( ) Selects the numerator of a fraction plot( ) Plots functions defined by an algebraic expression: plot(3*x^2-8 , x=-5 . . 5 , y = -20 . . 40 ); Plots more than one function at a time: plot( [ 3*x^2-8 , sin(x) , cos(x) ] ,x=-5 . . 5 , y=-20 .. 40 ); Plots points: Plots parametric equations : plot( [cos(t), sin(t), t=0 . . 2*Pi] , x=-2..2, y=-2..2); rationalize(expr) Rationalizes the denominator of a given expression restart Clears Maple's memory of all definitions rhs(eqn ) Selects the right hand side of an equation simplify(expr) Simplifies the given expression solve(eqn) Finds exact solutions to equations, including literal equations and linear systems. subs(x= v,expr) Substitutes the value v for x in the expression subs(x=4,3*x^2+8); with( ) Brings in additional libraries of functions. The standard constants are: Caution: Do not use "pi", capital "P" is required Pi exp(1) I The names of the standard functions are: sqrt(x)

abs(x) exp(x) ln(x) natural log log(x) common log (base 10) sin(x), cos(x), tan(x), cot(x), sec(x), csc(x) arcsin(x), arccos(x), arctan(x) >

sine of x, etc. the inverse trig functions

You might also like