{VERSION 5 0 "IBM INTEL NT" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "Hyperlink" -1 17 "" 0 1 0 128 128 1 2 0 1 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 2" -1 4 1 {CSTYLE "" -1 -1 "Times " 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 2 1 0 1 0 2 2 0 1 } {PSTYLE "List Item" -1 14 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 3 3 1 0 1 0 2 2 14 5 }{PSTYLE "Normal" -1 256 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "List Subitem" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 3 3 3 12 1 0 2 2 270 5 }{PSTYLE "" 0 258 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 259 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 260 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 261 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 0 "" }}{PARA 256 "" 0 "" {TEXT -1 41 "ORDINARY DIFFERENTIAL EQUATIONS POWERTOOL" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 256 "" 0 "" {TEXT -1 29 "Unit 16 -- Runge-K utta Method" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 256 "" 0 "" {URLLINK 17 "Prof. Douglas B. Meade" 4 "http://www.math.sc.edu/~meade/ " "" }}{PARA 256 "" 0 "" {URLLINK 17 "Industrial Mathematics Institute " 4 "http://www.math.sc.edu/~IMI/" "" }}{PARA 256 "" 0 "" {URLLINK 17 "Department of Mathematics" 4 "http://www.math.sc.edu/" "" }}{PARA 256 "" 0 "" {URLLINK 17 "University of South Carolina" 4 "http://www.s c.edu/" "" }}{PARA 256 "" 0 "" {TEXT -1 19 "Columbia, SC 29208\n" }} {PARA 256 "" 0 "" {TEXT -1 7 "URL: " }{URLLINK 17 "http://www.math.s c.edu/~meade/" 4 "http://www.math.sc.edu/~meade/" "" }}{PARA 256 "" 0 "" {TEXT -1 25 "E-mail: meade@math.sc.edu" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 256 "" 0 "" {TEXT -1 57 "Copyright \251 2001 by Douglas B. MeadeAll rights reserved" }}{PARA 256 "" 0 "" {TEXT -1 0 "" }} {PARA 256 "" 0 "" {TEXT -1 67 "--------------------------------------- ----------------------------" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 18 "Outline of Unit 16" }}{EXCHG {PARA 14 "" 0 "" {HYPERLNK 17 "16.A" 1 "" "16.A" }{TEXT -1 46 " Explicit Implementation of Runge- Kutta Method" }}{PARA 257 "" 0 "" {HYPERLNK 17 "16.A-1" 1 "" "16.A-1" }{TEXT -1 10 " Example 1" }}{PARA 257 "" 0 "" {HYPERLNK 17 "16.A-2" 1 "" "16.A-2" }{TEXT -1 10 " Example 2" }}{PARA 14 "" 0 "" {HYPERLNK 17 "16.B" 1 "" "16.B" }{TEXT -1 1 " " }{HYPERLNK 17 "dsolve" 2 "dsolve" " " }{TEXT -1 23 " and Runge-Kutta Method" }}{PARA 257 "" 0 "" {HYPERLNK 17 "16.B-1" 1 "" "16.B-1" }{TEXT -1 22 " Example 1 (revisite d)" }}{PARA 257 "" 0 "" {HYPERLNK 17 "16.B-2" 1 "" "16.B-2" }{TEXT -1 22 " Example 2 (revisited)" }}{PARA 14 "" 0 "" {HYPERLNK 17 "16.C" 1 " " "16.C" }{TEXT -1 10 " Example 3" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 14 "Initializat ion" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "with( DEtools ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "with( plots ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 15 " with( linalg ):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {SECT 0 {PARA 3 "" 0 "16.A" {TEXT -1 50 "16.A Explicit Implementation \+ of Runge-Kutta Method" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 104 "The Eule r and Improved Euler Methods are members of the family of Runge-Kutta \+ methods for solving an IVP" }}{PARA 256 "" 0 "" {TEXT -1 1 " " } {XPPEDIT 18 0 "Diff( y, x ) = F(x,y(x))" "6#/-%%DiffG6$%\"yG%\"xG-%\"F G6$F(-F'6#F(" }{TEXT -1 6 ", " }{XPPEDIT 18 0 "y(x[0]) = y[0]" "6# /-%\"yG6#&%\"xG6#\"\"!&F%6#F*" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 73 "The method generally referred to as the s econd-order Runge-Kutta Method (" }{HYPERLNK 17 "RK2" 2 "dsolve,classi cal" "" }{TEXT -1 27 ") is defined by the formula" }}{PARA 258 "" 0 " " {TEXT -1 2 " " }{XPPEDIT 18 0 "x[n+2/3] = x[n] + 2/3* h" "6#/&%\"xG 6#,&%\"nG\"\"\"*&\"\"#F)\"\"$!\"\"F),&&F%6#F(F)*(F+F)F,F-%\"hGF)F)" } {TEXT -1 55 " " }}{PARA 259 "" 0 "" {TEXT -1 2 " " }{XPPEDIT 18 0 " y[n+2/3] = y[n] + 2/3" "6#/&%\"yG6#,&%\"nG\"\"\"*&\"\"#F)\"\"$!\"\"F),&&F%6#F(F)*&F+F)F ,F-F)" }{TEXT -1 1 " " }{XPPEDIT 18 0 "h" "6#%\"hG" }{TEXT -1 1 " " } {XPPEDIT 18 0 "F( x[n], y[n] )" "6#-%\"FG6$&%\"xG6#%\"nG&%\"yG6#F)" } {TEXT -1 39 " " }}{PARA 260 "" 0 "" {TEXT -1 2 " " }{XPPEDIT 18 0 "x[n+1] = x[n] + h" "6#/&%\"xG6#,& %\"nG\"\"\"F)F),&&F%6#F(F)%\"hGF)" }{TEXT -1 57 " \+ " }}{PARA 261 "" 0 "" {TEXT -1 2 " " }{XPPEDIT 18 0 "y[n+1] = y[n] + h/4" "6#/&%\"yG6#,&%\"nG\"\"\"F)F) ,&&F%6#F(F)*&%\"hGF)\"\"%!\"\"F)" }{TEXT -1 3 " ( " }{XPPEDIT 18 0 "F( x[n], y[n] ) + 3*F( x[n+2/3], y[n+2/3] )" "6#,&-%\"FG6$&%\"xG6#%\"nG& %\"yG6#F*\"\"\"*&\"\"$F.-F%6$&F(6#,&F*F.*&\"\"#F.F0!\"\"F.&F,6#,&F*F.* &F7F.F0F8F.F.F." }{TEXT -1 4 " ) " }}{PARA 0 "" 0 "" {TEXT -1 24 "whe re h is the stepsize." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 105 "A simple implementation of the second-order Runge-Kut ta Method that accepts the function F, initial time " }{XPPEDIT 18 0 " x[0]" "6#&%\"xG6#\"\"!" }{TEXT -1 19 ", initial position " }{XPPEDIT 18 0 "y[0]" "6#&%\"yG6#\"\"!" }{TEXT -1 11 ", stepsize " }{XPPEDIT 18 0 "h" "6#%\"hG" }{TEXT -1 22 ", and number of steps " }{XPPEDIT 18 0 " N" "6#%\"NG" }{TEXT -1 18 " as input would be" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "RungeKutta2s := pro c( F, x0, y0, h, N )" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 31 " local f, \+ i, L, X, X1, X2, Xt;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 27 " X := eval f( [ x0, y0 ] );" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 " L := X;" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 " for i from 1 to N do" }}{PARA 0 " > " 0 "" {MPLTEXT 1 0 18 " f := F(op(X));" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 29 " X1 := X + [ h, h*f ];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 29 " Xt := X + 2/3*[ h, h*f ];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " X2 := X + [ h, h*F(op(Xt)) ];" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 21 " X := (X1+3*X2)/4;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 " L := L, X;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 " \+ end do;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " return matrix( N+1, 2 , [ L ] );" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "end proc;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 53 "As a test, compute the Runge-Kutta Method solution to" }}{PARA 256 "" 0 "" {TEXT -1 1 " " }{XPPEDIT 18 0 "Diff( y, x ) = -2*y" "6#/-% %DiffG6$%\"yG%\"xG,$*&\"\"#\"\"\"F'F,!\"\"" }{TEXT -1 4 ", " } {XPPEDIT 18 0 "y(0)=1" "6#/-%\"yG6#\"\"!\"\"\"" }}{PARA 0 "" 0 "" {TEXT -1 30 "on the interval [ 0, 1 ] with " }{XPPEDIT 18 0 "h" "6#%\" hG" }{TEXT -1 5 "=0.1." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "RungeKutta2s( (x,y)->-2*y, 0, 1, 0. 1, 10 );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 244 "A more sophisticated implementation of t he Runge-Kutta method would accept as input the ODE, the initial condi tion, the interval on which the solution should be computed, and the n umber of steps. In this case, the implementation could appear as" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "RungeKutta2 := proc( ode, ic, domain, N )" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 43 " local f, h, i, t, y, F, L, X, X1, X2, Xt;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 19 " t := lhs(domain);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 21 " y := op(0,lhs(ic));" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 49 " h := ( op(2,rhs(domain))-op(1,rhs(domain)) )/N;" }}{PARA 0 " > " 0 "" {MPLTEXT 1 0 70 " F := unapply( subs( y(t)=_y, solve( ode, d iff(y(t),t) ) ), (t,_y) );" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 41 " X : = evalf( [ op(lhs(ic)), rhs(ic) ] );" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 " L := X;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 22 " for i from 1 to N do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 18 " f := F(op(X));" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 " X1 := X + [ h, h*f ];" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 " Xt := X + 2/3*[ h, h*f ];" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " X2 := X + [ h, h*F(op(X1)) ];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 21 " X := (X1 + X2)/2;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 " L := L, X;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 " end do;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 32 " retu rn matrix(N+2,2,[[t,y],L])" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "end pr oc:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{SECT 0 {PARA 4 "" 0 "16.A-1" {TEXT -1 16 "16.A-1 Example 1" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 35 "The approximate solution to the IVP" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "ode1 := dif f( y(x), x ) = -2*y(x);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "ic1 := y (0)=1;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 84 "on the interval [0,1] by RK2 with 10 subdivisio ns would be obtained with the command" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "RungeKutta2( ode1, ic1, x=0..1, 10 );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {SECT 0 {PARA 4 "" 0 "16.A-2" {TEXT -1 16 "16.A-2 Example 2" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 35 "For a second example, use RK2 with " } {XPPEDIT 18 0 "N" "6#%\"NG" }{TEXT -1 61 " = 2, 4, and 8 subdivisions \+ to find an approximate value for " }{XPPEDIT 18 0 "y(2)" "6#-%\"yG6#\" \"#" }{TEXT -1 6 " where" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "ode2 := diff( y(t), t )*sin(t) + y( t) = 3;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "ic2 := y(1)=2;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 8 "a2 := 1;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "b2 := \+ 2;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "N2 := [ 2, 4, 8 ];" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "H2 := map( n->(b2-a2)/n, N2 \+ );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "sol2 := RungeKutta2( ode2, ic2, t=a2..b2, N2[ 1] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "Y2[1] := sol2[N2[1]+2,2]; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 50 "sol2 := RungeKutta2( ode2, ic2, t=a2..b2, N2[2 ] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "Y2[2] := sol2[N2[2]+2,2];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "sol2 := RungeKutta2( ode2, ic2, t=a2..b2, N2[3] \+ ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "Y2[3] := sol2[N2[3]+2,2];" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 42 "These results can be summarized in a table" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "v0 := \+ vector( [ 'h', 'N', 'Y(2)' ] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 " v1 := vector( [ H2[1], N2[1], Y2[1] ] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "v2 := vector( [ H2[2], N2[2], Y2[2] ] ):" }}{PARA 0 " > " 0 "" {MPLTEXT 1 0 40 "v3 := vector( [ H2[3], N2[3], Y2[3] ] ):" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "stackmatrix( v0, v1, v2, v3 );" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 159 "Implementations of the Runge-Kutta Methods for a first-o rder system are not significantly different or more difficult, but wil l not be considered at this time." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "16.B" {TEXT -1 5 "16.B " } {HYPERLNK 17 "dsolve" 2 "dsolve" "" }{TEXT -1 24 " and Runge-Kutta Met hods" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 97 "To request the use of the \+ second-order Runge-Kutta method in Maple's numerical computations, use " }{HYPERLNK 17 "method=classical[rk2]" 2 "dsolve,classical" "" } {TEXT -1 68 ". The third- and fourth-Order Runge-Kutta Methods are uti lized when " }{HYPERLNK 17 "method=classical[rk3]" 2 "dsolve,classical " "" }{TEXT -1 4 " or " }{HYPERLNK 17 "method=classical[rk4]" 2 "dsolv e,classical" "" }{TEXT -1 121 " is specified. Also, recall that Maple' s default numerical method is the Fehlberg fourth-fifth order Runge-Ku tta method (" }{HYPERLNK 17 "method=rkf45" 2 "dsolve,rkf45" "" }{TEXT -1 2 ")." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 25 "To illustrate the use of " }{HYPERLNK 17 "dsolve" 2 "dsolve,numeri c" "" }{TEXT -1 97 " to obtain approximations using RK2, revisit the t wo examples considered in the previous section." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{SECT 0 {PARA 4 "" 0 "16.B-1" {TEXT -1 28 "16.B-1 Exa mple 1 (revisited)" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 169 "When an exp licit table of values is needed, it is necessary to provide a list of \+ values of the independent variable at which the approximate solution s hould be reported." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "x0 := 0:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "h1 := 0.1:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "N1 := 10:" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "x_list := vector( N1+1, i -> x0 + ( i-1)*h1 );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 68 "Then, the table of approximate solution v alues computed using RK2 is" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "dsolve( \{ ode1, ic1 \}, y(x ), type=numeric," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 59 " method= classical[rk2], stepsize=h1, value=x_list );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 43 "If the r esults are to be plotted, then the " }{HYPERLNK 17 "dsolve" 2 "dsolve " "" }{TEXT -1 5 " and " }{HYPERLNK 17 "odeplot" 2 "plots,odeplot" "" }{TEXT -1 32 " commands can be used as follows" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "sol := dsol ve( \{ ode1, ic1 \}, y(x), type=numeric," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 52 " method=classical[rk2], stepsize=h1 ): " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "odeplot( sol, [x,y(x)], 0..1 ); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 4 " " 0 "16.B-2" {TEXT -1 28 "16.B-2 Example 2 (revisited)" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 131 "Construction of the table of results whe n the second-order Runge-Kutta method is used is accomplished with thr ee separate calls to " }{HYPERLNK 17 "dsolve" 2 "dsolve,numeric" "" } {TEXT -1 1 ":" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "sol2 := dsolve( \{ ode2, ic2 \}, y(t), type=nume ric," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 56 " method=clas sical[rk2], stepsize=H2[1] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "Y2 [1] := eval( y(t), sol2(2) );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "sol2 := dsolve( \{ ode2, ic2 \}, y(t), type=numeric," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 56 " method=classical[rk2], stepsize=H2[2] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "Y2[2] := eval( y(t), sol2(2) );" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 50 "sol2 := dsolve( \{ ode2, ic2 \}, y(t), type=numeric ," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 56 " method=classic al[rk2], stepsize=H2[3] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "Y2[3] := eval( y(t), sol2(2) );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 18 "The final table is" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "v0 := vector( [ 'h', 'N', 'Y(2)' ] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "v1 := vector( [ H2[1], N2[1], Y2[1] ] ):" }}{PARA 0 " > " 0 "" {MPLTEXT 1 0 40 "v2 := vector( [ H2[2], N2[2], Y2[2] ] ):" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "v3 := vector( [ H2[3], N2[3], Y2[3] ] ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "stackmatrix( v0, v1, v2, v 3 );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}}{SECT 0 {PARA 3 "" 0 "16.C" {TEXT -1 14 "16.C Example 3" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 187 "The final example illustrates the use of the full r ange of Maple tools to obtain, visualize, and analyze an approximate s olution to an IVP obtained by the second-order Runge-Kutta Method." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "Consider \+ the problem of obtaining a solution to the IVP" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "ode3 := dif f( y(t) , t ) = sin( y(t) ) ;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "ic 3 := y(0) = 1;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 22 "on the interval [0,8]." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 28 "The Runge-Kutta M ethod with " }{XPPEDIT 18 0 "N" "6#%\"NG" }{TEXT -1 24 " = 4 subdivisi ons yields" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 53 "sol3rk2 := dsolve( \{ ode3, ic3 \}, y(t), type=nume ric," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 55 " method=c lassical[rk2], stepsize=2 ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "rk2 _plot := odeplot( sol3rk2, [t,y(t)], 0..8, style=line," }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 47 " color=BLUE, numpoints=4 ) :" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "display( rk2_plot );" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "To determine if this approximation is reasonable, superim pose this solution on the slope field." }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "slope_field := DEplot( \+ ode3, y(t), t=0..8, y=0..4, arrows=SMALL ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "display( [ slope_field, rk2_plot ] );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 406 "On the interval [0,2] the Runge-Kutta solution does not look \+ too bad. However, on [2,4] the Runge-Kutta solution does not follow th e slope field and is a much poorer approximation to the true solution. This solution is very similar to the one obtained with the Improved E uler Method. To obtain a reasonable approximation on the entire interv al using the Runge-Kutta Method, a smaller stepsize is required." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "sol3rk22 := dsolve( \{ ode3, ic3 \}, y(t), type=numeric, " }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 " method=classica l[heunform], stepsize=0.8 ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 59 "rk2 _plot2 := odeplot( sol3rk22, [t,y(t)], 0..8, style=line," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 49 " color=CYAN, numpoints=1 0 ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "display( [ slope_field, rk2 _plot2 ] );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "To complete the evaluation of this approx imate solution, the " }{HYPERLNK 17 "DEplot" 2 "DEtools,DEplot" "" } {TEXT -1 104 " command is used to include the (Maple-generated approxi mate) solution curve for this initial condition." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "sol_plot := DEplot( ode3, y(t), t=0..8, [ [ic3] ]," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 51 " arrows=NONE, linecolor=GREEN ):" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 58 "display( [ slope_field, sol_plot, rk2_plo t, rk2_plot2 ] );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 9 "[Back to " }{HYPERLNK 17 "ODE Power tool Table of Contents" 1 "unit00.mws" "" }{TEXT -1 1 "]" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "0 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }