> restart;

Summary of Calculus I Syntax in Maple

In this worksheet we summarize the syntax that we have used in the previous worksheets and explain a few finer points. In MTH 142 next semester we shall continue working with Maple and use the syntax that we have learned this semester.

Functions and Expressions

A function, for example [Maple Math] , is defined in Maple as follows

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

[Maple Math]

A function, as far as Maple is concerned, is a rule which to each input, say x, prescribes the output given by the formula for the function. You can apply a function to anything in place of x and obtain the corresponding value

> f(s); f(10);

[Maple Math]

[Maple Math]

If you define

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

[Maple Math]

you have defined not a function but a formula or an expression m in terms of x. Maple can process expressions, as well as functions, but, as you see below, the appropriate syntax may look a little different. For example "m(s)" is meaningless to Maple. If you want to substitute s for x in the formula m you have to use the " subs " command

> subs(x=s,m);

[Maple Math]

There are basically three commands to evalute expressions. They are " eval ", " evalf " and " value ". The command " eval " will attempt to give you an exact value for your expression, while " evalf " will evaluate an expression numerically and return a decimal point approximation. The command " value " is most often used in cojuction with inert commands, like " Int ", " Limit " which do not evalute the input but only print it out. You will see in subsequent sections how " value " works. The best way to learn the differences between the evaluation commands is by practice and example. Click on the lines below and see if you can predict an output.

> Pi;

> eval(Pi);

> evalf(Pi);

> eval(m,x=3);

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

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

