Sei sulla pagina 1di 85

Maple 10 By Example

Edition 1.4142135623 - August 2006

by M. Alsani
E-mail: alsani@ecc.edu

Introduction:
This document presents some of the fundamental Maple 10 functions that a user may need in pre-calculus, calculus, multivariable calculus, and elementary statistics levels of computations. Its objective is to help users become familiar with Maple's basic functions. Feel free to print out the directions for educational, non-profit use. This document's edition number converges to therefore this edition will be followed by edition 1.41421356237. 2,

Maple is a computing environment for solving a wide variety of mathematical problems. For the undergraduate student, Maple includes facilities for interactive algebra, trigonometry, calculus, linear algebra, differential equations, logic, group theory, number theory, linear optimization, discrete mathematics, statistics and finance, 2D and 3D graphics, animation, numeric and symbolic computations, and programming. Also it can be used to create technical reports for publication, or e-publication. Maple 10 has thousands of Computational Functions for symbolic and numeric mathematics. Some functions may or may not work in versions before or after this release. For use at home, you can purchase your own copy of Maple for your PC, Mac, or Linux. Some schools have a license to provide free copies to faculty and students. Maple and the Maple Logos are trademarks and copyrighted to the Waterloo Maple Software Corporation: http://www.maplesoft.com For free online resources of Maple, visit the Maple Application Center at http://www.mapleapps.com

Maple Worksheet
Maple 10 provides users with two environments to enter data; modern and traditional versions. The first is called "Document mode" which is the new Maple environment that supports rich documents. The second is called "Worksheet mode" which is the classic traditional Maple environment. The traditional Maple worksheet is a command-based environment, uses less memory and thus suitable for solving very large complex problems, and suitable for programmatic use of Maple. The examples in this document use the classic traditional Maple worksheet exclusively. When you start the Classic Worksheet Maple 10 environment, a new window opens with a blank worksheet.

This is the Classic Worksheet window in which all commands are typed and where results will appear. The space marked off by the square bracket [ is called an Execution Group. There is a prompt (>) in the upper left corner and a cursor bar (|) indicating that Maple is ready for input. In this mode, you may enter commands, define variables and perform calculations. The worksheet interface is similar to many Windows applications such as word processors. You can perform standard operations such as opening, saving, and printing files in the same way as in a word processor. Windows "cut/copy and paste" editing features work as well.

Maple commands must end with either a semicolon (;) or a colon (:). To activate a command, hit Enter. A semicolon tells Maple to calculate the input and display the result. A colon tells Maple to calculate the input and not to display the result. Input can be several lines long. Pressing Enter anywhere in an input region causes Maple to process all of the expressions in the region. Maple is case sensitive. For example, limit() and Limit() are interpreted as different functions. The majority of Maple commands are written in lowercase letters.

Text Input
Some times you need to type textual commentary to give information to the human reader. To do so, here are the procedures: To change an empty Execution Group to a Text region, click on that region where you would normally type a Maple command and then click the icon containing T. You can then type your comments. To go back to Command mode, click on the icon containing [> . To insert text before or after an Execution Group and within the same Execution Group, click on that region and then select the menu "Insert > Paragraph > Before or After", and then type your textual commentary. To insert text before or after Execution Group, click once on the square bracket [ itself and then select the menu "Insert > Paragraph > Before or After", and then type your textual commentary. To insert text before an Execution Group, click once on the square bracket [ itself. Then choose the "Text" option from the "Insert" menu, and then you may add your textual commentary. To insert a text between two commands, move the cursor into the first command line, click on the icon containing [> , then click on the icon containing T. Now you can type your text material.

You can control the size and style of the text you enter using the three pull-down menus at the top of the Maple window (when you are in Text mode). We should mention that Maple treats any input following the # sign within an Execution Group as a comment.

Help
Maple has a built-in Help facility. For information and examples on a particular Maple command , use the syntax ?command. For example, for detailed information regarding the solve command, type and enter ?solve at the Maple prompter >. And if you need more information on the plot command, just type and enter ?plot at the Maple prompter >. For information on using Maple's worksheet interface, look under the "Help" menu, select "Introduction". For information about a particular topic, you can use the option Topic Search in the Help menu. For a list of categories of available topics, type and enter click on the link you want in the window that appears.
?index

at the Maple prompter >. Then

Maple's packages
The most frequently used Maple functions are contained in Maple's standard library and are ready to be used - you do not need to explicitly load them. For a list of these built-in functions, type and enter ?index at the Maple prompter > then click on the link function in the window that appears. In addition to this standard library of functions, Maple has a collection of packages. Each package contains a set of functions of related calculations. For example, the "LinearAlgebra" package contains a collection of functions for working with vectors and matrices. Frequently used ones are the "LinearAlgebra" , "plots" , "student" , "plottools" and the "DEtools" packages. To see a list of all available Maple's packages, type and enter ?package at the Maple prompter > then click on the link index, package in the window that appears. To use a function contained in one of these packages, the package must be loaded into Maple's working memory by using the syntax with(package-name): at the Maple prompter >. For example, if your session is about vectors and matrices, then load the linear algebra package at the beginning of your session by typing with(LinearAlgebra): at the Maple prompter >. This will load all the commands in the package. Also, you may load a single command from a package by using the syntax with(package,command): at the Maple prompter >. For example, to load only the command implicitplot from the plots package type with(plots,implicitplot): at the prompter >. Note: It is enough to load a package once during your Maple session, although if you use the command restart: that will clear Maple's memory of any previous work. In this document I load packages often just to emphasize that a certain function is contained in a certain package. Often it will take more than one session at the computer to complete your project. You will need to save your work and come back to the lab and open your Maple file again to continue working.

Table of Contents: There are seven main subjects


1) Basic Computations and Functions ....... (Page 6) 2) Pre-Calculus ....... (Page 11)
- Solving equations (in one or more unknowns) - Simplifying Expressions - Expansion of Expressions - Factoring Polynomials - Partial Fraction Decomposition - Substitution and Evaluation ....(Page 16) - Naming Mathematical Objects using the symbol ":=" ....(Page 18) - Defining, Evaluating and Composition of Functions in one variable ....(Page 20) - 2-dimensional Plots ....(Page 22) - Some Matrix calculations ....(Page 29) - Sums, Sequences and Power Series

3) Calculus ....... (Page 33)


- Limits, Differentiation, Implicit Differentiation, and Integration - The surd command ....(Page 37)

Loops ....(Page 38)

- Some Ordinary Differential Equation calculations ....(Page 39) Samples of Using Maple to Illustrate Calculus Ideas ....(Page 41)

4) Vectors and Multi-variable Calculus ...... (Page 46)


- Plotting a rectangular box whose vertices are a point P and the projections on the xy-, xz-, yz-planes, and on the axes. - Vectors: Arithmetic operations on vectors, Dot and Cross products and norms ....(Page 47) - Vectors: polygon plots, area of parallelogram and volume of parallelepiped - Vector-Valued Functions, tangent and normal vectors, graphing Space Curves ....(Page 51) - Defining and Evaluating Functions in two or more variables ....(Page 56) - 3-dimensional plots ....(Page 57) - Partial Derivatives, the Gradient and Directional Derivatives ....(Page 63) - The Chain Rule - Maximum and Minimum Values of a Function of Two Variables - Lagrange Multipliers Method for Maximizing or Minimizing a Function Subject to Constraints. - Double and Triple Integrals ....(Page 69) - Vector Fields, Curl, Divergence, and Field Plots

5) The Simplex Method in Linear Programming ..... (Page 74) 6) Elementary Statistics ..... (Page 76)
7) Some Common Problems .... (Page 82)

Let's Start Mapleing!


The examples in this document use the classic traditional Maple worksheet exclusively. On a PC running Windows, if there is a Classic Worksheet Maple 10 icon on your screen Double-click the icon with the left mouse button to start Maple. If not, look under the Start menu, in All Programs, then select Maple 10, and then select Classic Worksheet Maple 10. A new window opens with a blank worksheet.

This is the Classic Worksheet window in which all commands are typed and where results will appear. There is a prompt (>) in the upper left corner and a cursor bar (|) indicating that Maple is ready for input. Maple commands must end with either a semicolon (;) or a colon (:). After you have typed a command you can execute it by hitting Enter. A semicolon tells Maple to calculate the input and display the result. A colon tells Maple to calculate the input and not to display the result. Pressing Enter anywhere in an input region causes Maple to process all of the expressions in the region.

Basic Computations and Functions


Simple expressions are entered in the same way you would expect, followed by the semicolon (;). As shown below, type 1+1; and then press Enter. Do not type the symbol [>. It comes by default when you are using the Classic Worksheet . > 1+1;

The space marked off by the square bracket [ is called an execution group. Maple will allow you to do more than one calculation inside an execution group. Type the following then press Enter: > 1+1; 2+2; 9/3; Maple uses ^ for exponent, * for multiplication, / for division, and uses sqrt(x) for square root of x. Type the following then press Enter: > 4^2; 3*2; 7/3-sqrt(2);

Maple uses abs(x) for absolute value of x, and exp(x) Type the following then press Enter: > abs(-2)+exp(3);

for ex .

Maple has the command evalf to convert results from exact to floating point (decimal) form. You might say evalf stands for "evaluate in floating point form". Type the following then press Enter: > evalf(%); Maple uses % as a ditto operator. It refers to the immediately preceding computed result anywhere in the worksheet! Maple can display the answer with very high precision. To approximate the number (Pi, with capital P), type the following then press Enter: > evalf(Pi); # This will produce the default 10 digits approximation.

To approximate the number up to 50 digits, for example, we use the command Type the following then press Enter: > evalf(Pi,50); #This will produce a 50 digits approximation to .

evalf(Pi, 50).

> evalf(sqrt(2),100);

#This will produce a 100 digits approximation to

2.

Maple supports all common mathematical functions, including all of the trigonometric, exponential, logarithmic, Bessel, Dirac, and Gamma functions. It does trigonometry using radian measure. To have an idea, we'll go over a small list of mathematical functions. Type and Enter each of the following lines : > 5!; > sin(Pi/4); > sin(Pi/4)^2;

# Capital P. # This is how to enter the expression sin2 4 .


Note: entering sin^2(Pi/4); is wrong!

> sin((Pi/4)^2); # This is how to enter the expression > > > > > > > > > > > > > >

sin

sinh(1.5); exp(1); # This is Euler's e evalf(exp(1)); # The command evalf converts a result from an exact to a floating point (decimal) form. cos(ln(3)); evalf(%); # % is a ditto operator. arctan(1); log[2](8); # Logarithm of 8 to the base 2. abs(-9); # This is |-9|. abs(1+I); # I in Maple denotes i = 1 norm(1+I,2); # This is the same as the absolute value of 1+I. sqrt(-9); (2+5*I)/(3-I); (2+I)^10; sqrt(8); 8^1/2; 8^(1/2); # You may put several commands or functions in one line.

Here are two useful procedures:


Procedure 1: Click on the Edit menu. Select the option "Remove Output > From Worksheet". That is how to clean your worksheet from the outputs. Procedure 2: Now, click the mouse somewhere in the first command you typed today, and then press the Enter key to evaluate the expression. Notice that when you evaluate a command, the cursor jumps ahead to the next command so that you can evaluate it. By repeatedly pressing the Enter key, you will eventually evaluate all of the commands in the worksheet. Please do so.

Decimal In, Decimal Out : In general you can get a decimal answer by typing, in decimal form, any one of the numbers in your input. Try the following input: > 2^4/3; But when entering 2. instead of 2, we get a decimal answer, as follows : > 2.^4/3;

The surd Command and the Odd Roots of Negative Numbers: Maple does not
return a real number when we compute odd roots of negative numbers. For example, type and Enter: > simplify((-8/27)^(1/3)); To obtain the result -2/3 which would be expected by most students, use the command surd , as follows: > surd(-8/27,3); For negative real x and odd n, surd(x,n) returns the real nth root of x. Thus, surd(-8/27,3)=-2/3.

EXERCISES on Numerical Calculations :


When entering expressions, be sure to include * between variables to denote multiplication.

1) Compute

.27 .23 .23( .77 )

200 Note. The answer is not 1.179535649. If you obtained this answer, please see the final section titled "Common Problems" at the end of this document.

2) Compute

84.72 14
2 2

38.22 6

84.7 14

38.2 6

14 1

This type of computation arises in Statistics II.

61

3) Compute ln( 81 ) up to 15 decimal digits. 4) Compute sin( 1 ) e2 up to 15 decimal digits. 5) Compute e


ln( )

up to 15 decimal digits.

The answers, respectively are: 1.344205626 , 6.21767631236797 , 3.14159265358979.

17.82736168 ,

4.39444915467244 ,

This is the end of Numerical Calculations. I hope you enjoyed it!

10

Pre-Calculus
When entering expressions, be sure to include * between variables to denote multiplication.

Solving equations (in one or more unknowns)


Maple solves equations with the commands solve and fsolve. To solve an equation for one of its variables, Maple has the

Syntax:

solve(equation, variable)

If the equation has one variable, then the variable argument becomes optional. Type the following then press Enter: > solve(y=m*x+c,x); > solve(y=m*x+c,c); > solve(.21*x^2-3*x-1.9=0); Let us now try to solve the equation e = x. Type and Enter: > solve(exp(-x)=x, x); As you see, the answer is a function you have never heard of. You have three options to obtain a numeric solution: Option 1: Use the command evalf to convert results from exact to floating point (decimal) form. > evalf(%); # remember that Maple uses % as a ditto operator.
( x )

Option 2: (Decimal In, Decimal Out). In general you can get a decimal answer by typing, in decimal form, any one of the numbers in your input. Let us type 1.*x in the input as follows: > solve(exp(-x)=1.*x, x);

Option 3: Use the command fsolve as follows: > fsolve(exp(-x)=x, x);

11

fsolve is a command used to find floating point (decimal) solutions as you have seen in the previous example. It has the

Syntax:

fsolve(equation, variable)

fsolve(equation, variable=a..b)

The second syntax tells Maple to find solutions only in the domain [a,b]. Type the following then press Enter: > fsolve(sin(x)+x^2=1,x=0..1);

Solving Systems of Equations:


Maple solves a system of equations with the commands solve and fsolve.

Syntax: Syntax:

solve({equation 1, equation 2, etc}) fsolve({equation 1, equation 2, etc})

Please observe the { } around the equations. Example: Suppose you want to solve the system: 3x+yz=8 2x1=3y+z x+y+z=0 Then type the following and press Enter: > solve({3*x+y-z=8, 2*x-1=3*y+z, x+y+z=0});

In the next example, observe how the command fsolve returns a decimal solution while the command solve returns the exact solution: > fsolve({r=2, r=2*(1+cos(theta))}); > solve({r=2, r=2*(1+cos(theta))});

12

Note: (Decimal In, Decimal Out). Try the following input, where we use 3. instead of 3 : > solve({3.*x+5*y=2, x+7*y=9}); Note: If, when solving an equation or system of equations, Maple returns nothing, then this indicates that there is no solution; the system is inconsistent. Try the following: > solve(x+1=x);

Simplifying Expressions Syntax:


simplify(expression)

This is how to simplify an algebraic expression. To simplify the expression e


( ln( 2 ) + 3 ln( 5 ) )

, for example, type and Enter

> simplify(exp(ln(2)+3*ln(5)));

To simplify the expression sin( arctan( x ) ), type and Enter > simplify(sin(arctan(x)));

The sum and/or difference of fractions written using the least common denominator is said to be x in its "normal form". To obtain the normal form of the expression + x, for example, type x+1 and Enter: > normal(x/(x+1)+x); or, > simplify(x/(x+1)+x);

13

Here is another example: To simplify

1 x3

1 x + x2 x3

, type and Enter

> normal(1/x^3-(1-x+x^2)/x^3);

To simplify an algebraic expression subject to conditions in the form of equations, Maple has the

Syntax:

simplify(expression,{equation 1, equation 2, etc})

Please observe the {} around the conditions. x3 + x2 + 1


3 2 subject to the condition x + x = u, type & Enter:

For example, To simplify

x+1 > simplify((x^3+x^2+1)/(x+1),{x^3+x^2=u});

The following example shows how to replace tan(x) by y: > simplify(tan(x)/sqrt(1-tan(x)), {tan(x)=y});

In the last two examples, please observe the {} around the conditions.

Expansion of Expressions
Maple expands expressions with the command expand.

Syntax: expand(expression)
Type the following then press Enter after each: > restart: > p:=expand((3*x-2)*(x+2)*(x^2-1)); # Note: In Maple, mathematical expressions can be named using the symbol := that is a colon (:) followed by an equal sign (=). If the exponents are not in descending order, then issue: > sort(p);

14

Here is another example on using the command expand. Type and Enter the following: > expand(cos(a+b)); expand(sin(2*x));

Also, you may tell Maple not to expand a subexpression in an expression as in the

Syntax:

expand(expression, subexpression 1, subexpression 2, etc)

Type and Enter the following: > y:=expand((3*x-2)*(x+2)*(x^2-1),(x^2-1)); y to the mathematical expression. # Here we gave the name

Now if you want y to be in the normal polynomial form, then use simplify or normal: > normal(y);

Factoring Polynomials
Maple factors polynomials with the command factor.

Syntax:

factor(polynomial)

Type the following then press Enter: > restart: > factor(3*x^4-7*x^2+4*x^3-4*x+4); > factor(tan(x)^3-8); If a polynomial has no real roots, then Maple returns the polynomial as is. Try the following: > factor(x^2+4); As you see, Maple did not find "real roots", so it returns the polynomial as is. Now, you may let Maple factor the polynomial over the complex field by using the option 'complex' as follows: > factor(x^2+4, 'complex');

15

Partial Fraction Decomposition


Maple determines partial fraction decomposition of rational expressions with the command convert.

Syntax:

convert(rational expression, parfrac, x)

Type the following then press Enter: > convert(1/((x-1)*(x-2)),parfrac,x); > convert(x^2/(x-3)^2,parfrac,x); In general, by the convert command we can convert mathematical expressions to other forms. For example, a decimal number to a rational, or a trigonometric function to an exponential one, etc. Type the following then press Enter: > > > > > convert(.5342,rational); convert(sin(x),exp); simplify(%); convert(4+3*I,polar); convert(12,binary);

Substitution AND Evaluation


Maple EVALUATE expressions at subexpressions with the command eval.

Syntax:

eval(expression, x=a)

This is how to evaluate an expression at the point a. Type & Enter: > eval(32/x,x=16); > eval(cos(x)+sec(x), x=0); To simplify x3 + x2 + 1 x+1 subject to the condition x=24, type:

> eval((x^3+x^2+1)/(x+1),x=24);

16

> eval((a+b+c)^2, {a=1,b=x,c=2*y} ); In the last example, please note the use of the braces {a=1,b=x,c=y^3}. If you are substituting for more than one value you should include them in braces.

Maple SUBSTITUTES subexpressions into an expression with the command subs, but it does not necessarily simplify the result.

Syntax:

subs(x=a,expression)

This is how to substitute a for x in the expression.

Syntax:

subs(s1, s2, ..., sn, expression)

Here s1, s2, ..., sn are equations where for each, the right-hand side is substituted for the left-hand side in the expression! Type & Enter: > subs(x=16,32/x); > subs(x=0,cos(x)+sec(x)); In the previous example the command subs does a strict syntactic substitution, and does not evaluate the results. For this reason, the command eval is preferred. > subs(tan(x)=y, tan(x)/sqrt(1-tan(x))); > subs(a=1,b=x,c=2*y, (a+b+c)^2 );

17

Naming Mathematical Objects using the symbol ":="


Mathematical and graphical objects can be named with Maple using the symbol := that is a colon(:) followed by an equal sign (=). Once an object is assigned a name in this manner, you can use the name as if it were the object. This an important feature of Maple, since we can avoid typing the same expression repeatedly. The name of an expression can be a single letter or more. Error will occur when attempting to assign an expression or object to a word which is protected, i.e. used by Maple. For example you cannot use tan as a name for some object.

Syntax:

name := expression

Example 1: Type the following then press Enter: > ma:=2^(1/2); Now enter > ma+ple; Example 2: Type the following then press Enter: > > > > eq1:=3*x+y-z=8; eq2:=2*x-1=3*y+z; eq3:=x+y+z=0; solve({eq1,eq2,eq3});

Example 3: Here we name a system of linear equations sys, then we solve sys and name the solution set sols, and then we verify the result by using the subs function; namely, substituting the solutions obtained back into sys. Type the following then press Enter: > sys:={x+5*y-2*z-w=4,3*x+2*y+z+5*w=3,3*x+4*y-z+2*w=2,6*y-7*z-2 *w=-2}; > sols:=solve(sys); > subs(sols,sys); Also, you may use the eval function to verify the result ; namely, > eval(sys,sols);

18

Warning: It is a common mistake to type either = or : without the other. Note: If you open a saved worksheet , Maple will not remember the assignments using ":=" made last time. You need to execute them, by clicking on their lines and press Enter. You may select the menu "Edit > Execute > worksheet" to execute all the commands in the worksheet. Note: The command restart: clears Maple's memory of any previous procedures, assignments or packages. Try the following: > x:=1; > x+2; > restart: > x+2;

19

Defining, Evaluating and Composition of Functions in one variable


Maple defines functions in one variable according to the

Syntax:

function's name := variable -> expression

and Piecewise-Defined Functions in one variable according to the

Syntax: function's name :=

variable -> piecewise(domain1, expression1, domain2, expression2, etc)

Type the following then press Enter: > f:=x->sqrt(x); To evaluate f at x=9 or at x=t+h, type > > > > f(9); f(t+h); g:=u->u^3+1; g(2); x2 cos( x ) 0<x x0

