Вы находитесь на странице: 1из 3

D.

Schwendeman
Numerical Computing

Due:
Thursday, 5/5/14

Problem Set 10

1. Find coefficients , such that the Runge-Kutta method is second order.


wi+1 = wi +

h
f (ti , wi ) + hf (ti + h, wi + hf (ti , wi ))
4

Note that
li+1 = wi+1 y(ti+1 )

y(ti+1 ) = y(ti ) = hf (ti , y(ti )) +

wi+1 = wi +

h2
(ft (ti , y(ti ) + fy (ti , y(ti ))f (ti , f(ti )) + O(h3 )
2

h
f (ti , wi ) + h[f (ti , wi ) + hf (ti , wi ) + fy (ti , wi )hf (ti , wi ) + O(h2 )]
4

Therefore we have that


h

+ h = h
4
2

h2 = h
2
2.
IVP:
y0 =

4ty
5
+
,
2
1+t
(1 + t2 )3

=
4

= 2
3

y(0) = 0,

0t2

(a) Solve exactly


4ty
5
2
=
(t) = e2 ln (t +1) = (t2 + 1)2
2
2
3
1+t
(1 + t )
Z
5
C
5
+C y =
arctan t +
(t2 + 1)2 y =
2
2
2
2
(1 + t )
(1 + t )
(1 + t2 )2
y0 +

Using initial conditions, we can see that C = 0 y =

5
(1+t2 )2

arctan t

(b) We now show some code. For the RK2 code please refer to the course website.
(c) The code for RK4 is as follows.
1

f u n c t i o n [ tOut , wOut]=myRK4( f , tspan , alpha , n s t e p )

2
3

% s o l v e y= f ( t , y ) , y ( a )=alpha , a<t<b u s i n g e x p l i c i t midpoint


method .
% ( h e r e [ a , b]= t s p a n and n s t e p a r e taken t o g e t from a t o b )

5
6
7
8

a=t s p a n ( 1 ) ;
b=t s p a n ( 2 ) ;
h=(ba ) / n s t e p ;

9
10

t=a ;
w=a l p h a ;

11
12
13
14
15
16
17
18
19
20
21
22
23

tOut=t ;
wOut=w ;
f o r k=1: n s t e p
K1=h f e v a l ( f , t , w) ;
K2=h f e v a l ( f , t+h / 2 ,w+K1/ 2 ) ;
K3=h f e v a l ( f , t+h , w+K2/ 2 ) ;
K4=h f e v a l ( f , t+h , w+K3) ;
w=w+(K1+2(K2+K3)+K4) / 6 ;
t=t+h ;
tOut =[ tOut ; t ] ;
wOut=[wOut ; w ] ;
end

(d) The order of accuracy is 2 for RK2 and 4 for RK4.

3. Find coefficients b0 , b1 , b2 .
The basic idea is to write the interpolation polynomial to approximate f and then
intergrate it.
)(tti2 )
0 (t) = (tti1
(h)(2h)
1 (t) =

(tti )(tti2 )
(h)(h3h)
(tti )(tti1 )
(3hh)(3h2h)

2 (t) =
Integrate the basis functions from ti to ti+1 would give the coefficients.
Z ti+1
bi =
i (t)dt
ti

for i = 0, 1, 2
We therefore have

23

b0 =

12

4
b1 =

b2 =
12

4. Adams-Bashforth Method.
1

f u n c t i o n [ tOut , wOut]=myAB( f , tspan , alpha , nstep , y h )

2
3
4
5
6
7
8

a=t s p a n ( 1 ) ;
b=t s p a n ( 2 ) ;
h=(ba ) / n s t e p ;
t l a s t=a ;
t=a+h ;

9
10

w l a s t=a l p h a ;
w=y h ;

11
12
13
14
15
16
17
18
19
20
21
22

tOut =[ t l a s t ; t ] ;
wOut=[ w l a s t ; w ] ;
f o r k=1: n s t e p
temp=w+h / 2 ( 3 f e v a l ( f , t , w)f e v a l ( f , t l a s t , w l a s t ) ) ;
wOut=[wOut ; temp ] ;
t l a s t=t ;
w l a s t=w ;
t=t+h ;
w=temp ;
tOut =[ tOut ; t ] ;
end
The method shows bigger error than RK4

Вам также может понравиться