Docsity

Maple Tutorial for Differential Equations in Math 2250, Assignments of Mathematics

Toggle sidebar
bg1
Maple Tutorial − Math 2250
October 10 2005
Differential Equations
First, we briefly review basic Maple commands and how we can use Maple to study differential equations.
Most of this should be familiar from the previous tutorial as well as your first Maple assignment.
A few things to remember and. what you need to do first when things don’t work out !
* Command lines should begin with the prompt ">"
* End every command with a semicolon ";" or a colon ":" If you end with a semicolon, you will see a
visible output while ending with a colon will suppress your output.
* Always check if you have the correct number of brackets if you get a cryptic error message. Also
check if your variable is called correctly; variable name and function name are case−sensitive
* You can enter explanatory comments in a command line by inserting a "#" Any text to the left of "#" will
be disregarded .
* You can use Maple in a text editor mode by clicking the "T" button at the very top. To go back to the
command line mode, click on the "[>" button next to the "T"
How to print?
You can print by clicking on the printer button above (or go to File and select Print)
Choose "Print Command" option and then type
lpr −l −P printername
That "−l" is dash−lower−case−L. Then hit "Print" button on the bottom of the print window
Printer names are
lcb115 in room LCB 115
spps in South Physics 205
mc155c in the Math Center
Arithmetic operation
> restart;
# it’s a good habit to begin with "restart" command.
# it will clear the memory so you can easily redo things
> 3+4; 6*7; (3+4)^2/5; 7
42
49
5
> evalf((3+4)^2/5); 9.800000000
> evalf[3]((3+4)^2/5);
# specify the number of digits of accuracy by using [] after evalf
# here, we evaluate to 3 digit accuracy9.80
> a := 3.5;
# define a variable by using ":=" not just "="
a := 3.5
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Maple Tutorial for Differential Equations in Math 2250 and more Assignments Mathematics in PDF only on Docsity!

Maple Tutorial − Math 2250

October 10 2005

Differential Equations

First, we briefly review basic Maple commands and how we can use Maple to study differential equations. Most of this should be familiar from the previous tutorial as well as your first Maple assignment.

A few things to remember and. what you need to do first when things don’t work out!

  • Command lines should begin with the prompt ">"
  • End every command with a semicolon ";" or a colon ":" If you end with a semicolon, you will see a visible output while ending with a colon will suppress your output.
  • Always check if you have the correct number of brackets if you get a cryptic error message. Also check if your variable is called correctly; variable name and function name are case−sensitive
  • You can enter explanatory comments in a command line by inserting a "#" Any text to the left of "#" will be disregarded.
  • You can use Maple in a text editor mode by clicking the "T" button at the very top. To go back to the command line mode, click on the "[>" button next to the "T"

How to print? You can print by clicking on the printer button above (or go to File and select Print ) Choose "Print Command" option and then type lpr −l −P printername That "−l" is dash−lower−case−L. Then hit "Print" button on the bottom of the print window Printer names are lcb115 in room LCB 115 spps in South Physics 205 mc155c in the Math Center

Arithmetic operation

**> restart;

it’s a good habit to begin with "restart" command.

it will clear the memory so you can easily redo things

> 3+4; 67; (3+4)^2/5;* 7 42 49 5

> evalf((3+4)^2/5);

**> evalf3;

specify the number of digits of accuracy by using [] after evalf

here, we evaluate to 3 digit accuracy**

**> a := 3.5;

define a variable by using ":=" not just "="**

a := 3.

**> a;

you can just refer back to the variable a from now on**

Differentiation and Integration

**> diff(x^3,x); # differentiate x^3 with respect to x > diff(x^3,x,x); # take second derivative

specify the n−th derivative with respect to x, by typing x n times**

3 x^2 6 x

> f:= x −> exp(sin(x))x^3; # defining a function*

f := x e

sin ( ) x x^3

> diff(f(x),x);

cos ( ) x e

sin ( ) x x^3 + 3 e

sin ( ) x x^2

**> int(t^2,t);

integrating t^2. note the integration constant is dropped here**

t^3 3

> int(t^2,t=0..1); # computing definite integral 1 3

*> int(t^3exp(sin(t)),t);

sometimes, maple doesn’t know how to do things either

i.e. it can’t find an elementary function for the anti−derivative**

t^3 e

sin ( ) t dt

*> evalf(int(t^3exp(sin(t)),t=0..1));

can still compute a numerical approx. to definite integral**

> evalf(Pi); evalf(exp(1)); infinity; # some important numbers

**> evalf(int(exp(−x),x=0..infinity));

you can integrate to infinity for some nice functions**

Plotting > with(plots): # load plot library Warning, the name changecoords has been redefined

*> dsolve(diff(y(t),t)=3y(t)+t, y(t));

you can also do it directly without naming the eqn. first**

y ( ) t = − t 3

  • e

( 3 t ) _C

*> dsolve(diff(y(t),t)=3y+t, y(t));

note that you have to refer to y(t) not just y

otherwise, maple won’t solve it for you**