To define a piecewise-defined function, say p := { Type and Enter:

> p:=x->piecewise(x>0,x^2,x<=0,cos(x)); If you would rather see the common expression, then issue > normal(p(x)); > p(0); # this is how to evaluate the function p at x=0.

The name of an expression or a function can be a single letter or more as in the following examples. Type the following then press Enter: > buffalo:=u->abs(u); > buffalo(snow);

20

Composition of Functions:
The symbol @ is used for composition of functions. That is, understands f(g(x)). Type the following then press Enter: > > > > > f:=x->sqrt(x); g:=x->x^3+1; (f@g)(x); # remember "g then f". f(g(2)); g(f(x)); # remember "f then g". (f@f)(x);
(f@g)(x)=(fog)(x). Also,

Maple

Another application of the symbol @ is composing a function with itself n times. The following example will illustrate that. To compose f with itself 5 times, type: > (f@@5)(x);

21

2-dimensional Plots
In this section we discuss the following commands: plot, implicitplot, polarplot To delete a graph, click on it to enclose it in a frame then press the Delete key.

plot
To graph a function f(x) in a variable x, on an interval from x=a to x=b, Maple has the plot command.

Syntax:
or

plot(function's expression, x=a..b, options)

Syntax:

plot(f(x), x=a..b, options)

no space is allowed between the dots "..". Type the following then press Enter: > plot(x^2,x=-1..1); NOTE: Maple chooses the scale on the x-axes and the y-axes independently. To force Maple to use the same scale on both axes you can choose the option "scaling=constrained" when using the plot command. Compare the next graph with the previous one. Type the following then press Enter: > plot(x^2,x=-1..1,scaling=constrained); You may focus on a given range in the y-dimension. To force Maple to plot the graph in a range [c,d] you can choose the option "y=c..d" . Compare the next two graphs. Type the following then press Enter: > plot(1/x,x=-5..5); > plot(1/x,x=-5..5,y=-4..4); The "y=" is optional, as in the following example: > plot(tan(x),x=-2*Pi..2*Pi,-4..4); To remove the vertical asymptotes, you can choose the option "discont=true" as follows:

22

> plot(tan(x),x=-2*Pi..2*Pi,-4..4,discont=true); Maple can also graph pre-defined functions, and pre-named expressions. Type the following then press Enter: > f:=x->sin(1/x); > plot(f(x),x=-1..1); > > > > #Here we defined a function f.

w:=sum(sin(n*t),n=1..10); #Here we named the expression a w. plot(w,t=-2..2); p:=sum(sin(n*t),n=1..3)/sum(cos(n*t),n=1..3); plot(p,t=1..10,y=-10..10);

You may choose a color for the curve. Use the

Syntax:

plot(f(x), x=a..b, color=color_name)

where the color_name option can be red, blue, gold, brown, black, navy, cyan, maroon, orange, pink, sienna, tan, turquoise, violet, wheat, white, yellow, gray, grey, khaki, aquamarine, green, magenta, plum. Type the following and press Enter: > plot(cos(1/x), x=-10..10,color=gold); You may choose a title for the curve. Use the

Syntax:

plot(f(x), x=a..b, title=`T`)

where T is the title. Type the following and press Enter : > plot(cos(1/x),x=-10..10,color=navy, title=`Graph_of_cos(1/x)`); Please observe the use of `...` not the '...' around the title! Finally, here is an example of plotting a piecewise-defined function : > f:=piecewise(x<0,0, x>0 and x<1,x, x>1 and x<2,x-2, x>2,0); > plot(f,x=-5..5);

23

implicitplot
Assuming that the equation g( x, y ) = 0 defines y as a function of x , Maple has the implicitplot command to graph the equation, as in the

Syntax:

implicitplot( g(x,y)=0, x=a..b, y=c..d, options)

Note: In implicitplot and plot , the INDEPENDENT variable x range must be specified first, then that of y.
implicitplot is contained in the plots package.

Example: To graph the unit circle x2 + y2 = 1, type & Enter: > with(plots): > implicitplot(x^2+y^2=1, x=-1..1,y=-1..1,scaling=constrained); To graph the hyperbola 9 x2 4 y2 18 x 8 y = 31 , type & Enter: > implicitplot(9*x^2-4*y^2-18*x-8*y=31, x=-10..10, y=-10..10);

Graphing Several Functions at Once


To graph several functions or expressions in one variable, say x, simultaneously, on an interval from x=a to x=b, Maple uses the

Syntax:

plot({expression1, expression2, etc}, x=a..b)

where the expressions are enclosed in curly brackets { } . Here is an example of plotting a line and a curve. Type & Enter: > f1:=x+4; > f2:=-x^2+9; > plot({f1,f2},x=-3..3); Here is another example of plotting three curves. Type & Enter: > plot({sin(x),sin(x/2),sin(2*x)},x=0..4*Pi);

24

You may choose to graph an expression in a point style and the other as a regular curve. > plot({sin(x),cos(x)}, x=-Pi..Pi, style=[point,line]); Finally, here is a unit circle composed of two curves: > plot({sqrt(1-x^2),-sqrt(1-x^2)},x=-1..1, scaling=constrained);

You may plot the upper semi-circle in a blue point style , and the lower semi-circle in a gold regular curve. Use the style and color options as follows: > plot({sqrt(1-x^2),-sqrt(1-x^2)},x=-1..1, style=[point,line],color=[blue,gold],scaling=constrained);

We may plot a text in two dimensional space. Here is an illustration: > f1:=4-(1/3)*x: f2:=6: f3:=(3/2)*x+2: > with(plots): p := plot({f1,f2,f3},x=0..8,y=0..8,thickness=2): t1 := textplot({[8,.9,`C`],[8,6,`B`],[4.2,8,`A`]},align=ABOVE): display({p,t1});

Graphing Polar Functions


To graph polar functions r=f() on an interval from =a to =b, Maple has the polarplot command.

Syntax:

polarplot(f(theta), theta=a..b, options)

polarplot is contained in the plots package.

Type the following and press Enter: > with(plots): > polarplot(sin(2*theta), theta=0..2*Pi); > polarplot(theta, theta=0..4*Pi); Besides the command polarplot, we may use the the option coords=polar, as in the
plot

or

implicitplot

commands as above with

25

Syntax:

plot(function's expression , theta=a..b, coords=polar)

and, assuming that the equation g( r, ) = 0 defines r as a function of in polar coordinates, the implicitplot command can be used to graph the equation as in the

Syntax:

implicitplot(equation in r and theta, r=c..d, theta=a..b, coords=polar)

Important Note: If the option "coords=polar" is used in implicitplot, then the DEPENDENT variable r range must be specified first, then that of . Type the following and press Enter: > plot(sin(2*theta), theta=0..2*Pi,coords=polar); > plot({sin(theta),cos(theta)},theta=0..2*Pi,coords=polar, scaling=constrained); > implicitplot(r=2-2*cos(theta), r=0..4, theta=0..2*Pi,coords=polar); > implicitplot(r^2=cos(2*theta),r=0..1,theta=0..2*Pi, coords=polar);

Plotting Curves Defined Parametrically


To plot curves defined parametrically, say in a variable t from t=a to t=b, we can also use the plot command as in the following

Syntax: plot([expression1, expression2, t=a..b])


where the whole input is enclosed in square brackets [ ] . Type and Enter the following: > plot([sin(t),cos(t), t=0..2*Pi],scaling=constrained); # This is a circle of radius 1. We could have defined two functions, x and y, then plot them parametrically as a curve, as follows: > x:=t->sin(t); > y:=t->cos(t); > plot([x(t),y(t), t=0..2*Pi],scaling=constrained);

26

Also try: > plot([x(t),y(t), t=0..2*Pi],-2..2,-2..2,scaling=constrained); If these functions were in the polar coordinates system, then we would type & Enter: > plot([x(t),y(t), t=0..2*Pi], coords=polar,scaling=constrained);

27

Graphing a Region Determined by a system of Linear Inequalities


The region can be graphed using the command inequal, which is contained in the plots package.

Example: Graph the solution of the three linear inequalities: 2x + 4y >= 8 , -x + 3y <= 2 , y >= 0 . Solution: Type and Enter: > with(plots): > inequal({2*x+4*y>=8,-x+3*y<=2},x=0..5, y=0..5); Or, > inequal({2*x+4*y>=8,-x+3*y<=2},x=0..5,y=0..5, optionsexcluded=(color=white));

Point Plotting
This is straight forward in Maple. First enter the points and then plot them, as follows: Type and Enter: > datapoints:=[[35.5,1], [45.5,2], [55.5,5], [65.5,15], [75.5,25], [85.5,20], [95.5,12]]; > plot(datapoints,style=point); If we wish, we may plot the points joined by line segments, as follows: > plot([datapoints,datapoints],style=[point,line]); Sometimes the points are given by a formula. In this case define the formula first, then plot the points. Here is an example: > data := [[ -n, cos(n-1)] $n=-5..5]; plot(data, x=-15..15, style=point,symbol=circle);

28

Some Matrix Calculations


Matrix calculations require the LinearAalgebra package to be loaded into Maple's working memory. Type the following and press Enter: > restart: with(LinearAlgebra): Let us make up some matrices and do some computations on them:

> > > > > >

L:=Matrix([ [1, 2], [-1,5] ]); M:=Matrix([ [0, 2], [1, -1] ]); 3*M; #This is how to perform scalar multiplication. X:=L+M-3*M; #This is how to add and subtract matrices, and call the result X. M.X; #This is how to multiply the two matrices M, X to get MX. N:=Matrix(3,2,fill=1); # This is how to construct a 3x2 matrix of 1s.

The following examples are self-explanatory: > > > > > > > > > > P:=DiagonalMatrix([1,-1,1]); IdentityMatrix(3); MatrixInverse(M); 1/M; # This is another way to compute the multiplicative inverse of M. Determinant(M); Adjoint(M); Transpose(M); Trace(M); Eigenvalues(P); # Eigenvalues of the square matrix P. Eigenvectors(P); # The Eigenvectors(A) command solves the simple eigenvalue problem by returning an expression sequence whose first member is a vector V of the eigenvalues of A, and whose second member is a Matrix E whose columns are the eigenvectors of A. The ith column of E is an eigenvector associated with the ith eigenvalue of the returned vector V. > CharacteristicMatrix(P,lambda);
0 2 5

Exercise: Solve for x the matrix equation x a x = d where a :=


2 d := 1 3

1 3 2

2 1 and 3

29

Solution: First re-write the equation x a x = d in the form ( i a ) x = d, where by i we mean the identity 3x3 matrix. Next solve the system with the LinearSolve command, as follows: > restart: with(LinearAlgebra): > a:=Matrix([ [0, 1, 2], [2,3,-1], [5,-2,3] ]); > i:=IdentityMatrix(3); Now to input the column matrix d, here are two options: > d:=Matrix([[2],[1],[3]]); Or, as a vector > d:=<2,1,3>; Finally, solve the system ( i a ) x = d with the LinearSolve command: > solution:=LinearSolve(i-a,d);

This is just a start. Maple can compute basis and spans of row and column vector spaces. It allows for exponentials of matrices and vectors calculations, and a whole host of other linear algebra tools. To see more, Enter: > with(LinearAlgebra);

30

Sums, Sequences and Power Series


Sums:
To find the sum

k = b , Maple uses the

k=a

f( k ) of values of an expression f( k ) over a range of integers k = a

to

Syntax:

sum(f(k), k=a..b)

Example: To find the sum

k=1

10

( k2 k ), type the following and press Enter:

> sum(k^2-k, k=1..10);

Example: To find the sum

, type the following and press Enter: 3n > sum(1/3^n+1/4^n, n=1..infinity);

4n

Two more examples: > sum(1/n^2, n=1..infinity); > sum(1.0/k!, k=1..50);

Sequences:
To find the values of a sequence f(k) of numbers, say from k=a to k=b, Maple uses the

Syntax:

seq(f(k), k=a..b)

Examples: Type the following and press Enter: > seq(k!, k=0..4); > seq(i^2, i=100..105);

Power Series:
Power Series are usually discussed in Calculus II. To compute the power series expansion of a function f(x) about the point x=a up to order n , Maple uses the

31

Syntax:

series(f(x), x=a,n)

Note: n is optional. If n is not specified, Maple will compute the series up to order 7.

Syntax:

series(f(x), x)

If this syntax is used then Maple will compute the series about x=0 up to order 7. Examples: Type the following and press Enter: > > > > series(sin(x),x); series(sin(x),x=0,10); series(exp(x),x); series(ln(x),x=1,5);

EXERCISES on Pre-calculus:
Solve the following exercises using Maple tools such as "implicitplot, plot, factor, solve ", and any others. When entering expressions, be sure to include * between variables to denote multiplication.

= 1. 16 4 2) Graph the functions f( x ) = x2 and g( x ) = 2 x simultaneously on the interval [-3,3]. 19 19 3) Graph the polar function f( ) = cos( ) on the interval , 2 2 4) Factor the polynomial 276 x3 + 69 x2 y 48 x y 12 y2 1) Graph the ellipse 5) Graph the function f( x ) = x4 + 4 x3 7 x + 2 from x=-4 to x=2, and find its roots. 6) Factor completely: 3 y( 5 y 2 ) + 3 y( y 7 ). 7) Solve the equation 2 cos( x ) = 2 x x3 on the interval [-2.5, 2.5] . 8) Use Maple to find the intersection algebraically and graphically of the two lines defined by 3x+2y=5 and 2x+4y=5 in the xy-plane. 9) Plot the curve whose parametric equations are: x( t ) = sin( t ) cos( 3 t ) and y( t ) = sin( 3 t ) cos( t ) , for t from 0 to 2 . 0 15 43 2 10) Solve for x the matrix equation x a x = d where a := 2 3 20 and d := 1 1 81 51 3 This is the end of the Pre-Calculus Section. I hope you enjoyed it!

x2

y2

32

Calculus
Limits, differentiation, and integration
These computations are straight forward in Maple. The following table displays the syntax in which Maple does such computations.

Syntax
limit(expression, variable=c) limit(expression, variable=c, left) limit(expression, variable=c, right) D(f)

Comments
#two-sided limit as variable approaches c #left limit as variable approaches c #right limit as variable approaches c #derivative of a function f of one variable #derivative with respect to variable #the n-th derivative with respect to variable #indefinite integration with respect to variable #definite integration from var=a to var=b

or, D[1](f)

diff(expression,variable) diff(expression, variable$n) int(expression, variable) int(expression, variable=a..b)

EXAMPLES On Limits: Type the following and press Enter:


> limit(1/x,x=0); > limit(1/x,x=0,left); > limit(1/x,x=0,right); # two-sided limit of 1/x as x approaches 0 # left limit of 1/x as x approaches 0. # right limit of 1/x as x approaches 0.

> limit((1/3)^n, n=infinity); # the limit of the sequence

> limit(sin(x^2)/sin(2*x)^2 , x=0); # this is lim


x0

3 sin [ x2 ]

as n goes to infinity .

sin2 [ 2 x ]

You can use the name of the expression instead of the expression itself when computing limits, for example: > g:=sin(x)/x; > limit(g,x=0);

33

EXAMPLES On Differentiation: There are two commands to find derivatives: D and diff.
The input and the output of D is a function . The input and the output of diff is an expression. Type the following and press Enter: > > > > > > f:=x->sin(x^2); D(f); # first derivative of the function f with respect to x. D[1](f); # first derivative of the function f with respect to x. D(D(f)); # second derivative of the function f with respect to x. D[1,1](f); # second derivative of the function f with respect to x. D[1,1,1](f); #third derivative of the function f with respect to x. #derivative of 1/x with respect to x. #The 50-th derivative of 1/x with respect to x.

> diff(1/x,x); > diff(1/x,x$50);

Note: You can compute the second derivative with respect to x by typing either > diff(1/x,x$2); or, > diff(1/x,x,x); Similarly for computing the third or higher derivatives. More Examples: Here we name an expression and use the name to avoid typing the same expression when performing computations. Type the following then press Enter: > g:=sin(x)/x; > d:=diff(g,x); If you would rather have a common denominator, you can type

> simplify(d); or, > normal(d); > simplify(diff(g,x$2)); derivative.

# This is how to compute and simplify the second

34

Note: In Maple there is a difference between using a named expression or a defined function. If
you define a function in one variable then you must evaluate the function at the variable for further calculations such as derivatives and limits. Type the following then press Enter: > > > > > h:=x->sin(x); diff(h,x); diff(h(x),x); limit(h,x=0); limit(h(x),x=0);

Exercise: Let f( x ) = e

2 ( x )

. Find f ' (x) and f ' (2).

Solution 1: Type and Enter: > f:=x->exp(-x^2); > D(f); > D(f)(2); # This is because the output of D is an operator! Solution 2: Type and Enter: > f:=x->exp(-x^2); > d:=diff(f(x),x); > eval(d,x=2);

35

Implicit Differentiation: A method for finding the derivative of an implicit function without
solving the defining equation for the dependent variable in terms of the independent variable is explained in the following Example: Assuming that the equation x2 y3 = x y defines y as a function of x, find differentiation. Answer: Type the following then press Enter : > eq:=x^2-y^3=x*y; > Dy:=implicitdiff(eq,y,x); dy dx

by implicit

A second method is the following: Tell Maple that y is a function of x, by replacing y by y(x) . Type and Enter: > eval(eq,y=y(x)); > diff(%,x); #The derivative of both sides with respect to x. > solve(%,diff(y(x),x)); #Solving for the derivative. Now replace y(x) by y : > Dy:=eval(%,y(x)=y); Obviously, using the command implicitdiff is more efficient.

36

EXAMPLES On Integration:

Type the following and press Enter:

> int(1/x,x); # indefinite integration of 1/x with respect to x. No integral constant c. > int(1/x,x=1..exp(1)); #definite integration of 1/x from x=1 to x=e.
x

> int(1/(x*ln(x)^2),x);

# the indefinite integral

1 ln2 x

dx
integral

> int(1/(x*ln(x)^2),x=2..infinity);

# the improper

1 x ln2 x

dx

To convert results from exact to floating-point (decimal) form, you may issue the command evalf as follows. (Recall that Maple uses % as a ditto operator.) > evalf(%);

Now type and Enter: > int(1/(exp(x)-x),x=1..2); What happened here? Can you find an approximation?

The surd Command and the Odd Roots of Negative Numbers: Maple does not return
a real number when we compute odd roots of negative numbers. For example, type and Enter: > evalf((-8)^(1/3)); To return the real-valued third root of -8, use the command surd as follows: > surd(-8,3); For negative real x and odd n, surd(x^n,n) returns x. Thus, surd( 8, 3 ) = 2. Here is a situation : > int(1/x^(2/3),x=-1..1); which has a result that might surprise improper-integral students. To return the real-valued third root

37

of x, use the command surd as follows: > int(1/surd(x,3)^2,x=-1..1);

Loops
Here are three applications: 1) Suppose you want to compute the first five derivatives of the function f( x ) = x5 7 x3. Then use the following loop: > for n from 1 by 1 to 5 do diff(x^5-7*x^3,x$n) od; 2) If some expression depends on n, for example sinn x, and you want to run an operation, for example ntegration, for the values of n from n=2 to n=8 increased by 2 each time, then use the following loop: > for n from 2 by 2 to 8 do int(sin(x)^n,x) od; 3) Another example is this: suppose you want to differentiate sinn x for n=1, 11, 21, 31, then type: > for n from 1 by 10 to 31 do diff(sin(x)^n,x) od;

38

Some Ordinary Differential Equation Calculations


In this section we present three basic examples on ordinary differential equations and use the built-in command dsolve to solve them. For more information about dsolve, type and enter ?dsolve at the Maple prompter > . NOTE: If y(x) is a function of x, then each time we type the dependent variable y we should be careful to include the argument x. Example 1: Let us make up the linear first order differential equation built-in command dsolve. Type and Enter: > restart: #clears Maple's memory of any previous work. > eq1:=diff(y(x), x) + 2*y(x) = exp(-x); Now to solve eq1 for y(x) , type and Enter : > dsolve(eq1, y(x)); Suppose we are given the initial condition y( 0 ) = and Enter : > dsolve({eq1, y(0)=3/4}, y(x)); Please observe the { } around the equation and the initial condition. Example 2: Let us make up the linear second order differential equation command dsolve. Type and Enter: > eq2:=diff(y(x),x$2)+y(x)=0; Now to solve eq2 for y(x) , type and Enter : > dsolve(eq2,y(x)); Suppose we are given the initial conditions y( 0 ) = 0 and D( y )( 0 ) = 1 . d2 y dx
2

dy dx

+2y=e

( x )

and solve it using the

3 4

. To solve the initial value problem, type

+ y = 0 and solve it using the

39

To solve the initial value problem, type and Enter : > dsolve({eq2,y(0)=0,D(y)(0)=1},y(x)); Please observe the { } around the equation and the initial conditions. Example 3: Let us make up the homogeneous differential equation ( y2 + 2 x y ) dx x2 dy = 0 and solve it for y(x). Type and Enter: > dsolve((y(x)^2+2*x*y(x))-x^2*D(y)(x)=0,y(x)); Please observe how the differential , dy, is typed, and how dx is ignored. This is just a start. Maple has a whole host of other differential equation tools contained in the DEtools package. For more information, type and Enter ?DEtools at the Maple prompter > .

40

Samples of Using Maple to Illustrate Calculus Ideas

Limits
Example 1: Compute lim
x0

sin( 2 x ) x

> f:=x->sin(2*x)/x; > plot(f(x),x); The graph suggests that lim f( x ) = 2. Further evidence can be obtained by computing the
x0

values of f(x) for values of x near 0, and observing that as x approaches zero, f(x) approaches 2 : > xvalues:=[seq((-1.)^rand()*rand()/10^(12+n),n=0..10)]; > map(f,xvalues); Now let us let Maple compute the limit, as follows: > limit(f(x),x=0); x2 + 25 5 x2

Example 2: Compute lim


x0

> g:=x->(sqrt(x^2+25)-5)/x^2; > plot(g(x),x=-100..100); x2 + 25 5 1

The graph suggests that lim

. Now let us check the values of g(x) as 10 x2 x approaches 0. We will use the same xvalues obtained above.
x0

> map(g,xvalues); In this example it seems that the values of g(x) approaches 0 as x approaches 0. Now let us let Maple compute the limit : > limit(g(x),x=0); So the table is not always helpful in suggesting that the true lim
x0

x2 + 25 5 x
2

1 10

41

Tangent Line Equation

Let

g( x ) =

x2 + 25 5 x
2 . Write an equation, in the form y=mx+b, for the

line tangent to the graph of the function at the point where x= .5 . Solution: > > > > > > > restart: g:=x->(sqrt(x^2+25)-5)/x^2; D_x:=diff(g(x),x); m:=subs(x=.5,D_x); T:=y-g(.5)=m*(x-.5); tangent:=solve(T,y); plot([g(x),tangent],x,color=[red,blue]);

Riemann Sums: Area under a curve and above the x-axis.


3 Example: Find the area under y = x + 1 and above [0,3]. Solution:

> restart:plot(x^3+1,x=0..3); > f:=x->x^3+1; > with(student):rightbox(f(x),x=0..3,5,title=`five subdivisions`); > rightsum(f(x),x=0..3,5);value(%);evalf(%); > rightbox(f(x),x=0..3,15,title=`fifteen subdivisions`); > rightsum(f(x),x=0..3,15);value(%);evalf(%); > rightbox(f(x),x=0..3,50,title=`fifty subdivisions`); > rightsum(f(x),x=0..3,50);value(%);evalf(%); > Sum(f(0+3/n*i)*3/n,i=1..n); > area_n:=simplify(value(%)); > limit(area_n,n=infinity); > int(x^3+1,x=0..3);

42

Area Between Two Curves Example 1: Find the area enclosed by y = x2 + 9 and y = x + 3. Solution: > > > > > > restart:f:=-x^2+9; g:=x+3; s:=solve(f=g); # or, solve({y=-x^2+9,y=x+3}); area:=int(f-g,x=-3..2); #or area:=int(f-g,x=s[1]..s[2]); plot({f,g},x=-5..5);

Example 2: (On the area between two curves.) Find the area inside the graph of r = 1 and outside the graph of r = cos( 3 ). Solution: The required area is the difference between the area of the unit circle and the area of the three-leafed rose. Thus: > area:=int(1/2*1^2,theta=0..2*Pi) 3*int(1/2*cos(3*theta)^2,theta=-Pi/6..Pi/6);

Riemann Sums: Comparison of the three standard Area Approximations (right endpoints, midpoints, left endpoints): > > > > > > > > > > > > restart:with(student):f:=x->x^3+1; rightbox(f(x),x=0..3,20); Rapprox:=rightsum(f(x),x=0..3,20); evalf(%); middlebox(f(x),x=0..3,20); Midapprox:=middlesum(f(x),x=0..3,20); evalf(%); leftbox(f(x),x=0..3,20); Leftapprox:=leftsum(f(x),x=0..3,20); evalf(%); actualarea:=int(x^3+1,x=0..3); evalf(%);

43

Note on Animation: When you start the animation, Maple displays the first frame. To play the animation, click on the image. A set of new icons will appear on the context bar. Click the Play button (the solid triangle) to play the animation. You can also use the other options to change the animation style; For example, you can play the animation continuously by clicking on the cycle-mode button .

An Animation of Riemann Sums Converging to an Integral


The following animation shows Riemann sums for the function 3 x x2, using n = 2, 4, 6, 8, ..., 40 subintervals. Change the function and/or the command rightbox to experiment with other curves and their Riemann Sums. > restart: with(plots): with(student): > pic := n -> [rightbox(3*x-x^2,x=0..3,2*n, tickmarks=[0,0])]; > display(seq(pic(n),n=1..20),insequence=true);

An Animation to illustrate the drawing of the cycloid


The cycloid is the locus of points generated by a fixed point of a circle as the circle rolls along a straight line. See the previous item on how to play the animation. > with(plots): > animate({[s+cos(t), 1+sin(t), t=0..2*Pi],[t-sin(t), 1-cos(t),t=0..4*Pi],[s-t*sin(s), 1-t*cos(s), t=0..1]},s=0..4*Pi,frames=50,color=blue, scaling=constrained);

An Animation to illustrate Solid of Revolution


> restart: with(plots): with(plottools): f := t -> t^3/2-2*t^2+2*t+1: start := spacecurve([0,t,f(t)],t=0..3, thickness=3,axes=normal,tickmarks=[0,0,0]): pic := n-> plot3d(f(z),theta=0..n*2*Pi/30,z=0..3,coords=cylindrical):

display(start,seq(rotate(pic(n),Pi/2,Pi/2,0),n=1..30), insequence=true);
Change the definition of the function in the second line, to experiment with other curves and their solids of revolution.

44

Exercises on Calculus
Solve the following exercises using Maple tools such as " plot, solve, int, diff, series ", and any others. When entering expressions, be sure to include * between variables to denote multiplication.

1) Given the function f( x ) =

sin( x ) x

, find its derivative and graph it.


3 2

2) Compute the 4th derivative of the function f( x ) = ( x2 + 5 ) ( x2 + 5 x )


( x sin( x ) )

3) Given y = e , find the arc length of the graph of f from x = 0 to x = . 4) Find the power series expansion of f(x)=arctan(x) about the point x=0. 5) Graph the function f whose values are given by f( x ) = tan( x ) when < x and x 0, 2 f( x ) = sin( x ) when 0 < x and x . 6) Assuming that the equation y = 2 x defines y as a function of x, find
2 3

d2 y dx2

by implicit

differentiation. = k y, where k = .60 and the dt initial condition is y( 0 ) = 20000. Then plot the solution between t=0 to t=5. Compute y(5). 7) Let y be a function of t. Solve the differential equation
3

dy

8) Evaluate the improper

integral

1 (x 1)

2 3

dx.

(Hint: answer=6.78, and recall

the command surd in the integration section.) 9) Compute the area of the region in the 4th quadrant bounded by the curve y = ln( x ) and the coordinate axes. Is the area finite or infinite? This is the end of the Calculus Section. I hope you enjoyed it!

45

Vectors and Multi-Variable Calculus


Plotting a rectangular box whose vertices are a point P and the projections on the xy-, xz-, yz-planes, and on the axes.
This section provides an exercise on plotting the rectangular box whose vertices are a point P and the projections on the xy-, xz-, yz-planes, and the axes. Recall that in plotting the point P(3,2,5), for example, we start from the origin and count 3 units along the positive x-axis, then 2 units to the right parallel to the positive y-axis, and then 5 units up, parallel to the positive z-axis.

Method 1: Using the command POLYGONS with the list of vertices. Type and Enter:
> restart:PLOT3D(POLYGONS([[0,0,0],[3,0,0],[3,2,0],[0,2,0]], [[0,0,0],[0,2,0],[0,2,5],[0,0,5]], [[3,0,0],[3,2,0],[3,2,5],[3,0,5]], [[0,0,0],[3,0,0],[3,0,5],[0,0,5]], [[0,2,0],[3,2,0],[3,2,5],[0,2,5]], [[0,0,5],[3,0,5],[3,2,5],[0,2,5]]), STYLE(HIDDEN), AXES(NORMAL), SCALING(CONSTRAINED), THICKNESS(3));

46

Method 2: By using the command

polygonplot3d. This command is used to create 3-D

plots of polygons by joining the points by line segments. To have a nice box, avoid connecting diagonals. First, we start by loading into Maple the plots package because the command polygonplot3d is contained in it. > restart: with(plots): > J:=polygonplot3d([ [3, 0, 0], [3, 2, 0], [0, 2, 0], [0, 2, 5], [0, 0, 5], [3, 0, 5], [3, 0, 0], [3, 0, 5], [3, 2, 5], [0, 2, 5], [3, 2, 5], [3, 2, 0]], axes=NORMAL, style=hidden, thickness=2): L:=textplot3d({[3,2,5.4,'P(3,2,5)'], [3,0,5.5,"(3,0,5)"], [0,2,5.5,"(0,2,5)"], [3,2,-0.5,"(3,2,0)"]},color=BLUE): > display3d({J,L});

Using Vectors: You may use the fact that the sum u+v of two vectors u and v coincides with
the diagonal of the parallelogram determined by u and v. To have a nice box, avoid connecting diagonals. > restart: with(plots): > px:=[3,0,0]: py:=[0,2,0]: pz:=[0,0,5]: > J:=polygonplot3d([px,px+py,py,py+pz,pz,px+pz,px,px+pz, px+pz+py,py+pz, px+py+pz,px+py],axes=NORMAL, style=hidden): L:=textplot3d({[3,2,5.4,'P(3,2,5)'], [3,0,5.5,"(3,0,5)"], [0,2,5.5,"(0,2,5)"], [3,2,-0.5,"(3,2,0)"]},color=BLUE): > display3d({J,L}); The command display3d is used to display, simultaneously, previously defined plots. The command textplot3d allows one to plot text in three dimensional space.

Vectors: Arithmetic operations on vectors, Dot and Cross products , and Norms
First, we load into Maple the LinearAlgebra and the plots packages since some commands are contained in them. Vector calculations requires the LinearAlgebra package to be loaded into Maple's working memory. Type the following and press Enter: > restart: with(LinearAlgebra):

47

The command restart: clears Maple's memory of any previous work. Let us make up two vectors u and v, and perform some vector operations on them. Type and Enter: > u:=<6,1,3>; v:=<4,0,-6>; > 3*v; # This is how to perform scalar multiplication. > x:=u+v-3*v; # This is how to add and subtract vectors, and call the result x. > DotProduct(u,v); # This is how to calculate the scalar " u > u.v; # This is another way to calculate the scalar " u dot v"
dot

v"

We calculate the vector "u

cross

v" by typing

> CrossProduct(u,v); # This is how to calculate the vector " u cross v" > u &x v; # This is another way to calculate the vector " u cross v". We calculate the angle "theta" between u and v by typing > VectorAngle(u,v); The decimal value of the angle (in radians) can be computed by typing > evalf(%); The cosine of the angle between the vectors can be calculated by typing > cos(VectorAngle(u,v)); As an application on dot product, we compute the vector "projection of u onto v", and name it proj, as follows: > proj:=(u.v)/(v.v)*v; # here the parentheses are needed.

We calculate the vector "component of u orthogonal to v", and name it orth, by typing > orth:=u-proj; We know that the dot product of proj and orth is zero. To check that type: > DotProduct(proj,orth);

48

Norm of a Vector
u = a, b, c is a vector, the syntax Norm(<a,b,c>,n) yields: ( a + b + c ) . Hence, we may compute the length of a vector by choosing n=2. For example, to find the length of u=<6,1,3> we type
n n n

1 n

> Norm(<6,1,3>,2); Also, we may use the name of [6,1,3], that is u . > u:=<6,1,3>; > Norm(u,2); Maple understands the notation u[i] as the ith component of the vector u , hence we may compute the length of u by typing > lenu:=sqrt(u[1]^2+u[2]^2+u[3]^2); The Norm command is more efficient, but also we may compute the length of u by typing > lenu:=sqrt(DotProduct(u,u)); Type

Vectors: polygon plots, area of parallelogram and volume of parallelepiped


The area of the parallelogram that has vectors u and v as adjacent sides is the length |u X v|, and the volume of the parallelepiped that has vectors u, v, and w as adjacent edges is the magnitude |u dot (v X w)|. In this part we will use Maple to compute such quantities and to graph parallelograms and parallelepipeds. Question: Find the area of the parallelogram in which the vertices are the points P(2,-1,0) , Q(3,2,2) , R(2, 4, -3) and the one opposite to P. Graph the parallelogram. Answer: To find the area, we enter the points (viewed as standard vectors), compute two edge vectors, then compute the norm of their cross product. Type the following and press Enter:

49

> restart: with(LinearAlgebra):

> > > >

P:=<2,-1,0>: Q:=<3,3,1>: R:=<2,4,-3>: PQ:=Q-P; PR:=R-P; X:=CrossProduct(PQ,PR); area:=Norm(X,2); (This command is

Now to graph the parallelogram, we use the command polygonplot3d . contained in the plots package). Type the following and press Enter:

> S:=PQ+PR; > with(plots):polygonplot3d([P,Q,P+S,R,P],axes=NORMAL); Question: Find the volume of the parallelepiped (i.e box) with adjacent sides the vectors u=<1,-3,1>, v=<4,0,-2> and w=<2,2,-4>. And graph the parallelepiped. Answer: To find the volume, we enter the vectors, compute u dot (v cross w) , then compute the absolute value of that. Type the following and press Enter: > u:=<1,-3,1>; v:=<4,0,-2>; w:=<2,2,-4>; > DotProduct(u,CrossProduct(v,w)); > abs(%); Now to graph the parallelepiped, we use the command polygonplot3d. Type the following and press Enter: > zero:=<0,0,0>; > P1:=polygonplot3d([zero,u,u+w,w,zero,v,v+w,w],axes=NORMAL, color=BLUE, orientation=[40,15]): P2:=polygonplot3d([u,v+u,u+v+w,u+w],color=BLACK): P3:=polygonplot3d([v,u+v,u+v+w,v+w],color=RED): > display({P1,P2,P3});

50

Vector-Valued Functions, Tangent and Normal Vectors, Graphing Space Curves


Defining and evaluating vector-valued functions; limits, derivatives, and integrals Maple defines vector function in a variable according to the

Syntax:

function's name := variable -> <components of the vector function>

although, in many cases, it is enough to name the expression as in the

Syntax:

name := <components of the vector function>

Limits, derivatives and Integrals of vector- valued functions require using the Maple package VectorCalculus; (otherwise the commands limit, diff, int will not work). If you are dealing with algebraic-expression functions, like the one in calculus I or II, then the commands limit, diff, int will work without loading the VectorCalculus package. Example: Typ the following and press Enter: > restart: with(VectorCalculus): > r:=t -> <cos(t),sin(t),t>; # here we named a 3-D vector-valued function r . > w:=<t^2-8*t, t^3, 1/2*t>; # here we named a 3-D vector w. The result is displayed in basis format, that is, as a sum of scalar multiples of basis vectors. Basis vectors are displayed by using the letter "e" subscripted by a coordinate name. Please observe: the first component of the expression w represents the x coordinate, the second represents the y coordinate, and the third represents the z coordinate. The Cartesian coordinates are assumed by default, but if you are working on a different coordinate system, and you would like to switch to the 3-D Cartesian coordinate system, then type and enter: > SetCoordinates( cartesian[x,y,z] ); , and the vector w at t=1. 4 The result is displayed in basis format, that is, as a sum of scalar multiples of basis vectors. Basis Observe below how to evaluate the vector-valued function r at t =

51

vectors are displayed by using the letter "e" subscripted by a coordinate name. Type and enter: > r(t); w; > eval(r(t),t=Pi/4); > eval(w,t=1);

On Differentiation:
The following examples illustrate how to differentiate the vector-valued function r and the vector w with respect to t: > diff(r(t),t); #this gives the first derivative of the vector-valued function r with respect to t. > diff(w,t); #this gives the first derivative of the vector w with respect to t.

You can compute the second derivative of r with respect to t by typing either > diff(r(t),t,t); or, > diff(r(t),t$2);

On Integration:
The following examples illustrate how to integrate the vector-valued function r and the vector w with respect to t. Type the following and press Enter: > r(t); w; # this gives the indefinite integral
cos( t ),

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

sin( t ), t dt

# this gives the indefinite integral

cos( t ),

sin( t ), t dt
cos( t ),
0 1

> int(r(t),t=0..1);

# this gives the definite integral


1

sin( t ), t dt

> int(w,t=0..1);

#his gives the definite integral

cos( t ),
0

sin( t ), t dt

52

On Limits:
> limit(r(t),t=2); # this is lim
t2

cos( t ),

sin( t ), t

To convert results from exact to floating-point (decimal) form, you may issue the command evalf as follows. (Recall that Maple uses % as a ditto operator.) > evalf(%); Another example is this: > limit(r(t),t=Pi/4); # this is lim
t

cos( t ),

sin( t ), t

> limit(w,t=1);

Tangent, Normal and Binormal Vectors.


Three vectors play an important role when studying the motion of an object along a space curve. These vectors are the unit tangent vector, the principal normal vector and the binormal vector.

Example 1. Let r( t ) = 1 + t3, t e , sin( 2 t ) . Find the unit tangent vector at the point
where t=0. Solution: Type the following and press Enter: > restart: with(VectorCalculus): > r:=t -> <1+t^3,t*exp(-t),sin(2*t)>: The derivative of r with respect to t is the tangent vector to the graph of r at t. Let us call it rprime. This vector can be obtained by either one of the following methods: > rprime:=diff(r(t),t); # or, > rprime:=TangentVector(r(t),t); As you see, the result is displayed in basis format, that is, as a sum of scalar multiples of basis vectors. Basis vectors are displayed by using the letter "e" subscripted by a coordinate name. By normalizing rprime we obtain the unit tangent vector at t. Let us call it
T.

( t )

53

> T:=1/Norm(rprime,2)*rprime;

Now by substitution we obtain the unit tangent vector at the point (1,0,0). Let us call it > T_at_0:=eval(T,t=0);

T_at_0.

Example 2. Consider the circular helix r( t ) = cos( t ), sin( t ), t . Find the unit tangent,
normal and binormal vectors at the point where t = Solution: Type the following and press Enter: > restart: with(VectorCalculus): > r:=t -> <cos(t),sin(t),t>; The derivative of r with respect to t is the tangent vector to the graph of r at t. Let us call it rprime. This vector can be obtained by either one of the following methods: > rprime:=diff(r(t),t); # or, > rprime:=TangentVector(r(t),t); As you see, the result is displayed in basis format, that is, as a sum of scalar multiples of basis vectors. Basis vectors are displayed by using the letter "e" subscripted by a coordinate name. By normalizing rprime we obtain the unit tangent vector at t. Let us call it > T:=1/Norm(rprime,2)*rprime; Now by substitution we obtain the unit tangent vector at the point where t =
T_at_FourthPi. T.

. Let us call it

