Web viewIf you wish to copy the output of Maple to enter into a word processor, ... Consider the...

download Web viewIf you wish to copy the output of Maple to enter into a word processor, ... Consider the following initial value problem: y’=(4-2/3x+4y)-1, y(0)=1

If you can't read please download the document

Transcript of Web viewIf you wish to copy the output of Maple to enter into a word processor, ... Consider the...

20

MAPLE TUTORIAL for Ordinary Differential Equations (ODEs)

Ver. 1.1

Raymon Baek

Vladimir Dobrushkin

Table of Contents

Preface.3

Before You Begin: Notes on Formatting...4

1. Functions: Definition, as a Solution of ODE, Piecewise, Plotting5

i. How to define functions..5

ii. Plotting functions.6

iii. Plotting with axes, without axes7

iv. Implitictplot command.8

v. Displaying multiple plots in the same/separate plane..9

2. Solving ODEs: dfieldplot, DEplot, odeplot, Defining Function as ODE, Nullclines...12

i. Solving Using Direction/Slope Fields (dfieldplot).13

ii. Solving Using DEplot.14

iii. Solving Using odeplot..14

iv. Plotting Vertical Lines..15

3.Analytical Solutions (General and Particular Solutions) and Cauchy Problem.17

i. Solving ODEs (General Solution)..17

ii. Solving ODEs (Particular Solution)..17

iii. Initial Value Problem (Cauchy Problems)..17

4. Sequences and Recurrences....19

i. Explicitly Defined Sequences..19

ii. Recursively Defined Sequences.19

iii. Using rsolve.19

iv. Resolving First Order Recurrences..20

5. Numerical Solutions: Plotting Difference Between Exact and Approximate in Regular Plot/Log Plot..21

i. Eulers Method.21

ii. Backwards Eulers Method..23

iii. Trapezoid Rule..23

iv. Improved Eulers Method.23

v. Modified Eulers Method..24

vi. First Order Polynomial Approximation25

vii. Second Order Polynomial Approximation.25

viii. Third Order Polynomial Approximation..26

ix. Regular Plotting vs. Log-Plotting..27

x. Runge-Kutta Method27

6. Laplace Transform.29

Preface

This tutorial is meant as an introduction to the mathematical program Maple created by MapleSoft for the APMA 0330 course. This is a tutorial made solely for the purpose of education.

If you have not taken or are not taking a course regarding Maple or programming, such as CSCI 0150 or ENGN 0030, then please begin from Chapter 1. Otherwise, please begin from Chapter 2: Functions: Definition, as a Solution of ODE, Piecewise, Plotting. For those who have used Maple before, please note that there are certain commands and sequences of input that is specific to solving differential equations, so it is best to read through this tutorial in its entirety. This tutorial is based on Maple versions 10~15. Therefore, tutorials from other sources may or may not be compatible with this tutorial.

This tutorial corresponds to the Maple mw files that are posted on the APMA 0330 website. You, as the user, are free to use the m files to your needs for learning how to use the Maple program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

Before You Begin: Notes on Formatting:

Text vs. Math

When starting maple, you will see a blinking cursor in an outlined square box:

This means you are typing information that Maple will interpret as math. This will be the input mode we will use in the rest of this tutorial and is technically all you need to know to use Maple. However, sometimes you may want to provide additional information on your Maple printouts, in which case you will want to switch to text input mode by clicking the button in the top left-hand corner. The cursor will change to a normal cursor, and maple will work like any standard text editor.

Copy and Paste:

If you wish to copy the output of Maple to enter into a word processor, make sure to change the font of the output to monospaced, because the default output of Maple is an image and not text.

Drawing on Plots

One can easily draw on plots by first clicking on the plot you want to modify, then clicking on the draw input button:

Once in drawing mode, you can draw on the plot as if it were any normal layout software (ie. Indesign, Microsoft Word etc.) with textboxes, arrows, and shapes. One note is that to end an arrow, you must click back on the arrow point where the arrow starts.

1. Functions:

How to Define Function and Plots

How to define functions

In Maple, defining functions, or anything for that matter, is done by the command :=

Try the following input (without the >, it is only used to denote a Maple input):