Error, (in ODEtools/info) y(t) and y cannot both appear in the given ODE.

**> dsolve({eqn1, y(0)=1}, y(t));

solving with an initial condition

set up your system inside the {.,.}**

y ( ) t = − t 3

e

( 3 t )

**> DEplot(eqn1, y(t), t=0..10, y=0..100, title="slope fields");

plot slope fields with t from 0 to 10 and y from 0 t0 100**

**> DEplot(eqn1, y(t), t=0..10, y=0..100,{[y(0)=0],[y(0)=2]});

tracing a few solution curves

each initial condition must be put inside [.]**

You can change how things look by using the different option. Run the following few commands.

**> DEplot(eqn1, y(t), t=0..10, y=0..100,{[y(0)=0],[y(0)=2]}, color = blue );

changing the color of the arrows**

**> DEplot(eqn1, y(t), t=0..10, y=0..100,{[y(0)=0],[y(0)=2]}, linecolor = blue );

changing the colors of the solution curves**

**> DEplot(eqn1, y(t), t=0..10, y=0..100,{[y(0)=0],[y(0)=2]}, arrows = line );

changing the type of arrows to lines**

**> DEplot(eqn1, y(t), t=0..10, y=0..100,{[y(0)=0],[y(0)=2]}, arrows = thick );

thicker arrows**

**> DEplot(eqn1, y(t), t=0..10, y=0..100,{[y(0)=0],[y(0)=2]}, dirgrid = [20,20] );

this is the default arrow size, you can make it bigger

by choosing smaller values inside dirgrid as shown next**

> DEplot(eqn1, y(t), t=0..10, y=0..100,{[y(0)=0],[y(0)=2]}, dirgrid = [10,10] );

Linear Algebra

> restart;

> with(linalg): Warning, the protected names norm and trace have been redefined and unprotected

Defining matrices and vectors

> A.B; # matrix multiply using ’.’ not ’’* 7 36 4 16 81 10

25 126 16

> AB;* Error, (in rtable/Product) invalid arguments

> A.v; # matrix and vector multiplication 18 42

66

**> A^2; # you can take the square of a matrix so that

A^2 = AA*

30 36 42 66 81 96

102 126 150

> AA;* 30 36 42 66 81 96

102 126 150

> (A^4); # you can raise the matrix to any power you want 7560 9288 11016 17118 21033 24948

26676 32778 38880

In your text, they use the command Array instead of Matrix. This will work but doing operations is a bit tricky.

> C := Array([ [1,2,3],[4,5,6],[7,8,9] ]);

C :=

> C*C;

*# you can use the operation ’’ or ’.’

but it’s not the correct matrix multiplication

instead, it will do multiplication element by element**

1 4 9 16 25 36

49 64 81

> C.C; 1 4 9 16 25 36

49 64 81

Computing determinant and inverse

**> B_inv := Matrix(inverse(B));

take the inverse of matrix B

you need to set this as a Matrix in order to do operations after**

B_inv :=

− 2

− 8

**> inverse(B).v;

this is what happens if you don’t assign the inverse as a matrix**

2 0 − 2

− 2

− 8

> Matrix(inverse(B)).v;

Row Operations You need to know three function calls:

  • mulrow
  • swaprow
  • addrow Note all of these functions start with a lower case

> M := Matrix([ [2,2,−1,−6],[3,−3,5,36],[5,4,2,13] ]);

M :=

The function mulrow will multiply a row by a constant mulrow(A,2,4) will multiply row 2 of matrix A by 4 Another example below > M1 := mulrow(M, 1 , 1/2); # multiply row 1 of matrix M by 1/

M1 :=

−

The function addrow will multiply a row and then add it to another row addrow(A,1,3,5) will multiply row 1 of matrix A by 5 and then add it to row 3 So addrow(matrix_name, row_a, row_b, coeff) means coeffrow_a + row_b > M2 := addrow(M1,1,2,−3); # −3row(1) + row(2)

M2 :=

−

> M3 := addrow(M2,1,3,−5); # −5row(1) + row(3)*

M3 :=

−

Finally, swaprow will just swap two rows swaprow(A,1,3)

will swap row 1 and row 3 of matrix A > M4 := swaprow(M3,2,3); # swap row 2 and 3

M4 :=

−

Eigenvalues and Eigenvectors You may need these later....

> e := eigenvals(A); # compute the eigenvalues of matrix A

e := 0 , 15 2

Note that one of the eigenvalue is zero which again shows that matrix A is singular (not invertible)

> evalf(eigenvals(A)); # numerical values 0., 16.11684397, −1.

> v := [eigenvectors(A)]; # eigenvectors

v := 15 2

, 1 , −^1

, 1 , −^1

, 1 , [ 0 , 1 , {[ 1 , −2, 1 ]}]

> v[1][1]; # the first eigenvalue 15 2

> v[1][2]; # the multiplicity of that eigenvalue 1

> v[1][3]; # the corresponding eigenvector

**> v[2][1]; v[2][3];

the second eigenvalue and its corresponding eigenvector**