> T_at_FourthPi:=eval(T,t=Pi/4); Next, we compute the derivative of T with respect to t. Let us call it Tprime. This is called the principal normal vector. It can be obtained by either one of the following methods: > Tprime:=diff(T,t); > Tprime:=PrincipalNormal(r(t),t); # Notice it is applied on the original curve r(t).

54

By normalizing Tprime we obtain the unit normal vector at t. Let us call it N. > N:=1/Norm(Tprime,2)*Tprime; Now by substitution we obtain the unit normal vector at the point where t =
N_at_FourthPi.

. Let us call it

> N_at_FourthPi:=eval(N,t=Pi/4); The binormal vector is the vector perpendicular to both the tangent and the normal to a curve at a point in three-space, given by the cross product "B = T cross N". Type and enter: > B:=CrossProduct(T,N); Now by substitution we obtain the binormal vector at the point where t =
B_at_FourthPi.

. Let us call it

> B_at_FourthPi:=eval(B,t=Pi/4);

55

Graphing Space Curves using the command spacecurve


This command is used to plot a three-dimensional curve (a space curve). It is contained in the plots package, and it has the Syntax:
spacecurve([components of the vector-valued function], options)

The first component of the vector-valued function represents the x coordinate, the second represents the y coordinate, and the third represents the z coordinate. Some of the options are illustrated in the following Examples: To graph the space curve [ sin( t ), cos( t ), t2 ] from t=0 to t=4*Pi, type & Enter: > restart: with(plots): > spacecurve(<sin(t),cos(t),t^2>,t=0..4*Pi, axes=normal); Also, we may assign a name for the function, then use the name to plot the curve, as follows: > r:=t -> <sin(t),cos(t),t^2>; > spacecurve(r(t), t=0..4*Pi, axes=normal, color=blue, title="Helix"); after you execute the command, note that if you click on the plot above, you can then rotate it by clicking and dragging.

Defining and Evaluating Functions in Two or More Variables


Maple defines functions in several variables according to the Syntax:
function's name := ( variable 1, variable 2, etc) -> expression

Type the following then press Enter: > > > > > f:=(x,y)->x^2+y^2; f(-1,1); f(x+h,y+k); g:=(x,y,z)->sqrt(x^2+y^2+z^2); expand(g(x+h,y+k,z+m));

56

3-Dimensional Plots
In previous sections we mentioned two commands: polygonplot3d, and spacecurve. In this section we introduce the following commands:
plot3d, implicitplot3d, display3d, contourplot & contourplot3d

The command display3d is used to display, simultaneously, previously defined plots. These commands require the plots package to be loaded , (except plot3d). Once a 3D-plot has been generated, the mouse may be used to rotate the graph so we may view it from different angles. Point at the graph and then adjust the angle values which will appear in the menu bar. Pull-down menus allows one to choose between different colors, and different surfaces (patch, contour, hidden-line, etc).

57

Here we start: plot3d Maple's plot3d is used to graph explicit functions, e.g. z=f(x,y) , on an interval from x=a to x=b and y=c to y=d. It has the Syntax: or the Syntax: plot3d(function's name, x=a..b, y=c..d, options) no space is allowed between the dots "..". Examples: To plot the surface z = sin( x y ) ; we type: > plot3d(sin(x*y),x=-Pi..Pi,y=-Pi..Pi, axes=frame); Maple can also graph pre-defined functions. To plot the surface z = type: x2 + y2 ; you may
plot3d(function's expression, x=a..b, y=c..d, options)

> z:=(x,y)->sqrt(x^2+y^2); > plot3d(z(x,y), x=-2..2, y=-2..2, axes=normal, style=contour, title=`elliptic cone`); The view can be improved with the view option, as follows: > plot3d(z(x,y), x=-2..2, y=-2..2,view=0..1.5,axes=normal, style=contour, title=`elliptic cone`); The same picture with the view option and the style patchcontour : > plot3d(z(x,y), x=-2..2, y=-2..2,view=0..1.5,axes=normal, style=patchcontour, title=`elliptic cone`); The same picture with the shade zhue : > plot3d(z(x,y), x=-2..2, y=-2..2,view=0..1.5,axes=normal, style=patchcontour,shading=zhue, title=`elliptic cone`);

58

display3d To plot two or more graphs at once, the command display3d is used to display, simultaneously, previously defined plots: Example: To plot the graphs of z = x2 + y2 and z = 10 ( x2 + y2 ) , simultaneously, first we define them, then we display them: > > > > with(plots): g1:=plot3d(x^2+y^2,x=-2..2,y=-2..2, axes=frame): g2:=plot3d(10-(x^2+y^2),x=-2..2,y=-2..2): display3d([g1,g2]);

implicitplot3d Maple's implicitplot3d is used to graph surfaces of the form g(x,y,z)=0 from x=a to x=b , y=c to y=d, and z=e to z=f. (we do not have to first solve the equation for z, as in using plot3d.) It has the Syntax: implicitplot3d(equation, x=a..b, y=c..d, z=e..f, options) or the Syntax: implicitplot3d(equation's name, x=a..b, y=c..d,z=e..f, options)

The command

implicitplots3d

is in the plots package.

> restart: with(plots): To graph the plane whose equation is 5x+y-3z+5=0, we would type: > implicitplot3d(5*x+y-3*z+5=0, x=-3..3, y=-3..3, z=-8..8, axes=normal, style=hidden); To graph the xz-plane, we would type: > implicitplot3d(y=0,x=-2..2,y=-3..3,z=-1..1, axes=normal, style=hidden);

59

To graph the ellipse

x2

4 9 > implicitplot3d(x^2/4+y^2/9+z^2=1, x=-2..2,y=-3..3,z=-1..1, axes=boxed);

y2

+ z2 = 1 ; type and enter:

Also, we may assign a name for the equation, then use the name to plot the surface, as follows: > ellipse:=x^2/4+y^2/9+z^2=1; > implicitplot3d(ellipse,x=-2..2,y=-3..3,z=-1..1, axes=boxed); Plotting Solid Surfaces Defined Parametrically Whereas a parameterization of a space curve is a function using a single independent variable t from an interval of the real number line to 3-space, a parameterization of a surface is a function using a pair (s,t) of independent variables s and t from a rectangle in the plane to 3-space. To plot solid surfaces in 3-space defined parametrically, say in two variables s and t from s=s1 to s=s2, and t=t1 to t=t2, we use the to plot3d command as in the following

Syntax: plot3d([expression1, expression2, expression3], s=s1..s2, t=t1..t2)


where the three expressions are enclosed in square brackets [ ] . For example, to produce a sphere with radius 1, type the following and press Enter: > plot3d([sin(s)*cos(t),sin(s)*sin(t),cos(s)],s=0..Pi, t=0..2*Pi, scaling=CONSTRAINED); We could have defined three functions, x, y and z, then plot them parametrically as a surface, as follows: > > > > x:=(s,t)->sin(s)*cos(t); y:=(s,t)->sin(s)*sin(t); z:=(s,t)->cos(s); plot3d([x(s,t),y(s,t),z(s,t)],s=0..Pi,t=0..2*Pi, scaling=CONSTRAINED);

Here is another example, where we map the st-rectangle s = 0 .. 2 , t = 0 .. 2 to a torus: > plot3d([sin(s)*(2+sin(t)),cos(s)*(2+sin(t)),cos(t)], s=0..2*Pi,t=0..2*Pi,scaling=CONSTRAINED,axes=boxed);

60

Level Curves (also called Contour plots) A contour plot is a graphical technique for representing a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format. That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs. The purpose is to display 3-d surface on 2-d plot. It is a commonly used way of visualizing a real-valued function of two variables. Imagine looking at the surface from above, and placing contour lines on the surface, each one a curve that is level in the sense that its height above (or below) the xy-plane is constant. The contour plot consists of the vertical projections of the countour lines onto the xy-plane; (Squashing three dimensions into two.) It is also possible to get a three dimensional version of contour plots. Syntax: contourplot(f,x=a..b,y=c..d, options) Syntax: contourplot3d(f,x=a..b,y=c..d, options) where f is an expression in x and y. The arguments x=a..b and y=c..d specify the horizontal and vertical ranges of the expression f. Both contourplot and contourplot3d take the same arguments and generate a contour plot for a given expression or function. The differences are as follows: contourplot3d generates a 3D view of the contours raised to their appropriate levels, whereas contourplot generates a flat 2D contour. The command contourplot and contourplot3d are in the plots package. Examples: Type and Enter the following: > f:=sin(x*y); > plot3d(f,x=-3..3,y=-3..3,axes=boxed); Here are the 2D and 3D level curves of the surface f : > with(plots): > contourplot(sin(x*y),x=-3..3,y=-3..3); > contourplot3d(sin(x*y),x=-3..3,y=-3..3); We may enhance the plots by adding some options as follows: > contourplot(sin(x*y),x=-3..3,y=-3..3,axes=normal, filled=true);

61

> contourplot3d(sin(x*y),x=-3..3,y=-3..3,axes=boxed, filled=true); > contourplot(sin(x*y),x=-3..3,y=-3..3,axes=boxed, filled=true,coloring=[blue,red]); A Comment about flat 2D contours: The height increments between any pair of adjacent contour lines are constant. Thus closely spaced contour lines indicate a steep region of the surface, while wide areas with no contour lines indicate relatively flat regions on the surface.

Rotating 3D Surface > with(plots): pic := n -> [plot3d(sin(sqrt(x^2+y^2)),x=-5..5,y=-5..5, orientation=[3*n,67],grid=[20,20])]; display(seq(pic(n),n=0..29),insequence=true);

It is actually the viewpoint that is being rotated by this Maple code, rather than the surface. However, the effect is that of the surface rotating in 3-space.

62

Partial Derivatives, the Gradient and Directional Derivatives


These computations are straight forward in Maple. The following table displays the syntax in which Maple does such computations. Syntax
D[i](f) D[i,j](f)

Comments
# derivative of a function f with respect to the i-th variable.

# derivative of a function f with respect to the i-th variable and then the j-th variable # derivative with respect to variable # the n-th derivative with respect to variable #the Gradient. This command requires the VectorCalculus package.

diff(expression,variable) diff(expression, variable$n)

Gradient(expression, [variable 1, variable 2, etc])

Recall that if f is a function of two variables x and y, and if f_x and f_y exist then the gradient of f is the vector [f_x, f_y]. Recall that the directional derivative of f in the direction of a unit vector u is the dot product : [f_x, f_y] dot u.

EXAMPLES On Differentiation: Type the following and press Enter: > restart: > f:=(x,y)->x^2+y^3; > D[1](f); > > > > > f x D[2](f); # This is f y D[1,2](f); # This is f y x D[2,2](f); # This is f y y diff(sin(x*y),x); #derivative of sin( x y ) with respect to x. diff(sin(x*y),y); #derivative of sin( x y ) with respect to y. # This is

You can compute the second derivative with respect to x by typing either > diff(sin(x*y),x$2);

63

or, > diff(sin(x*y),x,x); Similarly, to compute the mixed second partial derivatives with respect to (x then y), > diff(sin(x*y),x,y); and with respect to (y then x), type > diff(sin(x*y),y,x); Note: To avoid typing the same expression or function in performing various computations, we may name the expression or the function and use the name instead. Type the following then press Enter: > g:=sqrt(x)*exp(y+z); > diff(g,x); type

Note on Functions: In Maple there is a difference between using


defined function.

a named expression or a

If you define a function then you must evaluate the function at the variables if you want to use the commands diff. Example: Type the following then press Enter: > h:=(x,y)->ln(x*y); > diff(h,x); > diff(h(x,y),x); Exercise: Let f( x, y ) = e
2 2 ( x + y )

. Find

f( x, y ) and

d dx

f( 1, 2 )

Solution: Type and Enter: > f:=(x,y)-> exp(-x^2+y^2); > D[1](f); > D[1](f)(-1,2); # This is because the output of D is a function!

64

