Академический Документы
Профессиональный Документы
Культура Документы
Schwendeman
Numerical Computing
Due:
Thursday, 5/5/14
Problem Set 10
h
f (ti , wi ) + hf (ti + h, wi + hf (ti , wi ))
4
Note that
li+1 = wi+1 y(ti+1 )
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
+ 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
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
2
3
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
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
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