HW5answer-2013
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
exact value: y(1.04)= 0.11998749706134 exact value: y(1.55)= 4.78863502080140 exact value: y(1.97)= 17.27929843555766
来自百度文库
which is much more accurate compared with the results in part b).
1.8 10.65951448039274 10.79362466049064 1.9 14.15268209037690 14.32308153589101
10 2.0 18.46999448255634 18.68309708188642
b) For linear interpolation,
Notice that all other values except for the y(t_i) have to be interpolated one way or another.
[z,Q]=hermite(t4(10:11),w4(10:11),wp(10:11)) t=1.97 yt3=Q(1,1)+Q(2,2)*(t-t4(10))+Q(3,3)*(t-t4(10))^2+Q(4,4)*(t-t4(10))^2*(t-t4(11)) function [t,w, y]=taylor(a, b, N, n)
a) Taylor’s method of order two gives the results in the following table, (using the code provided above)
i
ti
wi
y (ti )
1 2 3 4
1.1 0.33978522855738 1.2 0.85214344927635 1.3 1.58176950519471 1.4 2.58099664973816
function z=myfun(t,y) z=(2/t)*y+t^2*exp(t);
function z=myfunder1(t,y) z=(2/t^2)*y+4*t*exp(t)+t^2*exp(t);
function z=myfunder2(t,y) z=6*exp(t)+6*t*exp(t)+t^2*exp(t);
10 2.0 18.68286816800903 18.68309708188642
As we can see, the approximated values are much more accurate than the results obtained by using Taylor’s method of order 2.
0.34591987653974 0.86664253575960 1.60721507818074 2.62035955123583 3.96766629422779 5.72096152559634 7.96387347784497
1.8 10.65951448039274 10.79362466049064 1.9 14.32289684844547 14.32308153589101
Solution: We shall derive the formula for Taylor’s methods first. Since
f t, y t
2 y 4tet t 2et 2 t
f t, y t 6et 6tet t 2et f t, y t 12et 8tet t 2et
h=(b-a)/N; t(1)=a; w(1)=0; y(1)=0;
for i=2:N+1 switch n case 2 w(i)=w(i-1)+h*(myfun(t(i-1),w(i-1))+h/2*myfunder1(t(i-1),w(i-1))); case 4 w(i)=w(i-1)+h*(myfun(t(i-1),w(i-1))+h/2*myfunder1(t(i-1),w(i-1))... +h^2/6*myfunder2(t(i-1),w(i-1))+h^3/24*myfunder3(t(i-1),w(i-1))); end t(i)=a+(i-1)*h; y(i)=t(i)^2*(exp(t(i))-exp(1)); end
y (t ) w(ti ) t ti 1 t ti w(ti 1 ) , t [ti , ti 1 ]. ti ti 1 ti 1 ti
Again, by the code provided above, we can obtain the approximate values as well as the true values: t = 1.04 t = 1.55 t = 1.97 w(1.04) = 0.13591409142295 w(1.55) = 4.77703279758934 w(1.97) =17.17480076490251 exact value: y(1.04)= 0.11998749706134 exact value: y(1.55)= 4.78863502080140 exact value: y(1.97)= 17.27929843555766
we have
T
2
f t w t w f t w h 2
i, i i, i i, i
T
4
h 2 f ti , wi h 3 h ti ,wi f ti ,wi 2 f ti ,wi 6 24 f ti ,wi
0.34591987653974 0.86664253575960 1.60721507818074 2.62035955123583
5 6 7 8 9
1.5 3.91098455934566 1.6 5.64308103583302 1.7 7.86038160386642
3.96766629422779 5.72096152559634 7.96387347784497
c) Taylor’s method of order four gives the results in the following table, (using the code provided above)
i
ti
wi
y (ti )
1 2 3 4 5 6 7 8 9
1.1 0.34591268884570 1.2 0.86662572927868 1.3 1.60718588643574 1.4 2.62031484281613 1.5 3.96760253888109 1.6 5.72087475559039 1.7 7.96375924414548
[z,Q]=hermite(t4(1:2),w4(1:2),wp(1:2)) t=1.04 yt1=Q(1,1)+Q(2,2)*(t-t4(1))+Q(3,3)*(t-t4(1))^2+Q(4,4)*(t-t4(1))^2*(t-t4(2))
[z,Q]=hermite(t4(6:7),w4(6:7),wp(6:7)) t=1.55 yt2=Q(1,1)+Q(2,2)*(t-t4(6))+Q(3,3)*(t-t4(6))^2+Q(4,4)*(t-t4(6))^2*(t-t4(7))
Page 271 Q. 5 solution
y ( t ) t 2 ( e t e) :
Given the initial value problem y
2 y t 2et , 1 t 2, y (1) 0, with exact t
a) Use Tylor’s method of order two with h 0.1 to approximate the solution and compare it with the actual value of y. b) Use the answer generated in part (a) and linear interpolation to approximate y at the following values, and compare them to the actual values of y. i) y(1.04) ii) y(1.55) iii) y(1.97)
d) Cubic Hermite interpolation, algorithm 3.3 in the textbook, gives,
t = 1.04 t = 1.55 t = 1.97
w(1.04) = 0.11997038351857 w(1.55) = 4.78852715568361 w(1.97) = 17.27904042080268
function p271q5
a=1; b=2; N=10;
% to generate the results for part a [t2, w2, y]=taylor(a, b, N, 2)
% to generate the results in part b. i=1; t=1.04 wt=w2(i)*(t-t2(i+1))/(t2(i)-t2(i+1))+w2(i+1)*(t-t2(i))/(t2(i+1)-t2(i)) yt=t^2*(exp(t)-exp(1)) i=6; t=1.55 wt=w2(i)*(t-t2(i+1))/(t2(i)-t2(i+1))+w2(i+1)*(t-t2(i))/(t2(i+1)-t2(i)) yt=t^2*(exp(t)-exp(1)) i=10; t=1.97 wt=w2(i)*(t-t2(i+1))/(t2(i)-t2(i+1))+w2(i+1)*(t-t2(i))/(t2(i+1)-t2(i)) yt=t^2*(exp(t)-exp(1))
function z=myfunder3(t,y) z=12*exp(t)+8*t*exp(t)+t^2*exp(t);
function [z,Q]=hermite(x,f,fp)
Q=zeros(4,4); z=zeros(4,1); for i=1:2 z(2*(i-1)+1)=x(i); z(2*i)=x(i); Q(2*(i-1)+1,1)=f(i); Q(2*i,1)=f(i); Q(2*i,2)=fp(i); end Q(3,2)=(Q(3,1)-Q(2,1))/(z(3)-z(2)); for i=3:4 for j=3:i Q(i,j)=(Q(i,j-1)-Q(i-1,j-1))/(z(i)-z(i-j+1)); end end
c) Use Tylor’s method of order our with h=0.1 to approximate the solution, and compare with the actual values of y. d) Use the answers in part (c) and piecewise cubic Hermite interpolation to approximate y at the following values, and compare them to the actual values of y. i) y(1.04) ii) y(1.55) iii) y(1.97)
% to generate the results for part c [t4, w4, y]=taylor(a, b, N, 4)
% to generate the results for part d
% to approximate the y' wp(1)=exp(1); for i=2:N+1 wp(i)=myfun(t4(i),w4(i)); end