You are on page 1of 6

2/2/2020

Start up with Maple


• MAPLE is a very good program that is used to do symbolic
manipulations of mathematical expressions
• The syntax in MAPLE is very sensitive to punctuation marks, such as,
Start Up with MAPLE “]” or “{“ or “,” or “;” and Capital/small letters…etc.
• When you start a new document, you will have a white sheet, it is a
Short Guide good practice to start a first line with the command restart;
By • restart; clears the memory and remove all names of variables ..etc
Mahmoud M.S. Dwaikat • Make sure you are in “Math” style when typing math expressions
• Use “Text” style to write comments, or use # before any text to make
it a comment line.

1 2

MAPLE BASICS – Syntax Sensitive


• The “ = “ is used as an equal inside a math expression. It does not
Run , executes a single line “assign” values.
Run ALL document
• The “ := “ is used to assign values to variables
Two styles: Text and Math • If you type x = 4 ; then hit enter, it will give you “ x=4” simply as an
Always start with : restart; expression, but does not mean that the value of x is stored as = 4.
Type x again and hit enter, it will just give x. (not a value).
Symbolic Math Templates
• If you type x:=4, then the program will store the value of 4 to the
variable x. So, if you type x anywhere and hit enter, it will show its
value “4” not x.

3 4
2/2/2020

MAPLE BASICS - Expressions MAPLE BASICS - Expressions


• To define an equation, then simply type: Eq1:= 5*x^2+6*x-8=0; • Type: Eq2 := a*x^3 - b^2*x + c*b = 0; to define an equation, then type:
• This will store the equation 5*x^2+6*x-8=0 to the variable name Eq1 B:=solve(Eq2,b); gives you
• If the value of x has already been assigned some value (like x:=4) , the
program simply will calculate the expression 5*x^2+6*x-8 and gives you
96=0. • To substitute values into expression, use: subs(c=3,B[1]); this will substitute
• To clear the value of only x from the memory, use the command: c=3 in expression of B[1]. Giving you
unassign(‘x’); This will return the value x to be a variable without value.
• Type: Eq1:= 5*x^2+6*x-8=0; gives you an equation 5*x^2+6*x-8=0 • To do integral of the function a*x^2+b*x
• To solve it: use the command X:=solve(Eq1,x); means: Solve Eq1 for int(a*x^2+b*x , x= 0..t);
variable x, and store the answers in X. Note here X is different from x.
This will integrate the expression
• Type: X:=solve(Eq1,x); hit enter, gives you: 4/5, -2
From x = 0 to x=t, No spaces between 0..t
• To show the first value of X type X[1]; hit enter: shows you 4/5
5 6

MAPLE BASICS – Differential Equations MAPLE BASICS – Differential Equations


• You can also define differential equations in MAPLE. • To solve the D.Eq. with known initial conditions, First, define the initial
• DEq1:= m*diff(u(t),t$2)+c*diff(u(t),t) +k*u(t) = 0; conditions : Type: ICS:= u(0)=1 , D(u)(0)=5 ; This defines initial value for
u at t= 0 , to be equal to 1. and the first derivative of u at t=0 to be 5.
• Then type: dsolve({DEq1, ICS}); it will solve the equation

• To solve it generally: (if the solution exists): type: dsolve(DEq1);

• Note if you type u(t) then hit enter, it will not show you the answer you
7
obtained. 8
2/2/2020

MAPLE BASICS – Substitute and Plot MAPLE BASICS - Plot


• To show the answer, you need to store the answer in a variable, so type: • Use plot command: plot(U1, t=0..5); to plot function U1.
• U:= rhs(dsolve({DEq1,ICS})); This will store the right-hand-side (rhs) of the
equation that contains the solution. Now if you type U it will give you the
answer you need.
• To plot the answer, first you need to substitute values, and leave only
single variable to plot. Use U1:=subs(m=1,k=4,c=0.2, U); This will
substitute values for m, c,k, inside expression U, and store the new result
into variable U1.

• Let’s evaluate the same expression with other constants,


U2:=subs(m=1,k=4, c=3, U); and then compare it to U1
9 10

MAPLE BASICS – Plot MAPLE BASICS - Matrices


• To compare solutions U1 and U2, Use plot command:
• MAPLE is also good for matrices. Define matrix using Matrix command.
plot([U1,U2], t=0..5, legend=[“U1”, “U2”], linestyle=[solid, dash]);
• A:=Matrix(5,5,0), will create 5 X 5 matrix A with all values in it = 0.
• To create matrix M, use:

• Or using M:= < < 1 | 2 > , < 3 | 4 > >;


• Find the inverse and transpose of the matrix, use ( M^-1 ) and ( M^%T )
• To compute the determinant, first you have to activate a special package
that deals with matrices. The package is called “LinearAlgebra” , so first
type with(LinearAlgebra): notice here the : prevents “echoing” the
results. Then you write Determinant(M);

11 12
2/2/2020

MAPLE BASICS - Matrices MAPLE BASICS - Matrices


• You can do operations on matrices. Use “ . “ to multiply matrices • To extract a subset of a matrix, use:
A1n = A[1,1..3] ; This takes the first
row and columns 1 to 3 from matrix A
and stores it into A1n as a row vector.
• To take derivative of every entry inside
a matrix, use the map command to
distribute the operation of the integral
“int” over every entry inside the matrix

• The same is done for derivatives


map(diff, A, x$2) , this will take the
second derivative of A with respect to x.
13 14

MAPLE BASICS - Functions EXAMPLE: Quadratic Bar Element Using MAPLE


• In order to define a variable as a function F(x)=3*x^2+1 , use: x -> • Lets use MAPLE to construct the stiffness matrix for a quadratic bar element
• F:=x -> 3*x^2 +1 ; Now if you substitute F(3) , hit enter it will give you 13. • First define the function matrix X and coefficient matrix a, used to define the
displacement as: u :=X.a, :
• Sometimes you have (as results of solutions, etc) some system of equations in restart; X:=< 1| x | x^2 >; a:= < <a1>, <a2>, <a3> >; u:=X.a;
some repeated variables, say You have two equations: a*x+b*y = 5 and a*x
– b*y = 2, and you want to write them in matrix form
• First, activate the “LinearAlgebra”
package, then You can re-write
these equations as matrix using 
This will give you, A and c such that
Ax = c , which can be solved as
X:=(A^-1).c; 15 16
2/2/2020

Quadratic Bar Element Using MAPLE Quadratic Bar Element Using MAPLE
• Evaluate X at the nodes at X = 0, L/2 and L. • Now to write u as a function of DOF (u1,u2,u3), then U = [X*inv(Xo)]*d , the
X1:=subs(x=0,X); X2:=subs(x=L/2, X); X3:=subs(x=L,X); matrix [ X*inv(Xo) ] is the shape function matrix. Use N:= X.Xo^-1 ;

• Note that N[1] gives you 1-3x/L+2x2/L2 , … etc.


• The strain is defined as eps = du/dx, but u = Nd, therefore, eps = (dN/dx)d, call
the matrix dN/dx as B matrix, defined as: B:=map(diff,N,x);

• Generate matrix Xo, where Xo are the


trial functions evaluated at location
of nodes.Use: Xo:= < <X1> , <X2>, <X3> >;
17 B1 B2 B3 18

Quadratic Bar Element Using MAPLE Quadratic Bar Element Using MAPLE
• Because E, A are constants, the stiffness matrix is then K ୣ = ‫ ׬‬۰ ୘EA۰dx • To compute the equivalent nodal force from a uniform distributed load qo
Which is computed in MAPLE as: Ke := map( int , B^%T . (E*A*B) ,x=0..L ) ‫ܨ‬௘௤ = න ‫ݍ ் ۼ‬௢ ݀‫ݔ‬

Fe := map( int , qo*N^%T, x = 0..L )

• Notice the “ . “ and the “ * “ for matrix and scalar multiplications,


respectively.
19 20
2/2/2020

MAPLE BASICS
• All the above steps can be condensed to the following coding:.
restart;
X:=< 1| x | x^2 >; # define the X and Xo
Xo:= < <subs(x=0,X)> , <subs(x=L/2,X)>, <subs(x=L,X)> >;
N:= X.Xo^-1; # Define the shape functions matrix
B:=map(diff,N,x); # Define the strain function
Ke := map( int , B^%T . (E*A*B) ,x=0..L ); # integrate for K
Fe := map( int , qo*N^%T, x = 0..L ); # integrate for nodal forces

• Any statement starting with #, will be considered a comment, and will not be
executed by the program
• The “ ; “ makes the program display the results, use “ : “ if you don’t want to
display the results 21

You might also like