EXAMPLES On the Gradient and Directional Derivative: Exercise: Let f( x, y ) = sin( x y ) . Find the gradient of f( x, y ). Solution: The command Gradient is in the VectorCalculus package. Type the following and press Enter: > with(VectorCalculus): > Gradient(sin(x*y),[x,y]); #this is how to compute the gradient. The result is a vector field. The result is displayed in basis format, that is, as a sum of scalar multiples of basis vectors. Basis vectors are displayed by using the letter "e" subscripted by a coordinate name. If the Vector being displayed is actually a Vector Field, the basis vectors display with an overbar. The overbar is to visually distinguish a Vector Field from an ordinary Vector. Exercise: Let f( x, y ) = x2 3 x y . Find the directional derivative of f at the point P(2,0,4) in the direction of V=4i-3j. Solution: The directional derivative is the dot product of the gradient and the unit vector in the direction of V. So if we want to solve this exercise by hand, then we compute the gradient of f, we find a unit vector in the direction of V, then we compute the required dot product, and evaluate it at the given point. Maple takes care of that as follows: > f:=(x,y)->x^2-3*x*y; > D_u:=DirectionalDiff(f(x,y),<4,-3>,[x,y]); > eval(D_u,{x=2,y=0});

The Chain Rule


This can be done by substitution first, then differentiating the result. Or by differentiating a composition of functions.

Example 1: Suppose f( x, y ) = x2 y2 , where x = t2 u3 and y =


We will solve this exercise in two methods:

t u

. Find

df dt

and

df du

Method 1: We define the function f , we define the variables x and y as expressions, then differentiate f(x,y) first w.r.t t, and second w.r.t u.

65

> > > > >

restart: f:=(x,y)->sqrt(x^2-y^2); x:=t^2*u^3; y:=t/u; fprime_t:=simplify(diff(f(x,y),t)); fprime_u:=simplify(diff(f(x,y),u));

Method 2: In Maple there is a difference between using a named expression or a defined function. If you define a function then you must evaluate the function at the variables if you want to use the commands diff. > > > > > > > restart: f:=(x,y)->sqrt(x^2-y^2); x:=(t,u)->t^2*u^3; y:=(t,u)->t/u; fprime_t:=diff(f(x(t,u),y(t,u)),t); simplify(%); fprime_u:=diff(f(x(t,u),y(t,u)),u); simplify(%);

Example 2: Suppose z = x2 y, where x = t2 u3 and y =

t u

. Find

dz dt

Method 1: We define the variables z, x and y as expressions, then differentiate z first w.r.t t, and second w.r.t u. > restart: > z:=x^2*y; x:=t^2-u^3; y:=t/u; > diff(z,t): z_t:=simplify(%);

Method 2: Find the partial derivatives we need using the diff command. Then substitute in the x and y values and simplify: > restart: > z_t:=diff(x^2*y,x)*diff(t^2-u^3,t)+diff(x^2*y,y)*diff(t/u,t); > eval(z_t,{x=t^2-u^3,y=t/u}): z_t:=simplify(%); Obviously the first method is more efficient.

66

Maximum and Minimum Values of a Function of Two Variables


Question: Locate all relative maxima, relative minima, and saddle points of the function f( x, y ) = 4 xy x4 y4 Answer: We will use the command diff to find the partial derivatives f_x , f_y, f_xx, f_yy, f_xy, and the command solve to find the critical points. We will use the command subs to evaluate the partial derivatives at the critical points. Type the following and press Enter: > restart: f:=4*x*y-x^4-y^4; > f_x:=diff(f,x); f_y:=diff(f,y); f_xx:=diff(f_x,x); f_yy:=diff(f_y,y); f_xy:=diff(f_x,y); > solve({f_x=0,f_y=0}); > d1:=eval(f_xx*f_yy-(f_xy)^2,{x=0,y=0}); fxx_(0,0):=eval(f_xx,{x=0,y=0}); > d2:=eval(f_xx*f_yy-(f_xy)^2, {x=1,y=1}); fxx_(1,1):=eval(f_xx, {x=1,y=1}); > d3:=eval(f_xx*f_yy-(f_xy)^2, {x=-1,y=-1}); fxx_(-1,-1):=eval(f_xx, {x=-1,y=-1}); So at the point (0,0) a saddle point occurs, and at the points (1,1), and (-1,-1) relative maxima occur. Using Maple's plot3d you can plot the surface: > plot3d(f,x=-1.5..1.5,y=-1.5..1.5, axes=boxed, orientation=[86,81]);

67

Lagrange Multipliers Method for Maximizing or Minimizing a Function Subject to Constraints


Maple has the command "LagrangeMultipliers" to perform the Lagrange Multipliers Method. Example: Apply the Lagrange multiplier method to maximize the function f( x, y, z ) = x y z x y z subject to the constraint + + = 1. 2 3 6 Solution: We direct Maple to do the computations for us: > restart: with(Student[MultivariateCalculus]); > f:=(x,y,z)->x*y*z; g:=(x,y,z)-> x/2+y/3+z/6-1; Now in the following please observe the syntax. Observe how the constraint function g is enclosed by brackets. > LagrangeMultipliers(f(x,y,z),[g(x,y,z)],[x,y,z]); So, in this case the maximum occurs only once while the minimum occurs three times. > maximum:=f(2/3,1,2); Also, without defining functions, you may type and enter the expressions directly: > LagrangeMultipliers(x*y*z,[x/2+y/3+z/6-1],[x,y,z]); > maximum:=eval(x*y*z,{x=2/3,y=1,z=2}); Note: In the example above we started by loading into Maple's memory the package MultivariateCalculus. This is because the command "LagrangeMultipliers" is included in it.

68

Double and Triple Integrals


These can be computed by reapplying the command int. For example, to compute the double
integral
a b d

f( x, y ) dy dx, we would use the

Syntax:
int(int(f(x,y),y = c .. d),x = a .. b)

Notice the order of variables (in - out). Similarly for triple integrals, where we repeat the commands int three times.
integral
1 2

Example: To compute the

y sin( x y ) dy dx, we would type:

> int(int(y*sin(x*y),y = 0 .. Pi),x = 1 .. 2);


integral
0 z 2 1 z

Example: To compute the

yx dy dx dz, we would type:

> int(int(int(y*x,y = 1 .. z),x = z .. 1),z=0..2);

Example: Change the Cartesian

integral

4x

2 2 ( x y )

dy dx into an equivalent polar

integral and evaluate the polar integral. > answer:=int(int(exp(-r^2)*r,r=0..2),theta=0..Pi/2);

69

Vector Fields
Defining a vector field is much like defining a space curve function, but rather than using a single independent real-variable, we use two or more independent real-variables. That is to say, a vector field is a vector-valued function of two or more real-variables. Type and Enter: > restart:with(VectorCalculus): In the following examples, please observe that the command "VectorField" expects its 1st argument to be a vector, and expects that the dimensionality of the vector field and the coordinate system are equal. Example 1: > G:=VectorField( <x^2*y,4*x*y^3>, 'cartesian'[x,y]); The result is displayed in basis format, that is, as a sum of scalar multiples of basis vectors. Basis vectors are displayed by using the letter "e" subscripted by a coordinate name. If the Vector being displayed is actually a Vector Field, the basis vectors display with an overbar. The overbar is to visually distinguish a Vector Field from an ordinary Vector.

To evaluate the vector field above at a point, for example (1,1), here are two methods: > eval(G,{x=1,y=1}); evalVF(G,<1,1>);

Example 2: The following is a 3-D vector field: > F:= VectorField(<z*sin(x), y, exp(x*z^4)>, 'cartesian'[x,y,z]); > eval(F, {x=0,y=1,z=0}); # This is how to evaluate the vector field at the point (0,1,0). > evalVF(F,<0,1,0>); # This another way to evaluate the vector field at the point (0,1,0).

70

To compute the curl and divergence of a 3-dimensional vector field in the Cartesian
coordinate system, Maple uses the Syntax: Curl(F) and the Syntax: Divergence(F) where F is a three-dimensional function of the three variables v. The command Curl and Divergence are in the VectorCalculus package. Example: Find div(curl F) if F is the vector field: F( x, y, z ) = x y2 z, 3 x z, y z . Solution: Type and Enter the following: > restart: with(VectorCalculus): > SetCoordinates( 'cartesian'[x,y,z] ); coordinate attribute on the Vector Field. > F:=VectorField(<x*y^2*z, -3*x*z, y*z>); > c:=Curl(F); > answer:=Divergence(c); You may achieve the answer at once by typing: > answer:=Divergence(Curl(VectorField(<x*y^2*z, -3*x*z, y*z>)));

# This command sets the

To plot a two-dimensional vector field, Maple uses the


Syntax: fieldplot(f,x=a..b,y=c..d) where f is a List or a Vector or a VectorField of two expression in x and y. The arguments x=a..b and y=c..d specify the horizontal and vertical ranges of the field. In Maple, each side of the rectangular domain is subdivided, by default, into 20 equal pieces, and at each of the 20 x 20=400 points of the resulting grid the center of a vector, with value of the vector field at that point, is placed. The lengths of the vectors are selected so that even the longest vectors will not overlap one another. For more information, type and enter ?fieldplot at the Maple prompter > .

71

To plot a three-dimensional vector field, Maple uses the


Syntax: fieldplot3d(f,x=a..b,y=c..d,z=e..f) where f is a List or a Vector or a VectorField of three expressions in x, y and z. The arguments x=a..b, y=c..d , z=e..f , specify the horizontal and vertical ranges of the field. If you decided to use a VectorField input, then you need to load the package "VectorCalculus". Each side of the rectangular-box domain is subdivided, by default, into 8 equal pieces. At each of the 8 x 8 x 8=512 points of the resulting grid the center of the value of the vector field at that point is placed. For more information, type and enter ?fieldplot3d at the Maple prompter >. The command fieldplot and fieldplot3d are in the plots package. Example: Type and Enter the following: > restart: with(plots): > G:=[x^2+y,4*x*y^3]; # A 2-D list. > F:=[z^2*sin(x),y,0]; # A 3-D list. > fieldplot(G,x=0..1,y=-1..1,color=blue); > fieldplot3d(F,x=-1..1,y=-1..1,z=0..1,axes=normal,color=gold);

72

Exercises on Multi-variable calculus


When entering expressions, be sure to include * between variables to denote multiplication. 1) Plot the vector-valued function s( t ) = cos( t ) + t, sin( t ), t from t = 0 to t = 4 . 2) Let F and G be the following two vector fields: F( x, y, z ) = x i + 7 z j + 3 y z4 k , G( x, y, z ) = 5 i 3 y j + ( x + z ) k .
2 2

Find curl(F X G). 3) f( x, y ) = x2 e


(x + y)

. Find the gradient of f at (1,4). f( x, y ) = ( x2 + 3 y2 ) e


2 2 (1 x + y )

4) Generate a contour plot of [-2,2].

on the rectangle [-2,2] X

5) f( x, y ) = x2 y3 . If v = 4 i + 3 j , then find the directional derivative in the direction of the unit vector u which points in the same direction as the vector v. 6) Find an equation of the tangent plane to the graph z = x2 + 2 y2 at the point (1,1,3). Plot the function and its tangent plane. , and z = r2 s sin( t ) , find the value of the partial derivative of w with respect to s when r = 2, s = 1 and t = . 2 8) Plot the space curve r( t ) = cos( t ), 1 sin( t ) 2 , 0 with t from 0 to 2pi. 4 3 , 2 t2 7 5

7) If w = x3 y + y4 z2 , where x = r s et , y = r s2 e

( t )

9) Where does the space curve r( t ) = 3 t2 + 5, t 2 x + 3 y + 4 z = 5.

intersect the plane

10) Change the order of integration in the integral

x3 + 1 dx dy . Try to compute both


y

integrals. Examine the intermediate steps. Explain what happened.


This is the end of the Multi-variable Calculus Section. I hope you enjoyed it!

73

The Simplex Method in Linear Programming


Maple has the simplex package to solve linear optimization problems. Here is a small problem which demonstrates using the package simplex. Minimize x + 3 y subject to: 2x + 4y >= 8 -x + 3y <= 2 y >= 0 . Solution: Load the simplex package, define the objective function, define the constraints, then issue the command minimize or maximize. Type the following and Enter: > restart: with(simplex): > obj:=x+3*y; > cons:={2*x+4*y>=8,-x+3*y<=2,y>=0}; > cornerpoint:=minimize(obj,cons); > subs(cornerpoint,obj); #this gives the minimum. The region determined by the constraints can be graphed using the command inequal, which is contained in the plots package. Type and Enter: > with(plots): > inequal({2*x+4*y>=8,-x+3*y<=2},x=0..5, y=0..5); OR, > inequal({2*x+4*y>=8,-x+3*y<=2},x=0..5, y=0..5, optionsexcluded=(color=white));

Exercise: Maximize p = (1/2)x + 3y + z + 4w subject to x + y + z + w <= 40 2x + y - z - w >= 10 w - y >= 10 x >= 0, y >= 0, z >= 0, w >= 0.

74

