Introduction

Introduction to Maple

Examples:

At the beginging of every session, it is a good idea to use the restart command. The restart command will cause the Maple kernel to clear its internal memory so that it acts as if you had just started Maple.

> restart;

adding 3, 5 and 5

> 3 + 4 + 5;

12

Expand the expression x*(x+1)*(x-1) and name the expanded results e1

> e1 := expand( x*(x+1)*(x-1) );

e1 := x^3-x

Factor the previous result

> factor( % );

x*(x+1)*(x-1)

Compute the floating value of sqrt(2)

> evalf( sqrt(2) );

1.414213562

Solve the equation x^3-x = 0 (previously called e1) for x

> solve(e1=0, x);

0, 1, -1

Differentiate cos(x)+x*ln(x)-3*x^2 with respect to x

> diff(cos(x)+ x*ln(x)-3*x^2,x);

-sin(x)+ln(x)+1-6*x

Integrate x*exp(x) with respect to x

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

x*exp(x)-exp(x)

To obtain help, use ? followed by a command name

> ?plot;

See Also: help , maple , index , index[function]

assign

Function: assign - perform assignments

Calling Sequence:
assign(a, b)
assign(a = b)
assign(t)

Parameters:
a - a name
b - any expression
t - a list or set of equations

Description:

Examples:

One use of this function is to apply it to a set of equations returned by the solve function when it is desired to assign the solution values to the variables.

Solve the linear system for x and y and place the results in a set called s

> s := solve( {x+y=1, 2*x+y=3}, {x,y} );

s := {x = 2, y = -1}

Now if we type x; or y; Maple does not return the values of x or y. The reason is that the values are not assigned to x and y

> x;

x

> y;

y

With the assign command the values are assgind to x and y. So x will have the value 2 and y the value -1

> assign(s);

> x;

2

> y;

-1

To unassign the values use the command unassign. Note that the variable must be placed between quotation marks.

> unassign('x','y');

Now, x and y will no longer have the values of 2 and -1

> x,y;

x, y

See Also: unassign

diff and Diff

Function: diff or Diff - Differentiation or Partial Differentiation

Calling Sequence:
diff(expr, x1, x2, ..., xn)
Diff(expr, x1, x2, ..., xn)
diff(expr, [x1, x2, ..., xn])
Diff(expr, [x1, x2, ..., xn])

Parameters:
expr - an algebraic expression
x1, x2, ..., xn - variables with respect to which differentiation is performed

Examples:

> diff(sin(x),x);

cos(x)

> diff(sin(x),y);

0

The sequence operator $ is useful for forming higher-order derivatives. diff(f(x),x$4), for example, is equivalent to diff(f(x),x,x,x,x)

> diff(sin(x),x,x,x);

-cos(x)

> diff(sin(x),x$3);

-cos(x)

and diff(g(x,y),x$2,y$3) is equivalent to diff(g(x,y),x,x,y,y,y)

> diff(g(x,y),x,x,y,y,y);

diff(g(x,y),`$`(x,2),`$`(y,3))

> diff(g(x,y),x$2,y$3);

diff(g(x,y),`$`(x,2),`$`(y,3))

>

> diff(y^2*x^4,x,x,y,y);

24*x^2

> diff(y^2*x^4,x$2,y$2);

24*x^2

> diff(tan(x),x);

1+tan(x)^2

The capitalized function name Diff is the inert diff function, which simply returns unevaluated.

> Diff(tan(x),x);

Diff(tan(x),x)

> Diff(tan(x),x) = diff(tan(x),x);

Diff(tan(x),x) = 1+tan(x)^2

Since f(x) and f(x,y) are not defined, no evaluation is returned

> diff(f(x),x);
diff(f(x,y),x,y);

diff(f(x),x)

diff(f(x,y),x,y)

The diff command assumes that partial derivatives commute, that is,

diff(f(x,y),x,y) = diff(f(x,y),y,x)

> diff(f(x,y),x,y) - diff(f(x,y),y,x);

0

These two forms are equivalent:

Variables with respect to which differentiation is performed are given as a list (not inclosed in brackets [ ] )

> diff(g(x,y,z),x,z,z);

diff(g(x,y,z),x,`$`(z,2))

Or, they may be given as a list

> diff(g(x,y,z),[x,z,z]);

