[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
[100] 006 revised on 2012.12.03 cemmath
The Simple is the Best
Chapter 6 Initial Value Problems
6-1 Syntax of Umbrella ‘ode’6-2 Self-Starting Integration Methods6-3 Multi-Points Integration Methods6-4 Application Examples6-5 System of IVPs6-6 Phase Diagram6-7 IVPs with Terminating Conditions6-8 Fully Implicit IVPs6-9 Steep IVPs6-10 Summary6-11 References
Initial value problems (IVPs) are one of the most important topics in science and engineering. In this regard, solution methods to IVPs are of critical importance. Here, we introduce the Umbrella ‘ode’ which can treat IVPs.
Section 6-1 Syntax of Umbrella ‘ode’
In this section, we discuss the standard forms of IVPs, and the syntax of Umbrella ‘ode’.
■ Standard IVPs and Syntax for ‘ode’. The Umbrella ‘ode’ is designed to solve IVPs the general forms of which are
DE : y ( n)=F ( t , y , y ' , y '' ,⋯ , y (n−1 ) )ICs : y (x0 )=k0 , y '(x0)=k1 ,⋯ , y(n−1 )(x0 )=kn−1
1
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
where t is an independent variable (typically time variable) and y is a dependent variable. The syntax for ‘ode’ to solve the standard IVPs reads
ode .t[n=101,g=1](a,b) ( << opt >>, DE, ICs ) .Spoke .Spoke ...
Much like other Umbrellas, the grid span for time variable follows right after the Umbrella ‘ode’. The Stem of ‘ode’ describes the DE and the ICs of interest. Subsequent Spokes handle data extraction, plot and integration methods, etc.
■ A Simple Case. Let us consider a simple IVP written as
0≤ x , y '= y+x+2 , y (0 )=−1
the exact solution of which is yex=2e x−x−3. To implement our motivation of expression-look-alike grammar, our Cemmath commands are written as
#> ode .x[11](0,1) ( y' = y+x+2, y = -1 ) .plot( y, -y+2*exp(x)-x-3 );
It would be readily understood that the interval of 0≤ x≤1 is divided into 10 uniform subintervals by the use of Hub grid ‘.x[11](0,1)’. Also, Spoke ‘plot’ yields two curves corresponding to expressions within the parenthesis. The results are shown in Figure 1.
Figure 1 A simple case of IVP
2
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
■ Spoke ‘return’. Umbrella ‘ode’ can return the final solution by using Spoke ‘return’. The syntax of Spoke ‘return’ is
.return( functions of(x,y,y',y'',…), … )
When Spoke ‘return’ is employed, the final result becomes matrix. The following IVP written as
y ''+ y=0 , y (0 )=0 , y ' (0 )=1
has an exact solution y=sin x . We solve this by the following Cemmath commands
#> ode.x[11](0,pi) ( y'' = -y, y = 0, y' = 1 ) .plot( y,y',-y+sin(x) ) .return( x,y,y', y*y+y'*y'-1 );
The solution plot is shown Figure 2, and Spoke ‘return’ produces the following matrix
ans = [ 0 0 1 0 ] [ 0.31416 0.30902 0.95106 4.9971e-006 ] [ 0.62832 0.58779 0.80902 9.9942e-006 ] [ 0.94248 0.80903 0.58778 1.4991e-005 ] [ 1.2566 0.95107 0.30901 1.9989e-005 ] [ 1.5708 1 -1.6882e-005 2.4986e-005 ] [ 1.885 0.95106 -0.30904 2.9983e-005 ] [ 2.1991 0.80902 -0.58781 3.498e-005 ] [ 2.5133 0.58778 -0.80905 3.9978e-005 ] [ 2.8274 0.309 -0.95109 4.4975e-005 ] [ 3.1416 -3.3764e-005 -1 4.9972e-005 ]
which represents the matrix [ x,y,y', y*y+y'*y'-1 ].
3
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
Figure 2 Spokes ‘plot’ and ‘return’ for an IVP
■ Spokes for Integration Methods. The integration method is by default based on the 4th-order Runge-Kutta-Fehlberg method, if not specified explicitly. Other integration methods can be adopted by using Spoke ‘method’ or several named Spokes.
Listed below are several Spokes to handle well-known integration methods in the literature.
.euler // .case(1) 1st-order Euler Method
.euler2 // .case(2) 2nd-order modified Euler method
.pc2 // .case(3) 2nd-order predictor-corrector
.rs2 // .case(4) 2nd-order Ralston method
.rk3 // .case(5) 3rd-order Runge-Kutta method
.r4 // .case(6) one of 4th-order Runge-Kutta methods
.k4 // .case(7) one of 4th-order Runge-Kutta methods
.rkg4 // .case(8) 4th-order Runge-Kutta-Gill method
.rkf4/rk // .case(9) 4th-order Runge-Kutta-Fehlberg method
.rkf5 // .case(10) 5th-order Runge-Kutta-Fehlberg method
.ab(n) // .case(11~16) nth-order Adams-Bashforth method
.am(n) // .case(21~26) nth-order Adams-Molton method
.apc // .case(31) Adams-predictor-corrector method
.mpc // .case(32) Milne-predictor-corrector method
.hpc // .case(33) Hamming-predictor-corrector method
.mopup // .case(34) Adams-Molton with mop-up method
Although more methods are known in the literature, other variations in solution methods are not implemented. As was mentioned, the default method adopted
4
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
here is
4th-order Runge-Kutta-Fehlberg method
In the following, we discuss several features of solution methods.
Section 6-2 Self-Starting Integration Methods
Among the integration methods known in the literature, self-starting integration methods do not resort to other integration methods and can initiate the numerical solution by themselves.
■ Euler Method. The Euler method, although simple and inaccurate, provides the fundamental concept of numerical integration of IVPs. For first-order IVPs, the following standard form
y '=f (x , y )
is approximated by the Euler method
yn+ 1= yn+hf (xn , yn ) , h=xn+1−xn
where detailed description of notations is omitted to save space.
(Example 6-2-1) As a first example, let us consider
y '=f (x , y )= y , y (0 )=1
which has an exact solution of y=ex. For an interval of 0≤ x≤0.1, we adopt two different steps, i.e. h=0.1 and h=0.01. This means that total numbers of nodes are 2 and 11, respectively, since both the starting and ending points are included. Reminding the Euler method given as yn+1= yn+hf (xn , yn ), we get
yn+1=(1+h ) yn=(1+h )2 yn−1=…=(1+h )n+1 y0
5
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
since f (xn , yn )= yn is from DE. We solve this problem by the following Cemmath commands
#> ode.x[ 2](0,0.1) ( y' = y, y = 1 ).euler.return(x,y,-y+exp(x)); #> ode.x[11](0,0.1) ( y' = y, y = 1 ).euler.return(x,y,-y+exp(x));
which result in
ans = [ 0 1 0 ] [ 0.1 1.1 0.0051709 ] ans = [ 0 1 0 ] [ 0.01 1.01 5.0167e-005 ] [ 0.02 1.0201 0.00010134 ] [ 0.03 1.0303 0.00015353 ] [ 0.04 1.0406 0.00020676 ] [ 0.05 1.051 0.00026105 ] [ 0.06 1.0615 0.0003164 ] [ 0.07 1.0721 0.00037283 ] [ 0.08 1.0829 0.00043036 ] [ 0.09 1.0937 0.00048901 ] [ 0.1 1.1046 0.00054879 ]
Since numerical values are
y x=0.1=(1+0.1 )1 y x=0=1.1y x=0.1=(1+0.01 )10 y x=0=1.1046221
the above results agree exactly with the previous formulation yn= (1+h )n y0. ◀
■ Modified-Euler Method. For a system of IVP given by y '=f (x , y ), The modified-Euler method, sometimes called the modified polygon method, is based on the following formulation
yn+ 1= yn+hf (xn+12h , yn+1 / 2)
6
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
yn+1 / 2= yn+12hf (xn , yn )
(Example 6-1-2) To compare the performance of the Euler and modified-Euler methods, consider again y '= y , y ( 0 )=1 for an interval of 0≤ x≤0.2. We use
h=0.1 (i.e. 2 steps) for modified-Euler method h=0.02 (i.e. 10 steps) for Euler method
Therefore, we write
#> ode.x[ 3](0,0.2) ( y' = y, y = 1 ).euler2.return(x,y,-y+exp(x)); #> ode.x[11](0,0.2) ( y' = y, y = 1 ).euler .return(x,y,-y+exp(x));
which results in
ans = [ 0 1 0 ] [ 0.1 1.105 0.00017092 ] [ 0.2 1.221 0.00037776 ] ans = [ 0 1 0 ] [ 0.02 1.02 0.00020134 ] [ 0.04 1.0404 0.00041077 ] [ 0.06 1.0612 0.00062855 ] [ 0.08 1.0824 0.00085491 ] [ 0.1 1.1041 0.0010901 ] [ 0.12 1.1262 0.0013344 ] [ 0.14 1.1487 0.0015881 ] [ 0.16 1.1717 0.0018515 ] [ 0.18 1.1951 0.0021248 ] [ 0.2 1.219 0.0024083 ]
Note the better performance of the modified-Euler method, as expected. However, from the standpoint of accuracy, it is recommended to employ at least 4th-order methods such as the 4th-order Runge-Kutta-Fehlberg method. ◀
■ Other Methods. Other self-starting methods can be compared by solving a properly selected benchmark problem. Let us consider a very oscillating profile
7
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
yex=sin x2obtained from
y '=2 xcos x2 , y (0 )=0
This problem is solved by
#> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).pc2 .plot(y-sin(x*x),y); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).rs2 .plot(y-sin(x*x),y); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).rk3 .plot(y-sin(x*x),y); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).r4 .plot(y-sin(x*x),y); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).k4 .plot(y-sin(x*x),y); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).rkg4 .plot(y-sin(x*x),y); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).rkf4 .plot(y-sin(x*x),y); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ).rkf5 .plot(y-sin(x*x),y);
or more concisely by
#> for.n(3,10) { ode.x[101](0,10) ( y' = 2*x*cos(x*x), y = 0 ) .case(n).plot(y-sin(x*x), y); }
and the results are all together drawn in Figure 3.
2nd-order Modified-Euler 2nd-order Ralston
3rd-order Runge-Kutta 4th-order Runge
8
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
4th-order Kutta 4th-order Runge-Kutta-Gill
4th-order Runge-Kutta-Fehlberg 5th-order Runge-Kutta-Fehlberg
Figure 3 Performance comparison between several methods
The error distribution y−sin x2 is denoted by a red line near y=0. It is obvious that higher-order methods are more accurate than basic 2nd-order methods.
Section 6-3 Multi-Points Integration Methods
Multi-points integration methods are based on integration of fitting polynomial obtained from the previous solution. This means that they need to be triggered by proper self-starting methods over a small time steps.
■ Adams-Bashforth Method. We consider Adams-Bashforth method (briefly AB method) up to sixth-order.
For the same benchmark problem discussed earlier, we repeat the same procedure to test performance by
#> for.n(2,6) { ode.x[101](0,10) ( y' = 2*x*cos(x*x), y = 0 ) .ab(n).plot(y,y-sin(x*x)); }
Figure 4 shows a typical result. Apparently, multi-point integration methods
9
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
work poorly for highly-oscillating fields.
Figure 4 Typical performance of multi-points methods
■ Adams-Molton Method. The Adams-Molton methods are also well-known in the literature and can be tested by the following
#> for.n(2,6) { ode.x[101](0,10) ( y' = 2*x*cos(x*x), y = 0 ) .am(n).plot(y,y-sin(x*x)); }
It can be seen that the performance is similar to the above Adams-Bashforth method.
■ Other Multi-Points Methods. Other methods can be tested similarly by
#> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ) .apc .plot(y,y-sin(x*x)); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ) .mpc .plot(y,y-sin(x*x)); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ) .hpc .plot(y,y-sin(x*x)); #> ode.x(0,10) ( y' = 2*x*cos(x*x), y = 0 ) .mopup .plot(y,y-sin(x*x));
or more concisely by
#> for.n(31,34) { ode.x[101](0,10) ( y' = 2*x*cos(x*x), y = 0 ) .case(n) .plot(y,y-sin(x*x)); }
The results are omitted since the multi-points methods show similar behavior
10
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
for highly-oscillating solution.
Section 6-4 Application Examples
For single IVPs, Umbrella ‘ode’ is capable of solving up to fourth-order IVPs. With minor modification internally, we can upgrade very easily the maximum degree. But it is considered that fourth-order is more than sufficient. The major concern rather lies in the accuracy and stability for steep IVPs. These points will be addressed later.
■ 1st-order IVP. A severely varying IVP is selected
y '=exp ( x ) y , y (0 )=exp(1)
The exact solution is given by yex=exp (exp ( x ) ) which reveals a severe variation for an interval of 0≤ x≤5, since
exp (exp (0 ) )=2.718…,exp (exp (5 ) )≅ 2.8511×1064
The numerical solution by
#> ode.x[51](0,5) ( y' = exp(x)*y, y = exp(1) ).return( x,y, exp(exp(x)), y/exp(exp(x)) );
ans = [ 0 2.7183 2.7183 1 ] [ 0.1 3.0197 3.0197 1 ] [ 0.2 3.3919 3.3919 1 ] …
[ 4.8 5.9058e+052 5.9061e+052 0.99994 ] [ 4.9 2.0955e+058 2.0956e+058 0.99993 ] [ 5 2.8509e+064 2.8511e+064 0.99991 ]
results in y (5 )≅ 2.8509×1064. Agreement with yex (5 )≅ 2.8511×1064 is of
course satisfactory considering a huge degree of variation.
■ 2nd-order IVP. A famous Van der Pol equation (only for non-stiff case
11
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
in this version) with
y ''=μ (1− y2 ) y '− yis considered with ICs
y (0 )=2 , y ' ( 0 )=0
over an interval of 0≤ t ≤20. For the case of μ=1, it can be easily understood that the following Cemmath commands
#> mu=1; #> ode .t(0,20) ( y'' = mu*(1-y*y)*y' - y, y=2, y'=0 )
.plot( y,y' ).return(t,y,y');
yield the interesting curves shown in Figure 5.
Figure 5 Var der Pol equation μ=1
■ 3rd-order IVP. The Pohlhausen equation famous in fluid dynamics is written as
y '''+1−( y ' )2=0 , y (0 )= y ' (0 )=0 , y '' (0 )=2 /√3
The exact solution is known to be
yex=x+2√3−3√2 tanh [ x / √2+tanh−1 (2 /3 )1 / 2]
12
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
We solve this problem by
#> double Pohl(x) = x+2*sqrt(3) - 3*sqrt(2)*tanh( x/sqrt(2)+atanh(sqrt(2/3)) );
#> ode.x(0,8) ( y''' = y'*y'-1, y''=2/sqrt(3), y=0, y'=0 ) .plot( y',y'', -y + Pohl(x) ) .return( -y + Pohl(x) ).tr;
For the Pohlhausen equation, the fields of major interest are y ' , y '' (dimensionless velocity and shear) rather than y itself. Therefore, we draw three curves y ' , y '' and the error distribution – y+ yex in Figure 6. Obviously, the numerical results agree well with the known exact solution.
Figure 6 Pohlhausen equation
■ Singular Starting Point. Although a certain mathematical expression allows a finite value by limit process, direct calculation may fail to evaluate a function value. Under these circumstances, solution methods for IVPs may fail. This can be treated by splitting the point from the interval.
An example IVP with singular starting point is written as
y '= sin xx
y , y (0 )=1
This can be solved by
13
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
#> ode .x(0,30) ( y' = (x == 0 ? 1 : sin(x)/x*y), y=1 ) .plot(y);
which prevents from evaluating function at x=0. The result is shown in Figure 7. Note that the default use of ‘.plot’ is the same as ‘.plot(y)’.
Figure 7 IVP with singular starting point
Section 6-5 System of IVPs
■ System of IVPs. For coupled IVPs, the syntax of ‘ode’ reads
ode .t[n=101,g=1](a,b) ( << opt >>, DE, ICs, DE, ICs, … ) .Spoke .Spoke..
or
ode .t[n=101,g=1](a,b) ( << opt >>, DE, DE, … ICs, ICs, … )
.Spoke ...
This implies that there is no significant difference in writing ICs, as long as they are written after their master DEs.
(Example 6-5-1) Consider the following coupled IVPs
u ''+v '+18u=563
cos x+18ex , u (0 )=3 ,u ' (0 )=4
14
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
v ''+4v+5u '=−10 sin 2 x , v (0 )=2 , v ' (0 )=−403
The exact solutions are given by
uex=cos x+cos (2 x )+sin (3 x )+ex
vex=53
sin x−7 sin (2 x )+3 cos (3 x )−ex
Therefore, we write
#> ode.x[21](0,1) ( u'' = -v'-18*u + 56/3*cos(x)+18*exp(x), u=3, u'=4, v'' = -4*v-5*u' - 10*sin(2*x), v=2, v'=-40/3
).plot( u,v, u',v',
-u + ( cos(x)+cos(2*x)+sin(3*x)+exp(x) ), -v + ( 5/3*sin(x)-7*sin(2*x)+3*cos(3*x)-exp(x) ) )
.return( u,u',v,v' );
and show the results in Figure 8.
Figure 8 System of IVPs
Also due to the use of Spoke ‘return’, the final results produce the matrix
15
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
[ u, u', v, v' ]
such that
ans = [ 3 4 2 -13.333 ] [ 3.1945 3.7679 1.2995 -14.662 ] [ 3.3758 3.474 0.53654 -15.827 ] …
[ 3.2814 -2.9836 -10.683 -2.0892 ] [ 3.1316 -2.9937 -10.727 0.32253 ] [ 2.9836 -2.9118 -10.651 2.7382 ]
■ Elimination-Accompanying IVPs. Some IVPs can be algebraically eliminated to result in simpler IVPs. For example, let a,b,c,d,f,g are all functions of t,x and y. The following IVP systems
{ax '+by '=fcx '+dy '=g or {ax ''+by ''=f
cx ''+dy ''=g
need an elimination procedure. Elimination is carried out inside << opt >>.
(Example 6-5-2) IVPs of interest are3 x '−2 y '=−4 x+6 y+18−6 t−4 x'+3 y '=5 x−7 y−24+9t
x=39 , x=3(e¿¿2 t+8 e−t)−6 t+12¿y=12 , y=3 (e2 t+2e−t )−3 t+3
and the Cemmath commands are
eps = 0.1;;ode .t(0,1) (<<
a = 3, b = -2, // can be pre-defined before odec = -4, d = 3,f = -4*x + 6*y + 18 – 6*t,g = 5*x – 7*y – 24 + 9*t,den = 1/(a*d-b*c)
>>,x' = (d*f-b*g)*den,
16
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
y' = (-c*f + a*g)*den, x = 39, y = 12)
.plot( x,y, 3*(exp(2*t)+8*exp(-t))-6*t+12+eps,
3*(exp(2*t)+2*exp(-t))-3*t+3+eps );
Figure 9 Elimination-Accompanying IVPs
(Example 6-5-3) IVPs of interest are3 x ' '−2 y ' '=−2x '+ y '+ x−6 y−t 2+10t+5−4 x' '+3 y ' '=3 x '−5 y '−x+2 y+t 2−8 t−3
x=1 , x'=−1, x=exp (−t )+t 2
y=1 , y '=−1 , y=exp (−2 t )+t
and the Cemmath commands are
eps = 0.002;;A = [ 3,-2; -4,3 ]; ode .t(0,1) (<<
f = -2*x' + y' + x – 6*y – t^2 + 10*t + 5, // for 2nd-orderg = 3*x' – 5*y' – x + 2*y + t^2 – 8*t – 3, // x', y' are hereB = A \ [ f ; g ]
>>,x'' = B(1),y'' = B(2), x = 1, y = 1, x' = -1, y' = -1
).plot( x,y, exp(-t) + t^2 + eps, exp(-2*t) + t + eps );
17
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
Figure 10 Elimination and Matrix-Applied IVPs
(Example 6-5-4) Given the following system of coupled ODEsϕ̇+sinθ ψ̇=30 cos 45ο
cos ϕθ̇−sinϕ cosθ ψ̇=0sinϕ θ̇+cos ϕcosθ ψ̇=30sin 45ο
θ=ϕ=ψ=0Find numerical solutions for 0≤ t ≤2.
cemm# utilizes an option field (enclosed by a pair of << >>) in solving this problem, since it is written as
[ 0 1 sinθcosϕ 0 −sin ϕcos θsin ϕ 0 cos ϕ cos θ ] [ θ̇ϕ̇ψ̇ ]=[30 cos 45ο
030 sin 45ο ]
#> b = [ 30*cosd(45); 0; 30*sind(45) ];;#> ode.t[5000](0,2) ( << A = [ 0, 1, sin(theta) ; cos(phi), 0, -sin(phi)*cos(theta); sin(phi), 0, cos(phi)*cos(theta) ] , B = A \ b >>, theta' = B(1), theta = 0, phi' = B(2), phi = 0, psi' = B(3), psi = 0 ).plot(theta,phi,psi);
18
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
User-defined solver can be also utilized as follows.
matrix fun6(double x, matrix y) { A = [ 0, 1, sin(y(1)) ; cos(y(2)), 0, -sin(y(2))*cos(y(1)); sin(y(2)), 0, cos(y(2))*cos(y(1)) ]; B = A \ [ 30*cosd(45);0;30*sind(45) ]; return B.tr;}
#> ysol = user_ode( 0,2, 0.002, [ 0,0,0 ], fun6 );; #> ysol. plot;
Section 6-6 Phase Diagram
The phase diagram of a certain IVP represents a family of solutions obtained by changing its ICs. In this section, we explain how to present a phase diagram and a few particular solutions relevant to IVPs.
■ Particular Solutions and Phase Diagram. Consider a 1st-order IVP written as
y '=e− x / 10 sin ( x ) y , y=a
where a is a parameter. By changing the value of a, we get a family of solutions to the given IVP. For example,
#> .hold;#> for(a = 0; a <= 2; a += 0.1) ode .x(0,10) ( y' = y*exp(-0.1*x)*sin(x), y = a ).plot+(y); #> plot;
yields a family of curves shown in Figure 11.
19
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
Figure 11 A family of solutions to 1st-order IVP
Those particular solutions shown in Figure 11 can be further generalized to a phase diagram, since the tangent lines to the solution of y '=e− x / 10 sin ( x ) y are represented by a series of vectors (1 , y '). Therefore, we draw a phase diagram (discussed in Chapter 2), and add two particular solutions
#> .hold; ode .x(0,10) ( y' = y*exp(-0.1*x)*sin(x), y = 1 ).plot(y); ode .x(0,10) ( y' = y*exp(-0.1*x)*sin(x), y = 0.5 ).plot+(y); plot .x[21](0,10).y[21](0,6) ( 1, y*exp(-0.1*x)*sin(x) ).phase[0.2,3]; #> plot;
From the phase diagram in Figure 12, it is readily understood what would look like other particular solutions.
20
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
Figure 12 Phase diagram for 1st-order IVP
■ Parameterized Plot. When the independent variable plays a role of parameter in plotting the result, either ‘plot@’ or ‘plot+@’ can be utilized to fulfill this purpose. We remember that the character ‘@’ has been used to denote parameterized plot, as was in plot .@t(0,pi) ( cos(t),sin(t),t ).
To illustrate this point, let us consider a 2nd-order IVP associated with the pendulum motion (see ref [1])
d2 xd t 2 +sin x=0 , x (0 )=a , x' (0 )=b
where a and b are parameters. This is solved by the following Cemmath commands in two different ways, using Spokes ‘plot’ and ‘plot@’.
#> t = (0,10).span(101);; #> ode[t] ( x'' = -sin(x), x = 1, x' = 1 ) .plot(x,x'); #> ode[t] ( x'' = -sin(x), x = 1, x' = 1 ) .plot@(x,x');
For an interval of 0≤ t ≤10, it is possible to draw the results in two different ways, as shown in Figure 13. The left of Figure 13 is a typical presentation of results for x and x' in terms of the independent variable t. However, the right of Figure 13 utilizes Spoke ‘plot@’ and adopts the horizontal and vertical axes to be x and x', respectively.
Figure 13 Typical and parameterized plots
21
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
Since the given IVP for the pendulum motion can be rewritten as
x '= yy '=−sin x
a number of particular solutions can be also superposed by a relevant phase diagram by the following commands
#> t = (0,10).span(101);; #> .hold; ode[t] ( x'' = -sin(x), x = 1, x' = 1 ).plot@(x,x'); ode[t] ( x'' = -sin(x), x = 2, x' = -1 ).plot@(x,x'); ode[t] ( x'' = -sin(x), x = 5, x' = -2 ).plot@(x,x'); ode[t] ( x'' = -sin(x), x =-5, x' = 2 ).plot@(x,x'); plot.x[21](-5,5).y[21](-5,5) ( y, -sin(x) ).phase[0.2, 4]; #> plot;
A phase diagram with four particular solutions are shown in Figure 14.
Figure 14 Phase diagram with particular solutions
By using Spokes ‘xran/xrange’ and ‘yran/yrange’, the bounds of Figure 14 can be adjusted to meet users’ preference.
■ Rossler System. Another example also taken from ref [1] describes the Rossler system
22
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
x '=− y−zy '=x+ay
z '=b+z (x−c)
where a ,b and c are parameters. The Rossler system is solved with (a ,b , c )=(0.2,0 .2,5) and the initial condition ( x , y , z )=(1,1,1) over an interval of 0≤ t ≤100 by the following Cemmath commands
#> (a,b,c) = (0.2,0.2,5); #> t = (0,100).span(1001);;#> ode[t] ( x' = -y-z,
y' = x+a*y, z' = b+z*(x-c), x=1, y=1, z=1
).plot@(x,y);
The result of (x , y )-plot is shown in Figure 15.
Figure 15 Parameterized plots
It is also possible to draw (x , y , z) plot in 3D space
#> t = (0,100).span(1001);; #> (a,b,c) = (0.2, 0.2, 5); #> ode[t] (
23
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
x' = -y-z, x = 1, y' = x+a*y, y = 1, z' = b+z*(x-c), z = 1 ).plot@(x+1,y+1,z+1);
#> (a,b,c) = (0.2, 0.2, 2.5); #> ode[t] ( x' = -y-z, x = 1, y' = x+a*y, y = 1, z' = b+z*(x-c), z = 1 ).plot+ @(x+20,y,z);
where two cases of (a ,b , c )=(0.2,0 .2,5) and (a ,b , c )=(0.2,0 .2,2.5) are considered. The results are shown in Figure 16.
Figure 16 Three-dimensional parameterized plots
To those readers familiar with functions, repeating the same expressions looks tedious. This is absolutely true. Later, we will discuss functions which make repeated tasks much easier. For example, the results in Figure 16 can be obtained by
#> void Rossler(a,b,c,xo) { ode.t[1001](0,100) ( x' = -y-z, x = 1, y' = x+a*y, y = 1, z' = b+z*(x-c), z = 1 ).plot@(x+xo,y,z); }
24
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
#> .hold; Rossler(0.2,0.2,5.0, 0.); Rossler(0.2,0.2,2.5, 20.); #> plot;
where a function called Rossler is introduced for easier handling.
■ Lorentz System. Let us consider the famous Lorentz equation. We believe that readers can identify the IVP system directly from the following Cemmath commands
#> ode.t[5001](0,50) ( x' = 10*(y-x), y' = 28*x-y-x*z, z' = x*y-8/3*z,
x = 0, y = 1, z = 0 ).plot@(x,z);
And the phase diagram ( x , z ) is shown in Figure 17.
Figure 17 Phase diagram of Lorentz equation
■ Rigid-Body Motion. Another example from ref [1] is for rigid-body motion.
#> ode.t(0,12) ( x' = y*z,
25
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
y' = -x*z, z' = -0.51*x*y, x = 0, y = 1, z = 1
) .plot(x,y,z) .return(t,x,y,z); // plot@ for 3D instead of plot
The results for 2D and 3D plots are shown in Figure 18.
Figure 18 Rigid body motion (non-stiff case)
Section 6-7 IVPs with Terminating Conditions
The motion of a ball thrown into the air normally terminates when it hits the ground of a designated level. In this section, we discuss Spoke ‘stopif’ that handles the terminating condition of IVPs.
■ Spoke ‘stopif’ and ‘update’. Spoke ‘stopif’ is an option that terminates solving procedure of IVP if the condition inside a parenthesis is true. Spoke ‘update’ is an option that writes down all the information at the current step before moving to the next step. Using this Spoke, it is possible to find out the time increment dt.
■ Motion of a Ball. The equation of a motion for a ball thrown into the air is described as
y ''=−9.8 , y (t 0 )= y0 , y ' (t 0 )=v0
where t 0 is the starting time, y0 is the initial height, and v0 is the initial speed of the ball. Our scenario for ball motion is as follows (all the units will be
26
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
omitted). At time t 0=0, the ball is thrown upward with v0=20. After reaching its maximum height, the ball is made to hit the plane elevated at yhit=5 and stops.
Under this situation, the time at which the ball motion stops is a part of solution, and thus our method of integrating IVP must accompany a certain terminating condition. For this purpose, we employ Spoke ‘stopif’ which specifies the conditional expression. Therefore, we solve the given problem by
#> (yo, vo) = (0,20); #> ode .t(0,30) ( y'' = -9.8, y = yo, y' = vo ) .stopif( y' < 0 && y <= 5 ) .plot(y,5) .return(t,y,y');
Integration is terminated when the conditional expression turns out to be true. In this case, the motion is downward (y' < 0) and the height is equal to or less than 5 ( y <= 5). Spokes ‘plot’ and ‘return’ provide the results in plot and matrix, as before. Figure 19 shows the motion of a ball until it hits the elevation level of yhit=5
Figure 19 Motion of a ball
Furthermore, Spoke ‘return’ provides the resulting matrix
ans = [ 0 0 20 ] [ 0.3 5.559 17.06 ]
27
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
[ 0.6 10.236 14.12 ] …
[ 3.3 12.639 -12.34 ] [ 3.6 8.496 -15.28 ] [ 3.8141 5 -17.378 ]
Note that the termination time is t end=3.8141 which agrees well with the exact value t ex=3.8141 obtained from
−9.82
t 2+20 t=5
Meanwhile, the maximum height attained can be found by
#> (yo, vo) = (0,20);; #> ode .t(0,30) ( y'' = -9.8, y = yo, y' = vo ) .stopif( y' < 0 ) .update( ymax = y );#> ymax ;ymax = 20.408163
■ Bouncing Motion of a Ball. When a table tennis ball is thrown into the air, it will undergo a number of bounding motions. Let us suppose that the speed is reduced 90% after each bouncing. Also, the bouncing motion occurs between the ceiling at y=10 and the floor at y=0. Therefore, there can be both upward and downward terminating conditions. We can solve this problem by the following commands
#> to = 0;; #> (yo,vo) = (0, 20);; #> ntouch = 0;; #> .hold;#> plot.circle(0.1).thick(9);; // ball
#> while( ++ntouch <= 10 ) { ode .t(to,to+10) ( y'' = -9.8, y = yo, y' = vo )
.stopif( (y' < 0 && y <= 0) || (y' > 0 && y >= 10) )
.update( to = t, yo = y, vo = -0.9*y' ) .plot(y); } #> plot;
28
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
The results are shown in Figure 20.
Figure 20 Bouncing motion of a ball between ceiling and floor
■ Fox and rabbit. Without specification of mathematical expressions, we directly solve this problem by
#> double u(t) = sqrt(1+t)*cos(t); #> double v(t) = sqrt(1+t)*sin(t); #> eps = 1.e-6;#> del = 100; // assume initial distance far away#> ntau = 1001; // accurate-sensitive, thus many steps#> ode.t[ntau](0,6) ( << rx = u(t), // rabbit's x-coordinate ry = v(t), // rabbit's y-coordinate d = .max(eps, .norm2(rx-x,ry-y) ), // distance s = (1.1/2)* .norm2( rx/(1+t)-2*ry, ry/(1+t)+2*rx )>>, x' = s/d * (rx-x), y' = s/d * (ry-y), x = 3, y = 0 // fox's initial position) .stopif( d > del ) // d' > 0 condition is realized .update( del = d, tau = t, xtau = x, ytau = y ) // make a new distance .plot@(x,y);
#> plot+ .@t(0,tau) ( u(t),v(t) );#> plot+ .circle(0.1).xmove(3); // fox#> plot+ .circle(0.1).xmove(1); // rabbit#> tau; del; xtau; ytau;
tau = 5.06475
29
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
del = 0.0014870192xtau = 0.8485762ytau = -2.3118532
Figure 21 Fox and rabbit problem
In ref. [1], solutions are tau = 5.0710 at (0.8646,-2.3073). More accurate solutions with time step ntau = 10001 can be obtained by Cemmath to be
tau = 5.0709 at (0.864541,-2.30726) del = 0.000154151
The reason of accuracy sensitivity can be understood from the result plot. The point of catching can be ambiguous depending on the criterion of catching.
■ Motion of a Projectile. The motion of a projectile discussed in ref. [1] is adopted to illustrate multiple terminating conditions. The object is to hit a desired position with a prescribed inclination of initial velocity. The drag by air impacts the motion of a projectile. Without specification of mathematical expressions of IVP, we directly solve this problem by
#> g = 32.2; ang = pi/4; cdrag = 0.002; vo = 600;
#> ode.t[201](0,30) ( x'' = - cdrag * .norm2(x',y') * x', y'' = -g - cdrag * .norm2(x',y') * y', x = 0, x' = vo*cos(ang), y = 0, y' = vo*sin(ang) )
30
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
.stopif( x' < 0.01 || y < -200 || (y' < 0 && x >= 1000) ) .plot@(x,y) .return(t,x,y,x',y');
from which the original IVP can be easily re-constructed. Note that three terminating conditions are described. The desired horizontal distance is x=1000. But the horizontal speed should not vanish in order to reach the desired position. Also, the target is at least above a certain elevation. With multiple conditions of termination, we obtain the numerical result shown in Figure 22. Readers are recommended to compare Figure 22 and the corresponding result in ref. [1].
Figure 22 Motion of a trajectory
Section 6-8 Fully Implicit IVPs
In this section, we discuss Umbrella ‘ode#’ which can handle fully-implicit IVPs of 1st-order. At present, only a single IVP can be solved by Umbrella ‘ode#’. The corresponding syntax is
ode# .t[n=101,g=1](a,b) ( DE, ICs ) .Spoke.Spoke..
In the above, the character ‘#’ is introduced due to an image that something is hidden inside the four lines, i.e. implicit image.
■ 1st-order fully-implicit IVP. An example of fully-implicit IVP of 1st-order is the Weissinger’s equation adopted from ref [1]
31
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
t y2 ( y ' )3− y3 ( y ' )2+t ( t2+1 ) ( y ' )−t 2 y=0 , y (1 )=√3 / 2
where the exact solution is y=( t2+1 / 2 )1 / 2. Note that the IC is given only for
the function value. This implies that one should find the first derivative y '(0) from the given IVP by trial-and-error. Therefore, it is necessary to guess properly y '(0). For this purpose, we use Spoke ‘guess’ to initiate the trial-and-error solution of y '(0) (the default value of guess is 0). In this regard, the Cemmath commands are
#> ode# .t(1,10) ( t*y*y*(y')^3 - y^3*(y')^2+t*(t*t+1)*(y')-t*t*y = 0, y = sqrt(3/2) ) .guess(1) .plot( y, sqrt(t*t+0.5) ) .return( t,y, -y+sqrt(t*t+0.5) );
and the results are shown in Figure 23.
Figure 23 Fully-implicit IVP (Weissinger equation)
Also, Spoke ‘return’ yields the solution field [ t,y,y', -y+sqrt(t*t+0.5) ]
ans = [ 1 1.2247 0.8165 0 ] [ 1.09 1.3004 0.84024 -0.0010974 ] [ 1.18 1.3778 0.86006 -0.0021264 ] …
32
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
[ 9.82 9.9032 1.0033 -0.057822 ] [ 9.91 9.9936 1.0034 -0.058357 ] [ 10 10.084 1.0034 -0.058892 ]
From the above, it is found that y ' (0 )=0.8165 (nearly the same as √2 / 3).
Section 6-9 Steep IVPs
A well-known Van der Pol equation
y ''=μ (1− y2 ) y '− y , y ( 0 )=2 , y ' (0 )=0is selected here to be a benchmark problem for stiff ODE. Find numerical solutions for μ=1,10,100, respectively.
A user function 'adaptive_ode' listed below is employed to handle stiff odes.
#> matrix VanderPol1(double x, matrix y) = [ y(2), 1*(1-y(1)^2)*y(2)-y(1) ];#> ysol = adaptive_ode(0,20, 0.2, [ 2,0 ], VanderPol1, 0.01);; #> ysol.len; ans = 127
#> ysol.endrow; ans = [ 20 2.00809 -0.0469113 0.000154643 ]
#> plot( ysol.col(1), ysol.col(2));
#> matrix VanderPol2(double x, matrix y) = [ y(2), 10*(1-y(1)^2)*y(2)-y(1) ];#> yans = adaptive_ode(0,60, 2, [ 2,0 ], VanderPol2, 0.01);; #> yans.len; ans = 681#> yans.endrow; ans = [ 60 1.801 -0.079977 2.29483e-006 ]#> plot( yans.col(1), yans.col(2));
33
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
Figure 11b Van der Pol equation with μ=10
#> matrix vanderpol3(double t, matrix y) = [ y(2), 100*(1-y(1)^2)*y(2)-y(1) ];#> ysol = adaptive_ode(0,300, 2, [ 2,0 ], vanderpol3, 0.01 );; #> ysol.len; // number of time steps ans = 15053#> ysol.endrow; ans = [ 300 -1.53485 0.0111001 0.000871423 ]#> yfig = ysol.skiprow(100);; plot( yfig.col(1), yfig.col(2));
Figure 11c Van der Pol equation with μ=100
// prototypematrix user_ode(double t,tf,h, matrix y,fun(double t,matrix y));matrix adaptive_ode(double t,tf,h, matrix y,fun(double t,matrix y), double tol);
//--------------------------------------------------------------------------// sample run//--------------------------------------------------------------------------%> "simple example of ODE";#> matrix fun1(double t, matrix y) = [ -y(1)-5*exp(-t)*sin(5*t) ];
#> ysol = user_ode( 0,3, 0.03, [ 1 ], fun1 );; #> ysol.plot;
34
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
//--------------------------------------------------------------------------// sample run for Van der Pol equation//--------------------------------------------------------------------------%> "stiff ODE with Van der Pol equation";#> matrix vanderpol40(double t, matrix y) = [ y(2), 40*(1-y(1)^2)*y(2)-y(1) ];#> ysol = adaptive_ode(0,200, 2, [ 2,0 ], vanderpol40, 0.01 );; #> ysol.len; // number of time steps// ans = 4423
#> ysol.endrow;// ans = [ 200 1.99166 -0.0167814 2.11069e-009 ]
#> plot( ysol.col(1), ysol.col(2));
//==========================================================================// user_odecoef:://==========================================================================double user_odecoef(double icase, matrix &A,&B,&C) { switch( icase ) { case 1: // Euler = 1st RK A = [1]; B = [0]; C = [ 0 ]; break;
case 2: // (modified Euler) predictor-corrector = 2nd RK A = [1,1]/2; B = [0,1]; C = [ 0; 1,0 ]; break;
35
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
case 3: // polygon = 2nd RK A = [0,1]; B = [0,1]/2; C = [ 0; 0.5,0 ]; break;
case 4: // Ralston = 2nd RK A = [1,2]/3; B = [0,3]/4; C = [ 0; 0.75,0 ]; break;
case 5: // 3rd RK A = [1,4,1]/6; B = [0,1,2]/2; C = [ 0; 0.5; -1,2,0 ]; break;
case 6: // Runge = 4th RK A = [1,2,2,1]/6; B = [0,1,1,2]/2; C = [ 0; 0.5; 0,0.5; 0,0,1,0 ]; break;
case 7: // Kutta = 4th RK A = [1,3,3,1]/8; B = [0,1,2,3]/3; C = [ 0; 1/3; -1/3,1; 1,-1,1,0 ]; break;
case 8: // Gill = 4th RK s = 1/sqrt(2); A = [0.5,1-s,1+s,0.5]/3; B = [0,1,1,2]/2; C = [ 0; 0.5; -0.5+s, 1-s; 0, -s, 1+s, 0 ]; break;
case 9: // Fehlberg = 4th RK A = [ 25/216, 0, 1408/2565, 2197/4104, -0.2 ]; B = [ 0, 0.25, 3/8, 12/13, 1 ]; C = [ 0; 0.25; 3/32, 9/32; // 3rd 1932/2197, -7200/2197, 7296/2197; // 4th 439/216, -8, 3680/513, -845/4104, 0 ]; // 5th break;
case 10: // Fehlberg = 5th RK A = [ 16/135, 0, 6656/12825, 28561/56430, -9/50, 2/55 ]; B = [ 0, 0.25, 3/8, 12/13, 1, 0.5 ]; C = [ 0; 0.25; 3/32, 9/32; // 3rd 1932/2197, -7200/2197, 7296/2197; // 4th 439/216, -8, 3680/513, -845/4104; // 5th -8/27, 2, -3544/2565, 1859/4104, -11/40,0 ]; // 6th }
36
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
return A.len; // A.len = A.length = A.longer}
//==========================================================================// user_odeRK:://==========================================================================void user_odeRK( double to,h, matrix &y,&yo, &A,&B,&C,&K, // ampersand & means 'refer' not 'copy' matrix fun(double t, matrix y)) {// to : previous time at whicvh solutions are known// h : magnitude of time step, h = t-to // yo : solution at previous time step// y : dependent variables for coupled ODEs, y(1),y(2), ... , y(numeq)// A,B,C : coefficients for integration scheme// K : generalized slopes for integration scheme
K.row(1) = fun(to,yo); // B(1) = C.row(1) = 0 for.i(2,A.len) { t = to + B(i)*h; y = yo + h*( C.row(i) * K ); K.row(i) = fun(t,y); } y = yo + h*( A * K );}
//==========================================================================// user_ode:: for positive h//==========================================================================matrix user_ode(double t,tf,h, matrix y,fun(double t,matrix y)){// t : initial time// tf : final time// h : size of time step// y : initial conditions, [ y(1), y(2), ... , y(n) ]// fun : ODE in matrix form, [ y'(1)=f1, y'(2)=f2, ... , y'(n)=fn ]
icase = 9; // Fehlberg 4th, change this manually sdim = user_odecoef(icase, A,B,C); K = .zeros(sdim,y.len);
yo = fun(t,y); if( yo.len != y.len ) "ode function is not valid in dimenension";
37
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
num = 0; ysol = [ t, y ]; while(1) { yo = y; if( t+h >= tf ) h = tf-t ; // stay exact at the final time user_odeRK(t,h, y,yo, A,B,C,K, fun); t += h; ysol _= [ t, y ]; // stack newly-obtained solutions if( t >= tf || t.-.tf < 1.e-6 || ++num > 10000 ) break; } return ysol;}
//==========================================================================// adaptive_ode:: for positive h//==========================================================================matrix adaptive_ode(double t,tf,h, matrix y,fun(double t,matrix y), double tol){// t : initial time// tf : final time// h : size of time step// y : initial conditions, [ y(1), y(2), ... , y(n) ]// fun : ODE in matrix form, [ y'(1)=f1, y'(2)=f2, ... , y'(n)=fn ]
s = user_odecoef( 9, A5,B5,C5); K5 = .zeros(s,y.len); // Fehlberg 4th s = user_odecoef(10, A6,B6,C6); K6 = .zeros(s,y.len); // Fehlberg 5th E6 = [ 1/360, -128/4275, -2197/75240, 0, 1/50, 2/55 ];
yo = fun(t,y); if( yo.len != y.len ) "ode function is not valid in dimenension"; num = 0; ysol = [ t, y, 0 ]; while(1) { yo = y; if( t+h > tf ) h = tf-t ; // stay exact at the final time
do { user_odeRK(t,h, y,yo, A6,B6,C6,K6, fun); yerr = h * |(E6*K6).maxentry|; // error estimation if( yerr > tol) h *= 0.1; // reduce h where stiff } while( yerr > tol ); // y = yo + h*(A5 * K6..(1:5)()); // if prefered Fehlberg 4th
t += h; ysol _= [ t, y, yerr ]; // stack newly-obtained solutions
38
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
if( yerr < tol ) h *= 1.25; // increase h where plain if( t >= tf || t.-.tf < 1.e-6 || ++num > 100000 ) break; if( .mod(num,1000) == 0 ) "adaptive_ode is running" ;; } return ysol;}
Section 6-10 Summary
ode .t[n=101,g=1](a,b) ( << opt >>, DE, ICs, DE, ICs, … ) .Spoke.Spoke..
or
ode .t[n=101,g=1](a,b) ( << opt >>, DE, DE, … ICs, ICs, … ) .Spoke.Spoke..
t=(a,b).span(n,g=1); ode [t] ( << opt >>, DE, DE, … ICs, ICs, … ) .Spoke...
.plot(functions of t,y,y',…)
.return(functions of t,y,y',…) extract solution and its derivatives
.togo ( X=x, … ) extract the specified field
.euler // .case(1) 1st-order Euler Method
.euler2 // .case(2) 2nd-order modified Euler method
.pc2 // .case(3) 2nd-order predictor-corrector
.rs2 // .case(4) 2nd-order Ralston method
.rk3 // .case(5) 3rd-order Runge-Kutta method
.r4 // .case(6) one of 4th-order Runge-Kutta methods
.k4 // .case(7) one of 4th-order Runge-Kutta methods
.rkg4 // .case(8) 4th-order Runge-Kutta-Gill method
.rkf4 // .case(9) 4th-order Runge-Kutta-Fehlberg method
.rkf5 // .case(10) 5th-order Runge-Kutta-Fehlberg method
.ab(n) // .case(11~16) nth-order Adams-Bashforth method
.am(n) // .case(21~26) nth-order Adams-Molton method
.apc // .case(31) Adams-predictor-corrector method
.mpc // .case(32) Milne-predictor-corrector method
.hpc // .case(33) Hamming-predictor-corrector method
.mopup // .case(34) Adams-Molton with mop-up method
.stopif( condition) // terminate current step if condition is true
.update(expr,expr,…) // update after each step of integration
39
[100] 006 Chapter 6 Initial Value Problems, Tutorial by www.msharpmath.com
Section 6-11 References
[1] R.E. Larson, R.P. Hostetler, B.H. Edwards, Calculus with Analytic Geometry, 6ed., Houghton Mifflin Co., (1998)
[2] H.B. Wilson, L.H. Turcotte, Advanced Mathematics and Mechanics Applications Using MATLAB, 2ed., CRC Press (1997).
[3] MATLAB(R) 7, Mathematics, The MathWorks Inc. (2009).
[4] D.J. Higham and N.J. Higham, MATLAB(R) Program GuideBook, 2ed., SIAM (2005).
40