Professional Documents
Culture Documents
January 2010 Problem description ------------------Consider the 2nd-order ODE: y" y y' 3 y sin x 1 y' 0 1
Variable substitution to form a system of ODEs: ---------------------------------------------This 2nd-order ODE can be converted into a system of two 1st-order ODEs by using the following variable substitution: u 1 y u 2 y'
y"
sin x
The system of equations [Eq. 1] and [Eq. 2] is transformed into the vector ODE: u 1 d dx u 2 2 3 u u
sin x
or,
d u f x , u , where u dx 2 3 u u
u u
1 2
and
f x, u
sin x
us
1 1
at
xs 0
-1-
f x, u
sin x 1 1
The initial conditions are: The end of the solution interval is: Use 100 intervals: Calculate the increment size, x: x eval xe xs n
xs xe n
0 20 100
us
The following "for" loop calculates the Runge-Kutta algorithm (version 1) to produce the solution: for k 1 .. n x0 eval xsol u0 xM K1 uM K2 uM K3 u1 x1 K4 u1
1 K1 2 K2 2 K3 K4 6 usol augment usol , u1 After completing the iterative process, the solution is stored in a row vector called "ysol". This vector can be transposed to put together the graph of the two solutions as illustrated here: usol usol T
-2-
M1 M2
3
-1 0 2 4 6 8 10 12 14 16 18 20
M1 M2 The blue line represents u[1]=y while the red line represents u[2] = dy/dx. Solution (version 2): --------------------First, define the vector function f(x,y): 2 3 u u
f x, u
sin x 1 1
The initial conditions are: The end of the solution interval is: Use 100 intervals: Calculate the increment size, x: x eval xe xs n
xs xe n
0 20 100
us
The following "for" loop calculates the Runge-Kutta algorithm (version 1) to produce the solution:
-3-
k 1 x 3 2 x 3
1 K1 3 K2 3 K3 K4 8 usol augment usol , u1 After completing the iterative process, the solution is stored in a row vector called "ysol". This vector can be transposed to put together the graph of the two solutions as illustrated here: usol usol N1 N2 y T
-1 -2 0 2 4 6 8 10 12 14 16 18 20
N1 N2 The blue line represents u[1]=y while the red line represents u[2] = dy/dx.
-4-