diff(g(x,y,z),x,`$`(z,2))

dsolve

dsolve - Solve ordinary differential equations (ODEs)

Calling Sequences:

dsolve(ODE)

dsolve(ODE, y(x), extra_args)

dsolve({ODE, ICs}, y(x), extra_args)

dsolve({sysODE, ICs}, {funcs}, extra_args)

Parameters:

ODE - an ordinary differential equation

y(x) - any indeterminate function of one variable

ICs - initial conditions

{sysODE} - a set with a system of ODEs

{funcs} - a set with indeterminate functions

extra_args - optional, depends on the type of problem being solved (see below)

* Herein {x, y(x)} represent any pair of independent and dependent variables.

Description:

> infolevel[dsolve]:= 0;

infolevel[dsolve] := 0

INPUT AND OUTPUT

THE OPTIONAL ARGUMENTS

.

Examples:

See Also:

odeadvisor , dsolve,algorithms , dsolve,education , dsolve,ICs , dsolve,inttrans , dsolve,formal_series , dsolve,Lie , dsolve,linear , dsolve,numeric ; dsolve,piecewise , dsolve,series , dsolve,system , odeadvisor,types , and the Maple packages for differential equations DEtools , PDEtools

>

>

Examples:

> unassign('y','x');

> de:=diff(y(x),x$2)-y(x)=sin(x)*x,y(x);

de := diff(y(x),`$`(x,2))-y(x) = sin(x)*x, y(x)

> dsolve(diff(y(x),x$2)-y(x)=sin(x)*x,y(x));