The symbol " % " in Release 5 of Maple denotes the last executed output. (It is " in earlier releases.) In order to avoid confusion, the symbol " % " should always be used on the same command line as the command that " % " refers to.

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

Limits

To find the limit of a function at a point, use the syntax

> limit(f(x),x=0);

[Maple Math]

We have found the limit at x=0 of the function f(x) defined above. If you hadn't defined f(x) you could simply type

> limit(exp(2*x)+x*sin(x),x=0);

[Maple Math]

You could also find the limit of the expresion m at x=0 by typing

> limit(m,x=0);

[Maple Math]

You cannot, however, use the syntax "limit(f,x=0);" You have to type "f(x)". In most commands involving functions you have to enter "f(x)" and not just the name of the function.

If you want Maple to print out a given limit, use the inert version of the command " limit ", that is, " Limit ". Inert commands like " Limit ", " Int " print out an input without evaluating it. They are useful if you want to check if you entered a correct expression. If you want to evaluate your limit or integral right away, follow an inert command by the " value " command. " value " command simply changes the upper case inert commands to lower case commands and evaluates. For example

> Limit(f(x),x=0); value(%);

[Maple Math]

[Maple Math]

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

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

[Maple Math]

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

[Maple Math]

You can use L'Hospital rules to see that Maple gave us correct answers. If a given limit does not exist Maple will tell us so

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

[Maple Math]

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

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

[Maple Math]

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

[Maple Math]

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

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

[Maple Math]

[Maple Math]

Derivatives

To find the derivative of a given function, we can type

> diff(exp(2*x)+x*sin(x),x);

[Maple Math]

Since we have defined the function [Maple Math] above, we can also use the syntax

> diff(f(x),x);

[Maple Math]

The syntax "diff(f,x);", however, does not work. You have to type "f(x)". For expressions the syntax is a little different. To find the derivative of the expression m defined above type

> diff(m,x);

[Maple Math]

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

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

[Maple Math]

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

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

[Maple Math]

Another way of finding derivatives is by using the " D " operator.

> D(f);

[Maple Math]

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

> D(D(f));

[Maple Math]

Note: There is an important difference between the outputs of the " D(f) " and the " diff " commands. The command " D(f) ;" returns the derivative of f as a function of x. The command " diff(f(x),x) ;" gives the derivative as an expression in terms of x. Both forms have advantages and disadvantages. For example, if you want to simplify the derivative, the command " simplify(diff(f(x),x)) ;" works, in general, better than " simplify(D(f)); ". For other purposes, it may be more convenient to have the derivative D(f) as a function. There is a way of turning an expression into a function, using the so called " unapply " command. We shall look at this next semester.

Integrals

Maple can find indefinte integrals, as well as definite integrals. For example:

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

[Maple Math]

> int(f(x),x);

[Maple Math]

In the latter example we found an antiderivative of the function f(x) defined in the first section. If an antiderivative cannot be found in a closed form, Maple will simply print out the input.

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

[Maple Math]

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

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

[Maple Math]

[Maple Math]

Similar syntax applies to definite integrals.

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

[Maple Math]

[Maple Math]

We have just found the exact and the decimal value of definite integral of the function f(x) from 0 to 2.

> int(cos(3*x),x=-1..3); evalf(%);

[Maple Math]

[Maple Math]

If you want a given integral printed out, as well as evaluated, type

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

[Maple Math]

[Maple Math]

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

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

[Maple Math]

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

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

[Maple Math]

Solving Equations

As you know, solving equations is not an easy matter. In many cases there are no reliable methods of finding exact values of solutions and numerical methods have to be used. Maple knows all the standard techniques and algorithms, as well as numerical methods. There are essentially two commands for solving equations " solve " and " fsolve ". Command " solve " attempts to find exact values of as many solutions as possible. It works very well with polynomial equations up to the order four and equations which can be reduced to such form. For example:

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

[Maple Math]

Command " solve " can be applied to equations containing parameters. For example

> solve(a*x^2+b*x+c=0,x);

[Maple Math]

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

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

[Maple Math]

Maple's response indicates that it does not know how to solve this equation exactly. It is not surprising. As you may know there are no formulas for finding roots of polynamials of degree five or higher. In that case, we can ask Maple to solve a given equation numerically. The command "allvalues" applied to an output "RootOf" will produce approximate solutions, real and complex:

> allvalues(%);

[Maple Math]
[Maple Math]

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

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

[Maple Math]

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

[Maple Math]

A solution that " fsolve " returns may not be located in a range of interest to you. The situation can be remedied by adding under the " fsolve " command a range in which you want Maple to find a solution. The latter capabilty of Maple equation solver combined with Maple's plotting facility provide a very powerful tool of finding solutions relevant to your problem. Suppose that you are studying a process modeled by the function g(t) and the range of interest for t is [0,4]. You plot g(t) in that range:

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

[Maple Plot]

You see from the plot approximately where the zeros of g(t) are loacated. You ask Maple to find them using " fsolve " with the range for t specified. Namely:

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

[Maple Math]

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

[Maple Math]

> fsolve(g(t)=0,t,3..4);

[Maple Math]

Plotting

We have made and we will continue to make extensive use of Maple's plotting facility. The basic command " plot " as used in the previous section can be supplemented by many options, and several expressions can be plotted in one coordinate system. For example

> plot([t*sin(t),t*sin(2*t)],t=0..10,color=[blue,magenta],scaling=constrained,labels=["time","position"]);

[Maple Plot]

>

If you are assigning attributes, for example, colors to several expressions, remember to enter expressions as well as their desired attributes as a list and not as a set. A list is always entered between square brackets [...] , and a set is entered between curly brackets {...} .

Packages

When you start Maple, it loads into the computer's memory only the so called kernel, which contains the basic commands and functions. More advanced commands are contained in packages and libraries which can be loaded with appropriate commands. So far we have used two such packages: " plots " and " student ". To load a package, say " plots ", you use the command " with(plots): ".If you end your command with a colon, the content of the package will not be printed. If you end it with a semicolon " with(plots); " Maple will load the package, as well as print its content.

> with(plots);

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

Among the commands which the package contains we see " pointplot " and " display ", which we used before. We also see the command " implicitplot " which allows plotting curves given by xy-equations. For example:

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

[Maple Plot]

>

The package " with(plots) " contains many important plotting commands and we shall use it extensively in the future.

Problem 1. Find the following limits:

(a) [Maple Math] (b) [Maple Math] (c) [Maple Math] .

Problem 2. Let [Maple Math] . Find the twenty-fifth derivative of f(x).

Problem 3. Find the following indefinite integrals:

(a) [Maple Math] (b) [Maple Math] .

Problem 4. Plot the following curves. For each of them adjust properly the range for x and y so you can have a good idea about the shape of the curve.

(a) [Maple Math] (b) [Maple Math]

MTH 141 Maple Worksheets written by B. Kaskosz and L. Pakula, Copyright 1998.

Last modified August 1999.

>