Beruflich Dokumente
Kultur Dokumente
1
Mathematical Methods with Maple
Computer algebra systems in scientific computing (see e.g.
J.Gathen, J.Gerhard. Modern Computer Algebra. Cambridge
University Press, 1999; M.J.Wester. Computer Algebra
Systems: A Practical Guide, John Wiley, 1999)
Maple an interactive system, allowing one to carry out both
numerical and analytical computations. Maple contains 2D
and 3D graphical means, powerful programming language
and an extensive library of mathematical formulae
A convenient working method, when all stages of
mathematical, physical or engineering research can be
stored in a single document - worksheet
The worksheet automatically becomes a scientific article,
report, chapter in a book, etc.
2
Literature on Maple
3
Contents overview of the Chapter 1
General:
Maple has an extensive Help facility, it is an essential aid
Algebraic
Maple Variables
equations
Basics and
and
operators
transforms
Analytical ODE
transform Numeric
s s
PDE Graphic
s Programming
4
Document organization in Maple
One should familiarize oneself with Maple GUI
The best way is to learn use and syntax of Maple simultaneously
and by examples
A worksheet (*.mws) consists of logical groups called execution
groups Each group consists of several parts :
- Input Region
- Output Region
- Text Region (e.g. comments)
The principal objects in Maple: numbers, constants, names
- numbers: integer, real, rational, radicals
- constants: Pi, I, E, Infinity, gamma, true, false
- names: sequences of symbols starting with literal (e.g. new, New,
new_old, etc.)
5
Syntax and expressions
After typing a command, you should inform the computer that
the command has ended and must be accepted. There are
two types of terminators: ; and : The colon is needed to
suppress Return the output is not printed
The symbol % is called ditto, it is used to refer to previous
return. Twofold ditto (%%) refers to the second last return,
etc. In releases before Maple V.5, the double quote was
used for ditto. Remark: this notation may be convenient for a
succession of operations, but can be confusing when the
commands are executed in arbitrary order
Expressions are the main object for the most of commands.
Expressions are composed of constants, variables, signs of
arithmetical and logical operations
6
Typical syntax errors and remedies
Forgetting a bracket or an operator the error message comes after
Return (sometimes it appears meaningless)
It is easier to type the brackets and some operators first, and then
insert functions, variables and parameters, e.g.
> ( )*(sqrt( ) + ( )^( ) )* exp( );
It is better to start a new worksheet with the command restart
this resets the system and variables used in a previous worksheet
do not cast their value into the new one
Not all combinations of symbols are allowed in Maple (e.g. Pi and
I are already used by the system). In older versions of Maple E was
reserved for the constant e=2.71828..; in later versions the value
of the natural logarithm base is given by e=exp(1); but exp (1.0)
gives directly the number 2.718281828
7
Assignment of variables in Maple
In contrast to many programming languages, variables in Maple
can be free (unbounded). For instance in Fortran or Basic (and to
some extent in C), variables can be used only after being assigned a
specific numerical value
A variable can be made bound by using the assignment symbol :=
Example: to find the solution of a quadratic equation
> solve(a*x^2 + b*x + c=0,x);
1 b b2 4ac 1 b b 2 4ac
,
2 a 2 a
Here x is the unknown variable; a,b,c are parameters all these letters
are free. If we assign the variable y the value ax2 + bx + c:
> y:=(a*x^2 + b*x + c=0,x); # then until y is cleared or assigned
# another value, y is ax2 + bx + c
8
Reserved names in Maple
all the standard mathematical functions, e.g. sin, cos, exp, sqrt, sinh, cosh
have predefined names, and so do Maple commands and procedures:
int, diff, plot, sum, coeff, rhs, lhs,.. The same applies to data types: array,
list, set, matrix,..
9
Some sources of confusion
The difference between assign := and is equal to =
By assigning x :=a we are instructing the computer to replace x by
a wherever the former is met
Let us take a linear function, y = kx + b. This equation can be
rearranged e.g. in the manner y b = kx or x = (y b)/a
Now suppose we assign a variable, y : k x b then we are
already unable to rearrange this assignment
Suppose that one assigns a variable to an equation:
y : a x ^ 2 b x c
so that one can solve the quadric equation with the command
> solve (y,x). If one wishes now to solve a system of equation in
variables (x,y), one should be careful because y has already been
assigned (e.g. one would need to clear variables with restart)
10
Different manners of assignment
An example: to solve the system of equations
ax by A; cx dy B with respect to x and y
First the restart command, since x and y could be already assigned
Then we may assign e.g. z to the whole set of equations and u to
the set of unknown variables
> restart;
> z:={a*x+b*y=A,c*x+d*y=B}:
> u:={x,y}:
> sol:=solve(z,u);
Pressing return we obtain the Maple solutions, now we can assign
these solutions to be x and y
> assign(sol);
> x,y;
11
Different manners of assignment-II
After the assign command variables are not free
The used manner of assignment is convenient when there is only
one solution
Curly brackets signify declaration of a set
An example of another manner of assignment. A problem:
To find the distance of the intersection point of two straight lines
defined by the above equations from the origin of coordinates
> dist:=subs(sol,sqrt(x^2+y^2));
Here the substitute command subs is conveniently used, and in this
manner the variables x and y remain free
If we attempted to call the distance d or D, Maple would produce
an error
12
Substitutions
The substitute command is very important, since it is used to
change variables. Its formal structure may be designated as:
subs (old=new, expression),
where the variable old is replaced by the expression new in the
object expression (actually, this object may be not only an
expression but also a set, a list, etc.)
It is allowed to use a number of substitutions old=new , but in
this case multiple substitutions should be formulated as a set (see
two preceding slides)
Substitution does not change the initial object, but results in a new
expression. Thus, some simplifications may be needed. Example:
> restart;
> s:=subs(x=0,(sin(x)-1)*cos(x-Pi/3));
> factor(s),expand(s),simplify(s),eval(s);
13
Usual difficulties with assignments
The following example: we have assigned y : 3* x ^ 2 7 x 9
Now we want to know y(2), we can get this value by assigning 2 to x,
so y automatically becomes:
> y:=-3*x^2+7*x+9;
2
y := 3 x 7 x 9
> x:=2;y;
x := 2
11
And now we need to integrate y, i.e. to compute ydx dx(3x 7 x 9)
2
FileNew
Worksheet Mode
Maple Essential Tutorials
Maple has courseware on the website
www.maplesoft.com
http://www.maplesoft.com/applications/view.aspx?SID=4745
An example of numerical solution of ODE
The dynamical system the Cauchy problem for a nonlinear
oscillator with linear friction:
> s:=D(x)(t)=y(t),D(y)(t)=-a*y(t)-.8*sin(x(t));
> ic:=x(0)=0,y(0)=2;
> F:=dsolve({s,ic},{x(t),y(t)},numeric);
> a:=.2;evalf(F(1.5),5);
>plots[odeplot](F,[[t,x(t)],[t,y(t)]],0..30,labels=[t,"x,y"],axes=boxed);
To visualize numerical solutions of this Cauchy problem, one may
use the graphics commands from the DEtools package
The obtained solution may serve as a source of all the necessary
information about the system
Assignment: solve numerically the Cauchy problem for the
dynamical system. dx dy
y (t ), 3
x(t ) x (t ), x(0) 0, y(0) 0.1
dt dt
25
A list of exercises
To solve the problems contained in the below list of exercises you
may use any method you wish, e.g. computer algebra products like
Maple or Mathematica, available analytical techniques (separation of
variables, Fourier integral or other integral transforms, Greens
functions, etc.). You can also use numerical techniques where possible
1. Write the solution to the equation:
x 2 x f (t ), x(0) x(0) 0
To what model does this equation correspond?
2. Classify the following equations as elliptic, hyperbolic or
parabolic
2 2 y 2 y 2
u 2
u
a) 2 2 0; b) 8; c)(M 1) 2 2 0, M 0
2
v u u uv x y
Exercises 26
Exercises-2
3. Find the solution to the problem:
u 2u
2 2 , u (0, t ) u ( , t ) 0, u( x, 0) sin 2 x
t x
2u
4. Solve the equation x 2 y . Find a particular solution for
xy
u( x,0) x2 , u(1, y) cos y
5. Solve the boundary value problems:
u u
a) 5 , u (0, y) 10e4 y
x y
u u
b) a 0, u (0, y) Ae y Be y
x y