Exercise: Ronald's mathematics teacher has given his class three very long lists of problems with the instruction to submit no more than 100 of them (correctly solved) for credit. The problems in the first set are worth 5 points each, those in the second set are worth 4 points each, and those in the third set are worth 6 points each. Ronald knows from experience that he requires on the average 3 minutes to solve a 5-point problem, 2 minutes to solve a 4-point problem, and 4 minutes to solve a 6-point one. Because he has other subjects to worry about, he can not afford to devote more than 3.5 hours altogether to this mathematics assignment. Moreover, the first two sets of problems involve numerical calculations, and he knows that he can not stand more than 2.5 hours of work on this type of problems. Under these circumstances, how many problems in each of the three categories shall he do in order to get the maximum possible credit for his efforts?

This is just a start. In addition to the routines maximize and minimize, the simplex package provides routines to assist the user in carrying out the steps of the algorithm one at a time: setting up problems, finding a pivot element, and executing a single pivot operation. To see more, Enter: > with(simplex);

75

Elementary Statistics
Maple has a statistics package built in, called "stats", which itself contains many subpackages (macro packages); collections of commands that extend "stats" to provide functionality that is suited to a particular task or set of tasks. The subpackages available are: anova, describe, fit, random, statevalf, statplots, transform. This section contains examples of the use of Maple in elementary statistics.

Defining Data Sets


A data set is defined as a list enclosed by square brackets, []. See next.

Mean, Median, mode and Standard Deviations


To calculate the mean, median, and standard deviations, we use the describe command. Type the following and press Enter: > data1:=[25, 41, 27, 32, 43, 66, 35, 31, 15, 5, 34, 26, 32, 38, 16, 30, 38, 30, 20, 21]; > > > > > with(stats); describe[mean](data1); describe[median](data1); describe[mode](data1); describe[standarddeviation](data1);

This standard deviation is when the data set is considered as a population. For standard deviation of a sample use > describe[standarddeviation[1]](data1);

Measures of Location (Quartiles, Deciles, and Percentiles)


We still use the describe command. Type the following and press Enter: > describe[quartile[2]](data1); We may compute the three of them at once as follows:

76

> seq(describe[quartile[i]],i=1..3)(data1); Computing deciles and percentiles is done in the same way, either individually or as a sequence, as follows: Type the following and press Enter: > describe[decile[9]](data1); > describe[percentile[90]](data1); > seq(describe[percentile[30*i]],i=1..3)(data1);

Note: Are you surprised that the median does not equal Q2, and the quartiles Q1, Q3 are not as expected? Me too! (Note: In Statistics there are five ways to compute quartiles).

Frequency Histograms
To draw histograms we need to activate the subpackage statplots of the "stats" package. Using this subpackage we can draw three graphs: (histogram, boxplot, and scatterplot). We will present two methods to determine the class intervals of a histogram: by default, and by specifying the endpoints of the class intervals. Part(1): A histogram by Maple's "default" selection of class intervals, that is, letting Maple selects the class intervals: Type the following and press Enter: > restart:with(stats[statplots]): > data2:=[80, 79, 80, 70, 48, 90, 92, 74, 70, 65, 81, 91, 56, 98, 93, 81, 87, 82, 74, 80, 78, 73, 84, 68, 85, 51, 65, 95, 83, 86, 71, 90, 83, 73, 74, 43, 86, 68, 72, 92, 76, 71, 90, 72, 67, 75, 35, 80, 61, 72, 97, 91, 88, 81, 93, 70, 99, 93, 80, 59, 71, 77, 91, 63, 83, 82, 60, 67, 89, 63, 74, 60, 63, 76, 88, 70, 66, 88, 79, 75]:

> histogram(data2);

77

Part(2): A histogram by specifying the endpoints of class intervals: Suppose you want to construct a frequency histogram for the grouped data: 30.5 - 40.5 40.5 - 50.5 50.5 - 60.5 60.5 - 70.5 70.5 - 80.5 80.5 - 90.5 90.5 - 100.5 | | | | | | | 1 2 5 15 25 20 12

Then, type and Enter: > data3:=[ Weight(30.5..40.5, 1), Weight(40.5..50.5, 2), Weight(50.5..60.5,5),Weight(60.5..70.5,15), Weight(70.5..80.5,25),Weight(80.5..90.5,20), Weight(90.5..100.5, 12)]: > histogram(data3,color=cyan);

A frequency polygon for data3 can be made as follows: > datapoints:=[[35.5,1], [45.5,2], [55.5,5], [65.5,15], [75.5,25], [85.5,20], [95.5,12]]; > d1:=plot(datapoints,style=point):d2:=plot(datapoints): with(plots):display(d1,d2);

Least-Squares Regression
Here is an example: Sarah's parents are concerned that she seems short for her age. Their doctor has the following record of Sarah's height
Age( months ) Height( cm )

36 86

48 90

51 91

54 93

57 94

60 95

a) Find the equation of the least-squares regression line of height on age.

78

b) Graph the equation in (a) together with the scatterplot of the data. c) predict Sarah's height at 40 months. To solve this problem we are going to activate 3 packages: "plots", "stats", and " fit". Type the following and press Enter: > > > > restart: with(plots):with(stats):with(fit): age:=[36,48,51,54,57,60]; height:=[86,90,91,93,94,95]; eq:=leastsquare[[x,y],y=a*x+b,{a,b}]([age,height]);

Now let us form pairs (age,height) > > > > datapoints:=zip((x,y)->[x,y],age,height); d1:=plot(datapoints,style=point): d2:=plot(rhs(eq),x=36..60): display([d1,d2]);

Now to predict Sarah's height at 40 months, type and enter : > subs(x=40.,eq); A scatterplot displays the relationship between two quantitative variables. The command to get a scatter plot is mentioned above, but we repeat it here for the sake of clarity. Type and Enter: > data:=[[36,86],[48,90],[51,91],[54,93],[57,94],[60,95]]; > plot(data,style=point);

Non-Linear Regression
An equation of a given form can be produced for the data. To have an idea here are four examples: a line, a quadratic polynomial, an exponential function, and a trigonometric function. Type and Enter : > eq1:=leastsquare[[x,y],y=a*x+b,{a,b}]([age,height]);

79

> > > > >

eq2:=leastsquare[[x,y],y=a*x^2+b*x+c,{a,b,c}]([age,height]); eq3:=leastsquare[[x,y],y=a+b*exp(x),{a,b}]([age,height]); evalf(eq3); eq4:=leastsquare[[x,y],y=a+b*sin(x),{a,b}]([age,height]); evalf(eq4);

On Normal Distributions
Probability under normal distributions, and others can be computed. To compute probability, we need to activate the subpackage "statevalf" of the "stats" package. It provides numerical evaluations of statistical functions. For more information, type and enter ?statevalf; at the Maple prompter > . Here is an example using normal distribution with parameters = 126.89, = 28.9. Assume you want to compute the probability that x =< 130. Then Type and Enter: > with(stats):statevalf[cdf,normald[126.89,28.9]](130);
Note: cdf stands for cumulative density function , and icdf, coming next, stands for inverse cumulative density function .

Now to find x for which 90% of the normal distribution is to its left, we would type and enter: > statevalf[icdf,normald[126.89,28.9]](.90); > The plot for the normal curve with parameters (126.89,28.9) can be obtained using the function plot as follows: > plot(statevalf[pdf,normald[126.89,28.9]], 40..214); It is possible to generate a sample, of size 250 for example, from the normal distribution given above, and draw a histogram to display the sample. Type and Enter: > sample:=[random[normald[126.89,28.9]](250)]:

> with(stats):describe[mean](sample);describe[standarddeviation [1]](sample); > with(stats[statplots]):histogram(sample);

80

On Binomial Distributions
Here we use the discrete distribution binomiald[n,p], which has the probability density function binomial( n, x ) px ( 1 p )
(n x)

Here is an example where n=160 and p=0.2, and where we want to compute p(x=40).

> with(stats): P(40):=statevalf[pf,binomiald[160,.2]](40); Now to compute p(x < 40), we use the sum function, as follows: > sum(statevalf[pf,binomiald[160,.2]](x),x=0..39); >

This is the end of the Elementary Statistics Section. I hope you enjoyed it!

81

Some Common Problems:


This section includes a sample of the problems that students sometimes encounter.
Please always remember that: 1) Maple is case sensitive. For example: The Int command is not the same as the int command. 2) If a command is included in a package then that package should be loaded into Maple's working memory, so then the command will work. 3) The command restart: clears Maple's memory of any previous procedures, assignments or packages. Use the command restart: if you want to ensure that future operations can be performed without risk that previous definition will interfere with the processing. 4) Maple uses % as a ditto operator. It refers to the immediately preceding computed result anywhere in the worksheet!

In the following examples, try to find the answer yourself first. Suppose you want to multiply 3(4) to obtain 12. Type and Enter the following: > restart: 3(4); Question: What went wrong? Answer: Maple view the expression 3(4) as the constant function f(x)=3. Thus f(4)=3. Be sure to include * to denote multiplication, as follows: > 3*4;

Suppose you want to evaluate the expression 2x for x=3 to obtain 6. Type and Enter the function: > eval(2x,x=3); Question: What went wrong? Answer: No operation between 2 and x was specified. Use > eval(2*x,x=3);

82

Type and Enter the function: > restart: g:=x -> diff(x^2,x); > g(x); > g(1); Question: Message received: Error, (in g) ... What went wrong? Answer: Maple view your functional expression as diff(1^2, 1) in which the second argument is not a letter or name. Use > eval(g(x),x=1);

Type and Enter the following: > restart: p:=x^2*y+x*z; > eval(p,x=10); > x:=1; > eval(p,x=10); Question: The output is not correct. The expected answer is 100 y + 10 z. What went wrong? Answer: eval(p,x=10), in this case, means eval(1^2*y+1*z, 1=10). To correct the problem, return x to its normal status. Use > x:='x'; > eval(p,x=10);

Type and Enter the following: > restart: > expand([x-1]^2); Question: Maple is not able to expand this simple expression. What went wrong? Answer: Use round parentheses as follows: > expand((x-1)^2); Similar comment if you try: plot([x-1]^2);

Type and Enter the following: > restart: x:=1; > plot(sin(x),x=-3..3); Question: No graph is obtained. What went wrong? Answer: Actually you tried to graph sin(1) for 1 from -3 to 3. Maple is confused! Solution: Either use a different letter than x, for example t. Or return x back to its normal status, as follows: > x:='x'; > plot(sin(x),x=-3..3);

83

Type and Enter the following: > restart: with(LinearAlgebra): > dotproduct(<1,2>,<3,-1>); Question: Maple is not able to compute, what went wrong? Answer: Maple is case sensitive, you should type: > DotProduct(<1,2>,<3,-1>);

Type and Enter the following: > restart: > DotProduct(<1,2>,<3,-1>); Question: The output is not as expected, what went wrong? Answer: The DotProduct command is in the "LinearAlgebra" and in the "VectorCalculus" packages. First you need to load the desired package to Maple's working memory. Use for example, > with(LinearAlgebra): > DotProduct(<1,2>,<3,-1>); Type and Enter the following: > restart: plot(sin(x),x=0..10, title='The sine'); Question: Maple refuses to do the plot. What went wrong? Answer: `...` around the title should be used, not '..' Use: > plot(sin(x),x=0..10, title=`The sine`);

Type and Enter the following: > restart: implicitplot(x*y+1=x, x=0..4,y=0..4); Question: Maple refuses to do the plot. What went wrong? Answer: The implicitplot command is in the "plots" package. First you need to load the required to Maple's working memory. Use: > with(plots): > implicitplot(x*y+1=x, x=0..4,y=0..4);

84

Type and Enter the following: > restart: with(plots): implicitplot(2x*y+1=x, x=0..4,y=0..4); Question: Maple refuses to do the plot. What went wrong? Answer: No operation between 2 and x was specified. Use: > implicitplot(2*x*y+1=x, x=0..4,y=0..4);

Type and Enter the following: > restart: f:x->x^2; > diff(f(x),x); Question: The expected answer is 2x. What went wrong? Answer: It is a common mistake to type either = or : without the other. Solution: Use > f:=x->x^2; > diff(f(x),x);

Type and Enter the following: > restart: f:=x->x^2; > diff(f,x); Question: The expected answer is 2x. What went wrong? Answer: If you define a function then you must evaluate the function at the variable(s) for further calculations such as derivatives, integrals and limits. Solution: Use > diff(f(x),x);

85

Potrebbero piacerti anche