The Most Common Maple Commands

The following commands will be used repeatedly throughout the calculus labs. You should know the syntax of these commands.

Variable Assignment

Numbers, expressions and equations can be given variable names in Maple. This reduces typing and also increases accuracy. Assigning expressions to a variable in Maple is accomplished with the ":=" (colon equals) keystrokes. A variable name in Maple may be a single character or a name with more than one character. Variable names should begin with a letter. Examples include the following:

>    k:=3.76;

>    f1:=sqrt(x^2+3*x+7);

>    eq1:=x^2+7*x-3;

When the name of an assigned variable is used in another Maple command, Maple will automatically make the substitution.

Defining a Function

Maple has a special command for defining a function of a single variable, say x . (Any letter can be used for the variable.) The Maple format for defining a function makes a lot of sense if you remember that a function is a rule that begins with an input value, x , and assigns to x  an output value. The name of a function can have more than one character. Examples include the following:

>    f:=x->x^2;

>    f1:=x->x/(x+1);

Once a function has been defined in Maple, you can use standard functional notation such as f ( x ) or f (2).

Clearing all Variables

When beginning a new worksheet or a new section within a given worksheet, it is often useful to remove all variable and function assignments. This is accomplished with the restart  command.

>    restart;

You can also clear a single variable. Suppose a  has been assigned the value 3.

>    a:=3;

>    a:

If one wants to remove this assignment, the followng command works:

>    a:='a';

>    a;

Now a  is a free variable with no assigned value.

Solving an Equation

Maple has two very different methods of solving equations. One is algebraic and the other is numerical. To solve an equation algebraically, one uses the solve  command. To solve an equation numerically, one uses the f solve  command. Both commands require an equation and the variable or variables being solved for. Some examples of the solve  and fsolve  commands are shown below:

>    solve(x^2=2,x);

>    fsolve(x^2=2,x);

Often when using the fsolve  command, one specifies an interval of x -values over which Maple should search for a solution.

>    fsolve(x^2=2,x=-2..-1);

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

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

>    eq1:=x^2+7*x-3;
solve(eq1,x);

If the first argument in either a solve  or fsolve  command is merely an expression without an equals  sign, Maple automatically interprets it as an equation in which the expression is being set equal to 0.

>    solve(x^2-3,x);

Plotting Functions

The plot command in Maple is very useful. The basic plot command has three components - the expression being plotted, the x -range and the y -range:

>    plot(x^2,x=-5..5,y=-20..20);

The above command instructs Maple to plot the function f(x) = x^2  within the viewing window [-5,5] by [-20,20]. If the y -range is omitted, Maple will automatically set the y -range to the numerical range of the function over the x -range. This is often a problem when the y- range is large.

>    plot(1/(x-1),x=-5..5);

>    plot(1/(x-1),x=-5..5,y=-20..20);

More than one function cab be plotted in the same window by listing the functions in either square or curly brackets separated by commas.

>    plot([(x-1)^2,4-x^2],x=-5..5,y=-20..20);

Variable names of expressions as well as functional notation can be used within a plot command.

>    f:=x->4-x^2;g:=x->(x-1)^2;
plot({f(x),g(x)},x=-5..5,y=-20..20);

There are may options that can be added to a plot command that control various attributes of the plot such as color, thickness, axes.  You can learn about using these options by looking up plot  in the Maple help window. The easiest way is to type a keyword such as plot  preceded by a question mark on a Maple command line.

>    ?plot;

>    ?plot,color;

The Substitute Command

One often has a formula involving one or more variables, and one wants to substitute values for some or all of these variables. This is accomplished with the subs  command. Suppose we want to evaluate the expression x^2+2*x-3  when x  = 4. We can do this as follows

>    subs(x=4,x^2+2*x-3);

If more than one substitution is being made, one simply lists the substitutions within curly braces "{}" separated by commas.

>    subs({a=2,b=5,c=Pi},a*x^2+b*x+c);

Differentiation of Functions

The following Maple command will determine the derivative of the expression sqrt(x^2+1)

>    diff(sqrt(x^2+1),x);

If f ( x ) is a function that has been defined in Maple, "f(x)" can be used in place of the explicit formula

>    f:=x->sqrt(x^2+1);
diff(f(x),x);

Higher order derivatives can be computed by repeating the variable x   n  times where n  is the order of the derivative being calculated. For example the following command computes the third derivative of x^7-5*x^5+x^2

>    diff(x^7-5*x^5+x^2,x,x,x);

Instead of typing all the x 's in the above command, one can type " x $ n " where n  is the order of the derivative being calculated.

>    diff(x^7-5*x^5+x^2,x$3);

If one is using the diff  command for the derivative and one wants to evaluate the derivative at a particular value of x , one must use the subs  command

>    subs(x=3,diff(x^7-5*x^5+x^2,x$3));

There is a second command for calculating the derivative of a function. The function f  must first be defined as a function in Maple. One should think of f  as the "name" of the function, which is different from the formula for the function. The derivative of f  is the function having the name D(f). One then uses this name for a function just like any other name.

>    f:=x->x^7-5*x^5+x^2;
D(f)(x);

If one wants to evaluate the derivative of f  at x  = 3, one simply types D(f)(3) assuming the function f  has been defined in Maple.

>    D(f)(3);

The D  command for the derivative allows one to treat algebraic combinations of functions. For example if f(x) = x^2  and g(x) = sin(x)  one can differentiate the product with the command D(f*g)(x).

>    f:=x->x^2;g:=x->sin(x);
D(f*g)(x);

Note that the composition operator for functions is "@":

>    D(g@f)(x);

Setting Digits

The default number of digits used by Maple during calculations and displayed in floating-point numbers is 10.

>    evalf(sqrt(Pi));

Sometimes one wants to use a greater number of digits. This can be done with the Digits:=n command where n  is an integer.

>    Digits:=20;

>    evalf(sqrt(Pi));