> |(x^3+x+sqrt(x))/(Pi*x-1)|;

The resulting output should be:

Here is a guide to basic operators:

Operation

Expression

Operation

Expression

Operation

Expression

Addition

+

ex

exp(x)

Pi (remember to capitalize)

Subtraction

-

ln(x)

ln(x)

y^x

Division

/

sqrt(x)

exact answer

evalf()

Multiplication

*

Absolute Value

abs(x) or |x|

use most recent input

%

Some important reminders:

1. You must hit the right arrow key after inputting exponents, or you will continue to type in the exponent. The same concept applies to division; you must hit the right arrow to leave the numerator or denominator.

2. When inputting , you must type in Pi. For some reason, sometimes Maple will not accept pi as .

3. When using division, be sure to separate the numerators and denominators with parentheses to prevent errors.

4. When you wish to substitute a variable with a value, use the subs command. The generic syntax is as follows:

> subs(value, equation);

Therefore, if we use the above equation to substitute x with the value -2, we have:

> subs(x=-2, %);

The % is a special symbol which takes in the most recently inputted equation. This is a useful symbol to use to avoid assigning equations to variables.

5. You will notice in #4 that the resulting output is not be a specific value, but another equation with the x substituted with -2. You can call evalf() on the result for an exact answer:

> evalf(%);

1.386687900

Plotting functions

Lets begin by looking at the basic syntax of the plot command in Maple:

>plot(function, range, options(if any));

As you can see, the plot function involve a function, the x and y ranges of the plot, and any conditions if there are any present. The x and y ranges do not necessarily have to be inputted, but if there are other functions to plot (mentioned later), it is best to make the plot fit all functions by inputting the appropriate ranges. If you do not input a range for one function, then Maple will automatically generate a plot that fits the function. There are many options to choose from when using all types of plot commands. The most important options that can be used for ODEs are listed below, but others are listed in the Maple website:

http://www.maplesoft.com/support/help/Maple/view.aspx?path=plot%2foptions.

Option

Code Input

Notes

Specify type of axes

axes=f

The value f can be boxed, framed, none, or normal. This option is automatically set to normal if not specified.

Coordinate system

axiscoordinates=t

The value t can be either polar or Cartesian. This option is automatically set to Cartesian if not specified.

Specifying color for curves to be plotted

color=nOR

colour=n

The value n can be replaced with any color. For simplicities sake, its best to use simple colors such as blue and red. This option is automatically set to the default color of the plot command (which is usually red).

Detecting discontinuities

discont=t

If a discontinuity exists in the specified function for plotting, then the t value is true. This option is automatically set to false if not specified.

Labeling axes

labels=[x,y]

This option specifies what the axes in the plot is labeled with. By default they have no labels.

Legend entry

legend=s

This option can be used for displaying a legend entry for each curve in the plot. The s value can be whatever the user desires. This option is automatically nonexistent if not specified.

Scaling of the graph

scaling=s

The s value can be constrained or unconstrained. The default value is unconstrained, which means the plot is scaled to fit the window. The constrained value makes all axes use the same scale (ie. a circle would appear perfectly round).

Symbols used to plot graph

symbol=s

The s value can be asterisk, box, circle, diagonalcross, diamond, point, solidcircle, soliddiamond, or solidbox. This option is automatically nonexistent if not specified.

Title of graph

title=t

This option can be used for displaying a title for the plot. This option is automatically nonexistent if not specified.

Lets plot a piecewise function:

> f:= piecewise(x (cos(x),x=-2*Pi..2*Pi,title=Cosine Graph, axes=framed, axiscoordinates=Cartesian,color=green,labels=[x,t],legend=Function);

This input generates the below graph:

Plotting with axes, without axes

There are times when the axes could interfere with displaying certain functions and solutions to ODEs. Fortunately, getting rid of axes in recent versions of Maple is very easy.

One method of specifying axes is to use the above options, but there is also a visual method of changing axes.

Simply right-click the graph that is generated by Maple, and go to the tab labeled Axes, and click None to remove the axes from the graph. If you wish to make them appear, make sure the None is unchecked. You may also see the axes boxe