y(x) = -1/2*cos(x)-1/2*sin(x)*x+_C1*exp(x)+_C2*exp(...

Solve an initial value problem

> dsolve({diff(v(t),t)+2*t=0, v(1)=5}, v(t));

v(t) = -t^2+6

> dsolve(diff(y(x),x) - alpha*y(x) = 0, y(x), explicit=true);

y(x) = _C1*exp(alpha*x)

> de1 := diff(y(t),t$2) + 5*diff(y(t),t) + 6*y(t) = 0;

de1 := diff(y(t),`$`(t,2))+5*diff(y(t),t)+6*y(t) = ...

> dsolve({de1, y(0)=0, D(y)(0)=1}, y(t),method=laplace);

y(t) = exp(-2*t)-exp(-3*t)

> dsolve(diff(y(x),x$2)+2*diff(y(x),x)+6*y(x)=x,y(x),output=basis);

[[exp(-x)*sin(sqrt(5)*x), exp(-x)*cos(sqrt(5)*x)], ...

> sys := diff(y(x),x)=z(x)-y(x)-x, diff(z(x),x)=y(x);
fcns := {y(x), z(x)};

sys := diff(y(x),x) = z(x)-y(x)-x, diff(z(x),x) = y...

fcns := {y(x), z(x)}

> F := dsolve({sys,y(0)=0,z(0)=1}, fcns);

F := {y(x) = 1-1/2*exp(-1/2*(sqrt(5)+1)*x)-1/10*sqr...
F := {y(x) = 1-1/2*exp(-1/2*(sqrt(5)+1)*x)-1/10*sqr...

First order ODEs (see ? odeadvisor ).

> ode1 := diff(y(x),x)-y(x)^2+y(x)*sin(x)-cos(x);

ode1 := diff(y(x),x)-y(x)^2+y(x)*sin(x)-cos(x)

> ans1 := dsolve(ode1);

ans1 := y(x) = sin(x)-exp(-cos(x))/(_C1+Int(exp(-co...

> with(DEtools): odeadvisor(ode1);

[_Riccati]

ODE of high degree in dy/dx.

A linear ODE

> ode_L := sin(x)*diff(y(x),x)-cos(x)*y(x)=0;

ode_L := sin(x)*diff(y(x),x)-cos(x)*y(x) = 0

One can indicate to dsolve to use a specific sequence of 'methods' to tackle the ODE. In this example the method for 'linear' ODEs is indicated; in addition the optional argument 'useInt' makes dsolve not evaluate the integral appearing in the answer

> dsolve(ode_L, useInt);

y(x) = _C1*exp(Int(cos(x)/sin(x),x))

To see the answer before evaluating integrals is useful to understand how the answer was obtained; integrals can be evaluated afterwards using value

> value(%);

y(x) = _C1*sin(x)

Or you can use the dsolve command without specifying the useInt option

> dsolve(ode_L);

y(x) = _C1*sin(x)

This particular linear ODE is also separable

> dsolve(ode_L, [separable], useInt);

Int(cos(x)/sin(x),x)-Int(1/_a,_a = `` .. y(x))+_C1 ...

> value(%);

ln(sin(x))-ln(y(x))+_C1 = 0

As a general alternative, one can look for an integrating factor (see ? DEtools,intfactor )

> mu := intfactor(ode_L);

mu := 1/(sin(x)^2)

Integrating factors turn ODEs exact; to indicate to dsolve to use the scheme for exact ODEs:

> dsolve( mu*ode_L, [exact], useInt);

y(x) = -_C1/(1/2*tan(1/2*x)+1/2/tan(1/2*x))

> dsolve( mu*ode_L);

y(x) = _C1*sin(x)

> value(%%);

y(x) = -_C1/(1/2*tan(1/2*x)+1/2/tan(1/2*x))

A second order linear homogeneous ODE

> ode4 := diff(y(x), x$2) - x*diff(y(x),x)-
y(x)=0;

ode4 := diff(y(x),`$`(x,2))-x*diff(y(x),x)-y(x) = 0...

> dsolve(ode4);

y(x) = erf(1/2*sqrt(2)*x)*exp(1/2*x^2)*_C1+_C2*exp(...

A non-linear second order example

> ode5 := diff(y(x),x,x) =
-1/y(x)^2;

ode5 := diff(y(x),`$`(x,2)) = -1/(y(x)^2)

> ans5 := dsolve(ode5);

ans5 := -sqrt(_C1*y(x)^2+2*y(x))/_C1+ln((1+_C1*y(x)...
ans5 := -sqrt(_C1*y(x)^2+2*y(x))/_C1+ln((1+_C1*y(x)...

Error, invalid subscript selector

A non-linear high order example solved using symmetry methods:

> ode6 := diff(diff(y(x),x),x)*diff(y(x),x)*y(x)*x^6-
2*diff(y(x),x)^3*x^6+2*diff(y(x),x)^2*y(x)*x^5+y(x)^5;

ode6 := diff(y(x),`$`(x,2))*diff(y(x),x)*y(x)*x^6-2...

> dsolve(ode6);

y(x) = 0, y(x) = 3*x^3/((2*x-2*_C1*x^2)^(3/2)+3*_C2...

>

See Also: diff , D , convert[diff] , convert[D] , DESol , rsolve , series , dsolve[numeric] , dsolve[rkf45] , dsolve[dverk78] , dsolve[classical] , dsolve[gear] , dsolve[mgear] , dsolve[lsode] , DEtools , plots[odeplot] , inttrans , pdesolve

expand

Function: expand - Expand an Expression

Description:

Examples:

> expand((x+1)*(x+2));

x^2+3*x+2

> expand((x+1)*(x+3)/(x+2));

x^2/(x+2)+4*x/(x+2)+3/(x+2)

> expand(sin(x+y));

sin(x)*cos(y)+cos(x)*sin(y)

> expand(cos(2*x));

2*cos(x)^2-1

> expand(exp(a+ln(b)));

exp(a)*b

> expand(ln(x/(1-x)^2));

ln(x/((1-x)^2))

> expand((x+1)*(y+z), x+1);

(x+1)*y+(x+1)*z

>

See Also: expandoff , expandon , collect , combine , factor , frontend , normal , sort , Expand

function

Help For: Functional operators

Description:

Examples:

Define the function f(x) = 3 x + 5

> f := x -> 3*x + 5;

f := proc (x) options operator, arrow; 3*x+5 end pr...

> f(2);

11

Define a multivariate function g(x,y) = sin(x) cos(x) + x y

> g := (x,y) -> sin(x)*cos(y) + x*y;

g := proc (x, y) options operator, arrow; sin(x)*co...

> g(Pi/2, Pi);

-1+1/2*Pi^2

Define a vector function

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

h := proc (x) options operator, arrow; 2*x, x^3 end...

> h(3);

6, 27

> h(x);

2*x, x^3

> k:= x -> linalg[matrix](2,1,[2*x,x^3]);

k := proc (x) options operator, arrow; linalg[matri...

> k(3);

matrix([[6], [27]])

See Also: unapply , @ , @@ , D , operators[D] , operators[example]

int

Function: int or Int - Definite and Indefinite Integration

Calling Sequences:
int(expr, x) Int(expr, x)
int(expr, x=a..b, ...) Int(expr, x=a..b, ...)

Parameters:
f - an algebraic expression or a procedure, the integrand
expr
- a variable with respect to integration is performed
a, b - the limits of integration for definite integrals
... - options

Description:

Examples:

> int( sin(x), x );

-cos(x)

> Int( sin(x), x );

Int(sin(x),x)

> int( sin(x), x=0..Pi );

2

> Int( sin(x), x=0..Pi );

Int(sin(x),x = 0 .. Pi)

> int( x/(x^3-1), x );

1/3*ln(x-1)-1/6*ln(x^2+x+1)+1/3*sqrt(3)*arctan(1/3*...

> int( exp(-x^2), x );

1/2*sqrt(Pi)*erf(x)

Maple is unable to evaluate the following integral

> int( exp(-x^2)*ln(x), x );

int(exp(-x^2)*ln(x),x)

See Also: diff , evalf , series , limit , iscont , student[Int] , fourier , laplace , mellin , int[numerical]

map

Function: map - apply a procedure to each operand of an expression

Function: map2 - apply a procedure with a specified first argument to each operand of an expression

Calling Sequence:
map(fcn, expr, arg2, ..., argn)
map2(fcn, arg1, expr, arg3, ..., argn)

Parameters:
fcn - a procedure or a name
expr - any expression
argi - (optional) further arguments to fcn

Description:

Examples:

> unassign('f','y');

> map(f, x + y*z);

f(x)+f(y*z)

> map(f, y*z);

f(y)*f(z)

> map(f, {a,b,c});

{f(a), f(c), f(b)}

> map(x -> x^2, x + y);

x^2+y^2

> map(proc(x,y) x^2+y end, [1,2,3,4], 2);

[3, 6, 11, 18]

> map2(f, g, {a,b,c});

{f(g,b), f(g,a), f(g,c)}

See Also: op , proc , operators[functional] , select

matrix

Help For: matrices

Description:

Examples:

> linalg[matrix](2,3,[x,y,z,a,b,c]);

matrix([[x, y, z], [a, b, c]])

> array(1..2,1..2,[[1,2],[3,4]]);

matrix([[1, 2], [3, 4]])

> type(%,matrix);

true

> array(0..1,0..1,[[a,b],[c,d]]):
type(%,matrix);

false

> A:=linalg[matrix](2,2,[sin(x), x^2+x+3, exp(x), cos(x^2)]);

A := matrix([[sin(x), x^2+x+3], [exp(x), cos(x^2)]]...

> map(diff, A, x);

matrix([[cos(x), 2*x+1], [exp(x), -2*sin(x^2)*x]])

See Also: linalg[matrix] , linalg , array , vector , evalm , print , map , type

op

Function: op - extract operands from an expression

Function: nops - the number of operands of an expression

Calling Sequence:
op(i,expr) op(i..j,expr) op(expr) op(list,expr)
nops(expr)

Parameters:
i,j - integers marking positions of operands
expr - any expression
list - a list of integers marking positions of operands at increasing nesting levels of an expression

Description:

Examples:

Define a list of three elements (operands)

> u := [1,4,9];

u := [1, 4, 9]

> nops(u);

3

> op(2,u);

4

> op(2..3,u);

4, 9

> op(u);

1, 4, 9

> op(0,u);

list

> [op(u),16];

[1, 4, 9, 16]

> v := f(x,y,z);

v := f(x,y,z)

> nops(v);

3

> op(0,v);

f

> op(2,v);

y

> op(4,v);

Error, improper op or subscript selector

> op(v);

x, y, z

> w := f(g(a,b),h(c,d));

w := f(sin(a)*cos(b)+b*a,2*c,c^3)

Retrun the 2nd operand of the first operand of w

> op(1,op(2,w));

2

The same as above but clearer

> op([2,1],w);

2

See Also: subsop , applyop , map , type

restart

start over, (almost) as if Maple were restarted

Calling Sequences:
restart;

Description: :

Examples:

> a := 2;

a := 2

Load the differential equation tools package

> with(DEtools):

Define a 2nd order DE in stanadard form de:=diff(y(x),x$2)+p(x)*diff(y(x),x)+q(x)*y(x)=0;

de := diff(y(x),`$`(x,2))+p(x)*diff(y(x),x)+q(x)*y(...

Use the reduceOrder command supplied with the DEtools package (given a solution y[1](x), find another solution y[2](x)

> y[2](x):=reduceOrder(de,y(x),y[1](x));

y[2](x) := y[1](x)*Int(exp(-Int(p(x),x))/(y[1](x)^2...

Restart Maple

> restart;

The value of a is no longer known

> a;

a

The command reduceOrder is no longer knows

> y[2](x):=reduceOrder(de,y(x),y[1](x));

y[2](x) := reduceOrder(de,y(x),y[1](x))

See Also: unassign

sets and lists

Help For: Sets and lists

Calling Sequence:
{es}
[es]

Parameters:
es - an expression sequence

Description:

Examples:

> {x,y,y};

{x, y}

> {y,x,y};

{x, y}

> [x,y,y];

[x, y, y]

> [y,x,y];

[y, x, y]

> L := [seq(x[i],i=1..4)];

L := [x[1], x[2], x[3], x[4]]

> L[2];

x[2]

> L := [op(L),x[5]];

L := [x[1], x[2], x[3], x[4], x[5]]

> L[-3..-2];

[x[3], x[4]]

> L := subsop(2=NULL,L);

L := [x[1], x[3], x[4], x[5]]

See Also: selection , op , nops , union , intersect , minus , member , convert , seq

simplify

Function: simplify - Apply Simplification Rules to an Expression

Calling Sequence:
simplify(expr)
simplify(expr, n1, n2, ...)
simplify(expr, assume=prop)

Parameters:
expr - any expression
n1, n2,... - (optional) names or sets or lists
prop - any property (optional)

Description:

Examples:

> expr1:=4^(1/2)+3;

expr1 := sqrt(4)+3

> simplify(expr1);

5

> expr2:=exp(a+ln(b*exp(c)));

expr2 := exp(a+ln(b*exp(c)))

> simplify(expr2);

b*exp(a+c)

> expr3:=sin(x)^2+cos(x)^2;
simplify(expr3);

expr3 := sin(x)^2+cos(x)^2

1

> e := cos(x)^5 + sin(x)^4 + 2*cos(x)^2 - 2*sin(x)^2 - cos(2*x);
simplify(e);

e := cos(x)^5+sin(x)^4+2*cos(x)^2-2*sin(x)^2-cos(2*...

cos(x)^5+cos(x)^4

> f := -1/3*x^5*y + x^4*y^2 + 1/3*x*y^3 + 1;
simplify(f, {x^3 = x*y, y^2 = x+1});

f := -1/3*x^5*y+x^4*y^2+1/3*x*y^3+1

1+y^5+y^4-2*y^3-y^2+y

> g:=sqrt(x^2);

g := sqrt(x^2)

> simplify(g);

csgn(x)*x

> simplify(g,assume=real);

abs(x)

> simplify(g,assume=positive);

x

See Also: collect , combine , convert , expand , factor , normal , radsimp , assume

solve

Function: solve - Solve Equations

Calling Sequence:
solve(eqn, var)
solve(eqns, vars)

Parameters:
eqn - an equation or inequality
eqns - a set of equations or inequalities (equations or inequalities enclosed between braces {})
var - (optional) a name (unknown to solve for)
vars - (optional) a set of names (unknowns to solve for) (unkowns enclosed between braces {})

Description:

floats functions identity ineqs linear
radical scalar series system

Examples:

> restart;

Solve for a

> solve( f=m*a, a );

f/m

Solve eq for x

> eq := x^4-5*x^2+6*x=2;
solve(eq,x);

eq := x^4-5*x^2+6*x = 2

1, 1, -1+sqrt(3), -1-sqrt(3)

Solve eq for x and put the answers in a list (brackets). This way we can refere to the solutions as elements of the list

> sols := [solve(eq,x)];

sols := [1, 1, -1+sqrt(3), -1-sqrt(3)]

Element i in the list is refered to as sols[i].

> sols[1];sols[3];

1

-1+sqrt(3)

Use evalf to converst the answers to floating points

> evalf(sols);

[1., 1., .732050808, -2.732050808]

> eq;

x^4-5*x^2+6*x = 2

Solve eq for x and put the answers in a set (braces). We can then refer to the elemenst using subscripts.
Note that the repeated root was not listed twice as was the case in putting the answers in a list (see above)

> sols := {solve(eq,x)};
sols[1];sols[3];

sols := {1, -1+sqrt(3), -1-sqrt(3)}

1

-1-sqrt(3)

Check the first answer by substituting it in the equation

> subs( x=sols[1], eq );

2 = 2

> simplify(%);

2 = 2

Equations are provided in a set, no set of unknowns is provided (hence Maple assumes that we are solving for the variables in the equations):

> eqns := {u+v+w=1, 3*u+v=3, u-2*v-w=0};

eqns := {3*u+v = 3, u-2*v-w = 0, u+v+w = 1}

Manipulating Solutions solve for u,v,w

> sols := solve( eqns );

sols := {v = 3/5, w = -2/5, u = 4/5}

check solutions

> subs( sols, eqns );

{3 = 3, 0 = 0, 1 = 1}

pick off one solution

> subs( sols, u );

4/5

assign all solutions

> assign( sols );
u;w;

4/5

-2/5

Other examples

> solve( cos(x)+y = 9, x );

Pi-arccos(y-9)

> solve( x^2+x>0, x );

RealRange(-infinity,Open(-1)), RealRange(Open(0),in...

Solve a system of equations

> solve( {x^2*y^2=0, x-y=1} );

{y = 0, x = 1}, {y = 0, x = 1}, {x = 0, y = -1}, {x...

> solve( {x^2*y^2=0, x-y=1, x<>0} );

{y = 0, x = 1}, {y = 0, x = 1}

See Also: RootOf , allvalues , dsolve , fsolve , isolve , msolve , rsolve , assign , invfunc , isolate , match , linalg[linsolve] , simplex , grobner , solve[subtopic] where subtopic is one of: floats , functions , identity , ineqs , linear , radical , scalar , series , system

unapply

Function: unapply - Returns an Operator from an Expression and Arguments

Calling Sequence:
unapply(expr,x,y,..)

Parameters:
expr - any expression
x,y,.. - variable names

Description:

Examples:

> p := x^2 + sin(x) + 1;

p := x^2+sin(x)+1

> f := unapply(p,x);

f := proc (x) options operator, arrow; x^2+sin(x)+1...

> f(Pi/6);

1/36*Pi^2+3/2

> q := x^2 + y^3 + 1;

q := x^2+y^3+1

> f := unapply(q,x);

f := proc (x) options operator, arrow; x^2+y^3+1 en...

> f(2);

5+y^3

> g := unapply(q,x,y);

g := proc (x, y) options operator, arrow; x^2+y^3+1...

> g(2,3);

32

See Also: operators[functional] , operators[example] , operators[D]

with

Function: with - loads a library package such as DEtools, linalg, etc

Description:

Examples:

Define a 2 x 2 matrix

> a:=matrix(2,2,[1,2,3,4]);

a := matrix([[1, 2], [3, 4]])

The inverse of the matrix in not computed because the inverse command resides in the package linalg which has not been loaded yet

> inverse(a);

inverse(a)

Load the linear algebra package. The commands that are available in the package are listed (if you do not want to see the list of availabe commnads terminate the with command with ' : ' instead of ' ; ')

> with(linalg):

Warning, the protected names norm and trace have been redefined and unprotected

Now the inverse command is availabe and the inverse of a is computed

> inverse(a);

matrix([[-2, 1], [3/2, -1/2]])

See Also: index[package] , readlib , libname , table , indexfcn

wronskian

Function: linalg[wronskian] - wronskian matrix of a vector of functions

Calling Sequence:
wronskian(f, v)

Parameters:
f - a vector or list of expressions
v - a variable

Description:

Examples:

> with(linalg):

> A := vector([exp(x),cosh(x),sinh(x)]);

A := vector([exp(x), cosh(x), sinh(x)])

> Wr := wronskian(A,x);

Wr := matrix([[exp(x), cosh(x), sinh(x)], [exp(x), ...

> det(Wr);

0