0.1 maple worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "insert" menu,...

21
> restart; Introduction to Maple in Calculus II 0.1 Maple Worksheets In MTH 142 we shall continue our work with Maple. Similarly as last semester, our work is going to be organized intoworksheets like this one. A worksheet consists of text and Maple command lines. Portions of a worksheet containing text and portions containing Maple command lines marked by vertical lines on the left of the screen are calledexecution groups . It is very important for you to learn how to toggle between the text mode and the command line mode. Your homework problems will require of you opening a new Maple worksheet, using Maple to plot functions, perform calculations etc., as well asentering your answers and comments in complete sentences using the text mode. As most of you already know, you toggle between the text mode and the Maple command mode by pressing the two buttons on the toolbar marked ”T” for text, and ”[¿” for Maple command prompt. Right now we are, of course, in the text mode. As an excercise, place the cursor at the end of this sentence, press the button marked ”[¿and see a new Maple prompt ”¿” appear. Type a simple command at thefirst prompt, say2+2;(Don’t forget the semi- colon!) Press ”Enter”. Maple output, hopefully 4, appears and the cursor jumps to the next prompt. (If there was none below, Maple would create one). With the cursor at the new prompt press the ”T” button. The prompt disappears and the mode changes to the text mode. Type something, say your name. Then switch back to the command mode by pressing ”[¿” again. And so it goes. Should you ever want to insert a command line before already typed text go to the ”Insert” menu, choose ”Execution Group” and click on ”Before Cursor”. Be aware of one thing though, you can’t insert a command prompt in the middle of an execution group which consists of already typed text. If you are within already typed worksheet, after you click on any command, the cursor jumps to the next command line. If there is none below, one will be created. If you want Maple to do something, you type your command at a com- mand prompt and press ”Enter”. Your success with Maple depends on your use of correct and precise syntax . Syntax is a way of entering your commands. Last semester we learned quite a bit of Maple syntax and we shall continue using it this semster, as well as introduce new commands. For those of you who want to refresh your memory or who didn’t take MTH 141 last semester, we review below Maple syntax used in Calculus I. Remember, also, that when- ever in doubt, you can refer to the manualGetting Started with Maple that came with your textbook or to this introductory worksheet. Those of you who have never worked with Maple should not get discouraged by the amount of syntax

Upload: others

Post on 27-Sep-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

> restart;

Introduction to Maple in Calculus II

0.1 Maple Worksheets

In MTH 142 we shall continue our work with Maple. Similarly as lastsemester, our work is going to be organized intoworksheets like this one. Aworksheet consists of text and Maple command lines. Portions of a worksheetcontaining text and portions containing Maple command lines marked byvertical lines on the left of the screen are calledexecution groups . It isvery important for you to learn how to toggle between the text mode and thecommand line mode. Your homework problems will require of you openinga new Maple worksheet, using Maple to plot functions, perform calculationsetc., as well asentering your answers and comments in complete

sentencesusing the text mode. As most of you already know, you togglebetween the text mode and the Maple command mode by pressing the twobuttons on the toolbar marked ”T” for text, and ”[¿” for Maple commandprompt. Right now we are, of course, in the text mode. As an excercise,place the cursor at the end of this sentence, press the button marked ”[¿”and see a new Maple prompt ”¿” appear.

Type a simple command at thefirstprompt, say2+2;(Don’t forget the semi-colon!) Press ”Enter”. Maple output, hopefully 4, appears and the cursor jumpsto the next prompt. (If there was none below, Maple would create one). Withthe cursor at the new prompt press the ”T” button. The prompt disappears andthe mode changes to the text mode. Type something, say your name. Thenswitch back to the command mode by pressing ”[¿” again. And so it goes.Should you ever want to insert a command line before already typed text go tothe ”Insert” menu, choose ”Execution Group” and click on ”Before Cursor”. Beaware of one thing though, you can’t insert a command prompt in the middleof an execution group which consists of already typed text. If you are withinalready typed worksheet, after you click on any command, the cursor jumps tothe next command line. If there is none below, one will be created.

If you want Maple to do something, you type your command at a com-mand prompt and press ”Enter”. Your success with Maple depends on your useofcorrect and precise syntax . Syntax is a way of entering your commands.Last semester we learned quite a bit of Maple syntax and we shall continueusing it this semster, as well as introduce new commands. For those of youwho want to refresh your memory or who didn’t take MTH 141 last semester,we review below Maple syntax used in Calculus I. Remember, also, that when-ever in doubt, you can refer to the manualGetting Started with Maplethat camewith your textbook or to this introductory worksheet. Those of you who havenever worked with Maple should not get discouraged by the amount of syntax

Page 2: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

reviewed in the next section. You don’t have to memorize it all at once. Youshall learn it as you work on examples in this and in subsequent worksheets.

Note:As you probably learned the hard way last semester, whenever youopen a worksheet and want to do more with it than only viewing, if you wantto change commands, enter new commands etc., you have tore-executeall thecommands in the worksheet; that is you have to click ”Enter” on all commandlines, even if they have been saved and their outputs appear already on screen.Otherwise, Maple will not recognize functions and expressions defined in theworksheet and you will get strange error messages.

0.2 Review of Calculus I Maple Syntax

Each of the sections below describes syntax related to a specific topic. If youwant to view any of the sections just click on the ”+” button (right-pointingarrow in Maple 10). The ”+” will be replaced with ”-” (down-pointing arrowin Maple 10) and the section will open. If a section contains material familiarto you, click on ”-”. The section will close.

In all sections below the symbol ”%” is used. In Release 5 of Maple, ”%”denotes the lastexecutedoutput. That is, the output of the last command onwhich you have clicked. (It was”in earlier releases.) The symbol ”%” easilyleads to confusion and it should preferably be used on the same commandline as the command to which it refers.

1 Basic syntax

To make Maple do something you type your command at the Maple prompt”¿”. Your commands will usually appear in red on screen. You have to endeach command by a semicolon and then press ”Enter”. Maple will return itsoutput that usually appears in blue. (Ocassionally, when you do not want Mapleto print out the output, you end your command with a colon.) The best way tolearn the correct Maple syntax is by examples. We shall switch to the commandmode now and ask Maple to perform some simple calculations. Let’s ask Maple

to calculate24732073979750

32456789999. We type our command at the prompt, end it with

a semicolon, press ”Enter” and Maple returns an answer.

> 2*(359+23)-(5+21)/(2+11)+25^9/32456789999;

28546771244863

32456789999

As you see, the rules of entering the arithmetical operations are similar tothose on your calculator. Multiplication is always denoted by ”*” , division by”/” , exponentiation by ”ˆ”, addition and subtraction in an obvious way. The

Page 3: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

proper use of paretheses is, of course, crucial to the correct syntax. As in theabove example, whenever possible Maple will return an exact answer. If youwant a decimal form, or in other words, afloating point approximationofyour answer, you have to use the command ”evalf” .( The ”f” at the end of thecommand stands for ”floating point”, ”eval” for ”evaluate”.)

> evalf(%);

879.5315632

As mentioned above the symbol ”%” that stands for the lastexecutedoutput,that is, the output of the last command that you clicked on, should preferablybe used on the same command line as the command to which it refers. You canenter several commands on one line, end each with semicolon, and then press”Enter” to execute all of them. For example

> (2*7+23)/(17-2); evalf(%);

37

15

2.466666667

Maple gave the exact version of the answer followed by its floating pointapproximation.

As a little excercise, press ”Enter” on the command lines below. Do youexpect the same output for both of them?

> 3*5+2/7; evalf(%);

107

7

15.28571429

> (3*5+2)/7; evalf(%);

17

7

2.428571429

2 Functions and Expressions. Evaluating Ex-

pressions.

Recall that afunction , for examplef (x) = e2 x + x sin (x) , is a rule which toeach input, say x, prescribes the output given by the formula for a function.Maple’s syntax for defining a function reflects this interpretation of a function.If we want to define the function f(x) in Maple, we type the following at thecommand line

> f:=x->exp(2*x)+x*sin(x);

Page 4: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

x 7→ e2 x + x sin (x)

Observe that you have to type in an arrow ”-¿” which is entered usingthe ”minus” key and the ”greater” key. The symbol:=in Maple means always”define”. Note also that the proper syntax for the natural exponentialex is”exp(x)” .

Since a function is a rule which to each input prescribes the output given bythe formula for the function, you can apply a function to anything in place of xand obtain the corresponding value. The Maple syntax for doing that is simple.Namely

> f(s); f(10);

e2 s + s sin (s)

e20 + 10 sin (10)

If you define

> m:=exp(2*x)+x*sin(x);

e2 x + x sin (x)

you have defined not a function but a formula or anexpressionm in termsof x. Maple can process expressions, as well as functions, but, as you see be-low, the appropriate syntax may look a little different. For example ”m(s)” ismeaningless to Maple. If you want to substitute s for x in the expression m youhave to use the ”subs” command that, of course, stands for ”substitute”.

> subs(x=s,m);

e2 s + s sin (s)

There are basically three commands to evalute expressions. They are ”eval”,”evalf” and ”value”. The command ”eval” will attempt to give you an exactvalue for your expression, while ”evalf” will evaluate an expression numericallyand return a decimal point approximation. The command ”value” is most oftenused in conjuction withinertcommands, like ”Int”, ”Limit” which do not eval-uate the input but only print it out. You will see in subsequent sections how”value” works. The best way to learn the differences between the evaluationcommands is by practice and example. Click on the lines below and see if youcan predict an output.

> Pi;

π

> eval(Pi);

π

> evalf(Pi);

3.141592654

> eval(exp(x),x=3);

Page 5: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

e3

> evalf(eval(exp(x),x=3));

20.08553692

> eval(sin(h)/h,h=2); evalf(%);

1/2 sin (2)

0.4546487134

> eval(m,x=10);

e20 + 10 sin (10)

If the last command gave you the answer ”m”, which obviously doesn’t makesense, that is because you forgot to re-execute commands in this worksheet andyou didn’t click on the line defining m. Hence, to Maple, m is just some constant.Click on the line on which m is defined and click again on the last command.

Note:You should always use the syntax ”exp(x)” for the natural exponential.You should not use exp(1)ˆx, or define e:=exp(1) and then use eˆx. Although allof these options seem equivalent, Maple works better with the syntax ”exp(x)”.

3 Limits

Syntax for finding limits of functions is very simple. Let’s define a function, forexample

> g:=t->(cos(t)-1)/t;

We find the limit of g(t) as t approaches 0 by typing

> limit(g(t),t=0);

0

The limit is 0. If you hadn’t defined g(t) you could simply type

> limit((cos(t)-1)/t,t=0);

0

You could also find limits of expressions. Define an expression a as follows

> a:=(cos(t)-1)/t;

cos (t) − 1

t

The syntax for finding limits of expressions is

> limit(a,t=0);

0

Page 6: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

This is an example of when the syntax involving expressions is somewhatdifferent than the syntax involving functions. You couldn’t use the syntax”limit(g,t=0);” You have to type ”g(t)”. In most commands involving func-tions you have to enter ”g(t)” and not just the name of the function.

If you want Maple to print out a given limit, use theinertversion of thecommand ”limit”, that is, ”Limit”. Inert commands like ”Limit”, ”Int” printout an input without evaluating it. They are useful if you want to verify if youentered a correct expression. If you want to evaluate your limit or integral rightaway, follow an inert command by the ”value” command. The”value” commandsimply changes the upper case inert commands to lower case commands andevaluates. For example

> Limit(g(t),t=0); value(%);

limt→0

cos (t) − 1

t

0

Maple can find limits at infinity and infinite limits as well.

> limit(ln(x)/x,x=infinity);

0

> limit(exp(-x)/x^2,x=-infinity);

∞You can use L’Hospital rules to see that Maple gave us correct answers. If

a given limit does not exist, Maple will tell us so

> limit(1/x,x=0);

undefined

You can find one-sided limits using Maple. The appropriate syntax is:

> limit(1/x,x=0,left);

−∞> limit(1/x,x=0,right);

∞If you want the limits to be printed out, use:

> Limit(1/x,x=0,left); value(%);

limx→0−

x−1

−∞

3.1

4 Derivatives

There are several ways of finding derivatives. Let’s have a function

Page 7: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

> h:=x->x*sin(x^2);

x 7→ x sin(

x2)

We can find its derivative as follows

> diff(h(x),x);

sin(

x2)

+ 2 x2 cos(

x2)

If we hadn’t defined the function h(x) above, we could simply use the syntax

> diff(x*sin(x^2),x);

sin(

x2)

+ 2 x2 cos(

x2)

The syntax ”diff(h,x);”, however, does not work. You have to type ”h(x)”.For expressions the syntax is a little different. Define an expression b

> b:=x*sin(x^2);

x sin(

x2)

We find its derivative by typing

> diff(b,x);

sin(

x2)

+ 2 x2 cos(

x2)

The simplest syntax for finding the second order and other higher orederderivatives is

> diff(h(x),x$2);

6 cos(

x2)

x − 4 x3 sin(

x2)

In an instant, Maple can calculate for you the tenth derivative of h(x)

> diff(h(x),x$10);

332640 cos(

x2)

x − 1108800 x3 sin(

x2)

− 887040 x5 cos(

x2)

+ 253440 x7 sin(

x2)

+ 28160 x9 cos(

x2)

− 1024 x11 sin(

x2)

Another way of finding derivatives is by using the ”D” operator. It worksas follows:

> D(h);

x 7→ sin(

x2)

+ 2 x2 cos(

x2)

To find the second derivative using the ”D” syntax, you type

> D(D(h));

x 7→ 6 cos(

x2)

x − 4 x3 sin(

x2)

Note:There is an important difference between the outputs of the ”D(h)”and the ”diff” commands. The command ”D(h);” returns the derivative ofh as afunctionof x. The command ”diff(h(x),x);” gives the derivative asanexpression in terms of x. Both forms have advantages and disadvantages.For example, if you want to simplify the derivative, the important command”simplify” which tells Maple to simplify a given expression, works, in general,better applied the waysimplify(diff(h(x),x));than in the contextsimplify(D(h)(x));.For other purposes, it may be more convenient to have the derivative D(h) as a

Page 8: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

function. There is a way of turning an expression into a function, using the socalled ”unapply” command. We shall look at this command later.

5 Integrals

6

Maple can find indefinite integrals, as well as definite intergals. For example

> int(exp(3*x),x);

1/3 e3x

Maple has found an antiderivative of the functione3 x . You know that theindefinite integral is equal to an antiderivative plus an arbitrary constant. Mapledoesn’t bother to add an arbitrary constant. It does the hard part of the job.Namely, finds antiderivatives. If you define a function, say

> p:=x->x^2*exp((1/3)*x);

x 7→ x2e1/3 x

you can find its indefinite integral using the syntax

> int(p(x),x);

3(

18− 6 x + x2)

e1/3 x

If an antiderivative cannot be found in a closed form, which as you knowmay happen, Maple will simply print out the input.

> int(sin(cos(x^2)),x);∫

sin(

cos(

x2))

dx

If you want a given integral printed out, as well as found, use the inertversion ”Int” of the ”int” command together with the”value” command

> Int(x^3,x); value(%);∫

x3dx

1/4 x4

Similar syntax applies to definite integrals.

> int(p(x),x=0..2); evalf(%);

−54 + 30 e2/3

4.43202123

We have just found the exact and the decimal value of definite integral ofthe function p(x) from 0 to 2. It is usually a good idea to have a given integral

Page 9: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

printed out as well as evaluated. Again, we accomplish that with the command”Int”.

> Int(cos(3*x),x=-1..3); value(%); evalf(%);∫

3

−1

cos (3 x) dx

1/3 sin (3) + 1/3 sin (9)

0.1844128311

If Maple prints out a given definite integral instead of evaluating, that meansthat an antiderivative cannot be found and the Fundamental Theorem cannotbe used. For example:

> int(sin(cos(x^2)),x=0..2);∫ 2

0

sin(

cos(

x2))

dx

In such case, we can ask Maple to find the integral numerically by typing:

> evalf(int(sin(cos(x^2)),x=0..2));

0.3939912831

7 Plotting

We made an extensive use of Maple’s plotting facility last semester and we shallcontinue using it. The basic plotting syntax is very simple. You type in aformula for a function you wanted plotted and the range for the independentvariable. Maple automatically adjusts the range for the dependent variable sothat you can see your plot. For example

> plot(cos(3.5*x),x=0..Pi);

Page 10: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

If you have defined a function say

> k:=t->3*exp(.5*t);

t 7→ 3 e0.5 t

you can plot it using the syntax

> plot(k(t),t=0..4);

You can add a lot of options to your plots with appropriate commands. Forexample

Page 11: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

> plot(k(t),t=0..4,color=blue,thickness=2,labels=["time in seconds","positionin feet"]);

You can plot several functions in one coordinate system and assign attributesto each graph to distinguish between them. For example

> plot([sin(x),sin(2*x)],x=0..2*Pi,color=[black,blue]);

If you are assigning attributes to your graphs, like colors, it is importantto enter the functions, as well as colors in between square brackets[..]. Objectsinside square brackets are read by Maple as alist in which the order of elements

Page 12: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

matters. If you enter objects between curly brackets{..}Maple considers it aset in which the order does not matter. In order to use more advanced plottingcommands you need to load thepackage”plots” which is discussed in the section”Packages”.

8 Solving Equations

As you know, solving equations is not an easy matter. In many cases there areno reliable methods of finding exact values of solutions and numerical methodshave to be used. Maple knows all the standard techniques and algorithms, aswell as numerical methods. There are essentially two commands for solvingequations ”solve” and ”fsolve”. The command ”solve” attempts to find exactvalues of as many solutions as possible. It works very well with polynomialequations up to the order four and equations which can be reduced to suchform. For example:

> solve(x^2-4*x-8=0,x);

2 + 2√

3, 2 − 2√

3

Command ”solve” can be applied to equations containing letter constants,that is, parameters. For example

> solve(c*x^2+d*x+3=0,x);

1/2−d +

√d2 − 12 c

c, −1/2

d +√

d2 − 12 c

c

For more complicated equations ”solve” will return essentially the input itself

> solve(x^5-x+1=0,x);

RootOf(

Z 5 − Z + 1, index = 1)

, RootOf(

Z 5 − Z + 1, index = 2)

, RootOf(

Z 5 − Z + 1, index = 3)

, RootOf(

Z 5 − Z + 1, index = 4)

, RootOf(

Z 5 − Z + 1, index = 5)

e1 :={

RootOf(

Z 5 − Z + 1, index = 1)

,RootOf(

Z 5 − Z + 1, index = 2)

,RootOf(

Z 5 − Z + 1, index = 3)

,RootOf(

Z 5 − Z + 1, index = 4)

,RootOf(

Z 5 − Z + 1, index = 5)}

{−1.167303978,−0.1812324445− 1.083954101 i,−0.1812324445+ 1.083954101 i, 0.7648844336− 0.3524715460 i, 0.7648844336+ 0.3524715460 i}Maple’s response indicates that it does not know how to solve this equation

exactly. It is not surprising. As you may know there are no formulas for findingroots of polynamials of degree five or higher. In that case, we can ask Mapleto solve a given equation numerically. The command ”allvalues” applied to anoutput ”RootOf” will produce approximate solutions, real and complex:

> allvalues(RootOf(_Z^5-_Z+1, index = 1));

RootOf(

Z 5 − Z + 1, index = 1)

Page 13: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

The best way to solve equations numerically is by applying the ”fsolve”command. ”fsolve” will attempt to find a solution numerically, and in general,it will return one real solution.

> w:=t->sin(3*t)+cos(2*t);

t 7→ sin (3 t) + cos (2 t)

> fsolve(w(t)=0,t);

−1.570796327

A solution that ”fsolve” returns may not be located in a range of interestto you. The situation can be remedied by adding under the ”fsolve” commanda range in which you want Maple to find a solution. The latter capability ofMaple equation solver combined with Maple’s plotting facility provide a verypowerful tool of finding solutions relevant to your problem. Suppose that youare studying a process modeled by the function w(t) and the range of interestfor t is [0,3]. You plot w(t) in that range:

> plot(w(t),t=0..3);

You see from the plot approximately where the zeros of w(t) are located. Youask Maple to find them using ”fsolve” with the range for t specified. Namely:

> fsolve(w(t)=0,t,0.5..1);

0.9424777961

> fsolve(w(t)=0,t,2..2.5);

2.199114858

Page 14: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

9 Packages

When you start Maple, it loads into the computer’s memory only the so calledkernel, which contains the basic commands and functions. More advanced com-mands are contained in packages and libraries, which can be loaded with ap-propriate commands. So far we have used two such packages: ”plots” and ”stu-dent”. To load a package, say ”plots”, you use the command ”with(plots):”. Ifyou end your command with a colon, the package will be loaded but its contentwill not be printed. If you end it with a semicolon ”with(plots);” Maple willload the package, as well as print its content.

> with(plots);

[animate , animate3d , animatecurve , arrow , changecoords , complexplot , complexplot3d , conformal , conformal3d , contourplot , contourplot3d , coordplot , coordplot3d , densityplot , display , dualaxisplot ,fieldplot ,fieldplot3d , gradplot , gradplot3d , graphplot3d , implicitplot , implicitplot3d , inequal , interactive , interactiveparams , intersectplot , listcontplot , listcontplot3d , listdensityplot , listplot , listplot3d , loglogplot , logplot ,matrixplot ,multiple , odeplot , pareto, plotcompare , pointplot , pointplot3d , polarplot , polygonplot , polygonplot3d , polyhedra supported , polyhedraplot , rootlocus , semilogplot , setcolors , setoptions , setoptions3d , spacecurve, sparsematrixplot , surfdata , textplot , textplot3d , tubeplot ]

Among the commands which the package contains we see ”pointplot” and”display”, which we used before. ”pointplot” allows you to print numerical data,that is, a bunch of points on the xy-plane. ”display” allows you to print in onecoordinate systems graphs of different types or in different ranges. We also seethe command ”implicitplot” which allows plotting curves given by xy-equations.For example:

> implicitplot(3*x^2+y^2=4,x=-3..3,y=-3..3);

The package ”plots” contains many important plotting commands and weshall use it extensively in the future.

Page 15: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

10 Using Maple’s Help

Maple has an extensive on-line help and it may be a good idea to learn how touse it. For example, you want to factor a polynomial, say

x3 − 3 x − 2.

To find a Maple command to do this, select Topic Search...from the Helpmenu. Then type ”factor” because this is want you want to do. Among thechoices that come up, you see ”Factor” and ”factor”. Both look promising. Sayyou decide to try ”Factor” first. Click on it to select it, and then double clickto open the corresponding Help menu. A long page comes up. Scroll down toexamples. The examples look nothing like what you want. Try ”factor” instead.That’s it! The first example that you see looks almost exactly like what youwant. It is an example of how to factor the polynomial6 x2 + 18 x − 24 . Youcan try to remember the syntax and use it in your example, or, if the syntax iscomplicated, you can copy an example from the Help menu into your worksheetas follows. Highlight the command line that you want copied. Click on Copyunder the Edit menu and close the Help screen. Open a new execution groupin your worksheet by clicking on the ”[¿” button. Move the cursor to the new”¿” prompt and click on Paste under the Edit menu. Below we have done justthat.

> factor(6*x^2+18*x-24);

6 (x + 4) (x − 1)

Now we can simply follow the syntax to factor our polynomial.

> factor(x^3-3*x-2);

(x − 2) (x + 1)2

Done. You could have arrived at the right Help menu by typing ”polynomial”instead of ”factor” and then navigating your way through a series of menus thatappears on the top of the screen. Try this as an excercise.

10.1 Examples

The first example, which is very similar to some examples that we looked atlast semester, will help you refresh your memory about the syntax. We useit to illustrate how you are expected to do your homework problems in termsof proper comments and explanations. Remember, it is usually not sufficientto hand in a bunch of Maple inputs and outputs.In most examples, you

have to interpret the results and write your comments and answers

in complete sentences.

Page 16: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

Example 1.A rumor is spreading among a group of 200 people in an isolatedregion. The number of people, N(t), who have heard the rumor by time t,measured in hours since the rumor started to spread, can be approximated bythe following function

N (t) = 200(

1 + 199 e−0.17 t)

−1

.

How many people have heard the rumor after 20 hours? After 30 hours? Whenhas practically everybody heard the rumor? What can you say about the patternaccording to which the rumor is spreading? When have150 people heard therumor? When is the rumor spreading fastest?

We shall have to analyze the function N(t), hence we shall begin by definingit for Maple. To answer the first two questions we shall evaluate N(20), N(30).Then we shall calculate some more values to see when practically everyone hasheard the rumor. To answer the question about the pattern we shall graph N(t)and describe its shape. The usefulness of your graph depends on the properchoice of the range for t. We shall have to choose the range for t large enoughto see the global behavior of the function. To answer the question, when have150 people heard the rumor we will have to solve an equation. Answering thelast question will, of course require finding the maximum of the first derivative,which, in turn, will require finding zeros of the second derivative. As you workthrough the problem, you should comment and explain your methods and re-sults. Should a problem like this be a homework problem, your solution shouldlook like the one below in order for you to get full credit. (Remember, allcomments are part of the solution.)

A Solution That Will Earn You Full Credit

> N:=t->200/(1+199*exp(-.17*t));

t 7→ 200(

1 + 199 e−0.17 t)

−1

> N(20); N(30);

26.17362288

90.36474326

After 20 hours approximately 26 people have heard the rumor. After 30hours approximately 90 people have heard the rumor.

> N(40);N(50);N(60);N(65);

163.7141831

192.2170906

198.5314839

199.3696842

After about 65 hours practically everyone has heard the rumor.

> plot(N(t),t=0..70);

Page 17: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

At first the rumor is spreading slowly as the graph climbs slowly, then therumor is spreading faster and faster. After about 40 hours it begins to spreadslower again. After about 60 hours the graph levels off. Practically everyonehas heard the rumor.

> D(N);

t 7→ 6766.0e−0.17 t

(1 + 199 e−0.17 t)2

> plot(D(N)(t),t=0..70);

Page 18: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

The rumor is spreading fastest when the derivative is maximal. It seems tobe around t=30. To find the point exactly, we shall find the corresponding zeroof the second derivative.

> D(D(N));

t 7→ 457787.5600

(

e−0.17 t)2

(1 + 199 e−0.17 t)3− 1150.2200

e−0.17 t

(1 + 199 e−0.17 t)2

> fsolve(D(D(N))(t)=0,t,20..40);

31.13708720

The rumor is spreading fastest at approximately t = 31.14.

> solve(N(t)=150,t);

37.59951243

150 people have heard the rumor at t approximately 37.6, that is, 37.6 hoursafter the rumor began spreading.

This was a model homework problem solution. Usually, examples in theworksheets will contain much more elaborate explanations.

Since the first part of the course is devoted to integration, our next exampleinvolves indefinte and definite integrals.

Example 2.Consider the function

r (t) =sin (t)

2 + (ln (t))2 .

(a) Try to find the indefinite integral of r(t). What does Maple’s responseindicate?

(b) Find the definite integral

∫ 2

1

r (t) dt.

(c) Define in Maple the function

R (x) =

∫ x

1

r (t) dt.

(d) Find the derivative of R(x). Are you surprised with the result? Why not orwhy yes?

(e) Plot graphs of r(x) and R(x) in one coordinate system for x between 1and 8. Comment on how the two graphs are related.

We start from defining the function r(t) in Maple.

> r:=t->sin(t)/(2+(ln(t))^2);

t 7→ sin (t)

2 + (ln (t))2

Page 19: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

Now we ask Maple to find the indefinite integral of r(t).

> int(r(t),t);∫

sin (t)

2 + (ln (t))2dt

Maple simply printed out the input. This means that an antiderivative of r(t)cannot be found in terms of elementary (and even not so elementary) functions.Believe it or not, it is hard to come up with a function whose antiderivativecannot be found by Maple! Nevertheless, the definite integral of r(t) can befound numerically in any interval in the positive half-line. (Remember, ln(t) isdefined only for positive t.). The integral can be found numerically, thus weneed the command ”evalf” in front of ”int”.

> evalf(int(r(t),t=1..2));

0.4385344824

The integral is well-defined and can be found numerically in any interval[1,x], hence we can define the function

> R:=x->int(r(t),t=1..x);

x 7→∫ x

1

r (t) dt

Of course, we cannot find a more explicit formula for R(x). Nonetheless,there is plenty that we can do with the function. For example, find its derivative

> diff(R(x),x);

sin (x)

2 + (ln (x))2

Are we surprised? Of course not! The 2nd Fundamental Theorem of Calculussays exactly that R’(x)=r(x).

Amazingly , Maple can also plot the function R(x) (by evaluating numer-ically the corresponding definite integral for many values of x). We shall plotboth functions r and R in one coordinate system. (Observe that we have toenter r(x) not r(t) to plot them both together.

> plot([r(x),R(x)],x=1..8,color=[red,blue]);

Page 20: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

How are the graphs related the red graph r(x) is the derivative of the bluegraph R(x). Hence, where r(x) is positive, R(x) increases. Where r(x) in nega-tive, R(x) decreases. Local minima and maxima of R(x) correspond to zeros ofthe red graph, which happens around 3.2 and 6.2.

Homework ProblemsTo solve your homework problems you should open a new worksheet, enter

your name and the title of the worksheet to which your homework correspondsin the text mode. You should perform all the necessary Maple operations andsupplement them by your explanations and answers as in the example above.

Problem 1.Suppose that the total number of people, M, in a small town,who have contracted a contagious disease by a time t days after its outbreak isgiven by

M (t) = 1000(

1 + 24 e−0.25 t)

−1

.

(a) How many people have become sick after 5 days? After 10 days?(b) Graph the function M(t) and describe its behavior.(c) How long will it take for 300 people to have become sick?(d) When is the disease spreading fastest?Problem 2.Consider the function

p (t) = 2cos (t)

1 + ln (t).

(a) Try finding the indefinite integral of p(t). What does Maple’s responseindicate?

(b) Find numerically the integral

Page 21: 0.1 Maple Worksheetsbonifant/classes/spring09/mth142/1-intro142.pdf · the "Insert" menu, choose "Execution Group" and click on "Before Cursor". Be aware of one thing though, you

∫ 4

1

p (t) dt.

(c) Define the function

P (x) =

∫ x

1

p (t) dt.

(d) Find the derivative P’(x). Is the answer what you expected?(e) Plot p(x) and P(x) in one coordinate system between x=1 and x=9.

Comment on the relationship between the two graphs.MTH 142 Maple Worksheets written by B. Kaskosz and L. Pakula, Copyright

1998. Last modified August 1999.