IVP_worksheet.mws

Numerical Analysis Student Package-IVP

Initialization

>    restart:
currentdir("C:\\Documents and Settings\\Test Name\\Desktop\\School\\websites\\mohammad\\IVP"):
libname := "C:\\Documents and Settings\\Test Name\\Desktop\\School\\websites\\mohammad\\IVP",libname:
with(InitialValueProblem);

[AB, AM, Euler, RK, Taylor]

>    DE1:=diff(y(t),t) = y(t)-t^2+1;

DE1 := diff(y(t),t) = y(t)-t^2+1

>    DE2:=diff(y(t),t) = 1-cos(t):

>    DE3:=diff(y(t),t) = 2/(t+1) - y(t)^2:

>    DE4:=diff(y(t),t) = y(t)+t*cos(t):

>    DE5:=diff(y(t),t) = 1-y(t)/t:

>   

InitialValueProblem
The InitialValueProblem Module is to compute  numerical solution for the initial value problem (IVP).

The are five methods to solve the IVP problems in the Student[InitialValueProblem] module, Euler, Taylor, RK (Runge-Kutta), AB (Adams-Bashforth), and AM (Adams-Moulton).

RK
RK is the classical Runge-Kutta method. The Runge-Kutta method has the 'midpoint', 'MEuler', 'Heun',
'rk3', 'rk4', and 'rkf' submethods. The default submethod is 'midpoint'.

>    RK(DE1,y(0)=0.5, t=0..3, submethod=midpoint);

4.730

>    RK(DE1, y(0)=0.5, t=0..3, submethod=Heun);

4.730

>    RK(DE1, y(0)=0.5, t=0..3, submethod=MEuler);

5.898

>    RK(DE1, y(0)=0.5, t=0..3, submethod=rk3);

5.877

>    RK(DE1, y(0)=0.5, t=0..3, submethod=rk4);

5.939

>    RK(DE1, y(0)=0.5, t=0..3, submethod=rkf);

5.957

>    RK(DE1, y(0)=0.5, t=0..3, comparewith([[RK,Heun],[RK,MEuler],[RK,rk3],[RK,rk4],[RK,rkf]]),
numsteps=10,output=plotsolution);

[Maple Plot]

>   

Euler
This is the forward Euler method.

>    Euler(DE1, y(0)=0.5, t=0..3,submethod=NONE);

5.066

>    Euler(DE1, y(0)=0.5, t=0..3, comparewith([[RK,rk4]]),output=table);

Array(%id = 152313388)

>    Euler(DE1, y(0)=0.5, t=0..3, comparewith([[RK,rk4]]),output=plotsolution);

[Maple Plot]

>   

AB
AB is the classical Adams-Bashforth method. AB has 'step2', 'step3', 'step4', 'step5', and 'corrector' submethods.
The default submethod is 'step4'.

>    AB(DE1,y(0)=0.5, t=0..3, submethod=step2);

7.850

>    AB(DE1,y(0)=0.5, t=0..3, submethod=step3);

6.597

>    AB(DE1,y(0)=0.5, t=0..3, submethod=step4);

6.130

>    AB(DE1,y(0)=0.5, t=0..3, submethod=step5);

5.974

>    AB(DE1,y(0)=0.5, t=0..3, submethod=corrector);

6.022

>    AB(DE1,y(0)=0.5, t=0..3, submethod=corrector, numsteps=10, comparewith([[AB,step2],[AB,step3],[AB,step4]]), output=plotsolution);

[Maple Plot]

>   

AM
AM is the classical Adams-Moulton method. AM has 'step2', 'step3', 'step4', and 'corrector' submethods.
The default submethod is 'step4'.

>    AM(DE1,y(0)=0.5, t=0..3, submethod=step2);

6.295

>    AM(DE1,y(0)=0.5, t=0..3, submethod=step3);

6.046

>    AM(DE1,y(0)=0.5, t=0..3, submethod=step4);

5.966

>    AM(DE1,y(0)=0.5, t=0..3, submethod=corrector);

5.947

>    AM(DE1,y(0)=0.5, t=0..3, submethod=corrector, numsteps=10, comparewith([[AM,step2],[AM,step3],[AM,step4]]), output=plotsolution);

[Maple Plot]

>   

Taylor
This is the Taylor method with a specified order (order=posint).

>    Taylor(DE1,y(0)=0.5, t=0..3,order=6);

5.957

>    Taylor(DE1, y(0)=0.5, t=0..3, comparewith([[RK,rk4]]),output=table);

Array(%id = 153343804)

>   

Options (digits, numsteps, table, plotsolution, Error, solution,optional output)

digits:  This option determines the number of digits for the output. The default value is 4.

>    RK(DE1, y(0)=0.5, t=0..3, digits=8);

4.7297985

numsteps: This option determines the number of steps for the numerical method. This is to determine the static step size for
each iteration in the algorithm. The default number of steps is 5.

>    RK(DE1, y(0)=0.5, t=0..3, numsteps=20);

5.860

output: This option indicates the type of output. It is of the form 'output'=output_type where output_type is one of:
'Error', 'plotsolution', 'solution', and 'table'.

>    AM(DE1, y(0)=0.5, t=0..3, output=Error);

.9152e-2

>    AB(DE1, y(0)=0.5, t=0..3, output=plotsolution);

[Maple Plot]

>    AB(DE1, y(0)=0.5, t=0..3, output=table);

Array(%id = 152952196)

optional output: Users can obtain more than one output_type by assigning the output_type to an unassigned variable.
For example, if we have output=solution and plotsolution=var1, the output will be the solution, and the variable var1 will be
assigned to plotsolution.

>    R1:='R1':R2:='R2':R3:='R3':
RK(DE1, y(0)=0.5, t=0..3, output=Error, numsteps=8, table=R1, solution=R2, plotsolution=R3, comparewith([[RK,rk4], [RK,midpoint],  [AB,step4]]));

.5461

>    R1;

Array(%id = 149706296)

>    R2;

5.411

>    R3;

[Maple Plot]

>    R4:='R4':R5:='R5':R6:='R6':
Taylor(DE1, y(0)=0.5, t=0..3, output=Error, numsteps=5,table=R4, Error=R5, plotsolution=R6,comparewith([[RK,rk4], [RK,midpoint],[AB,step4]]));

.1675

>    R4;

Array(%id = 149182828)

>    R5;

.168

>    R6;

[Maple Plot]

>   

>