《数值分析》第五章实验报告
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
-2-
1.900 11.7479965 2.000 15.3982357 则有 i 1 5 6 9 10 ti 1.1 1.5 1.6 1.9 2.0 wi 0.2718282 3.1874451 4.6208178 11.7479965 15.3982357 y(ti) 0.345920 3.96767 5.70296 14.3231 18.6831
b)c)d)类似进行即可
EXERCISE SET 5.9 P322 2、方程组的 Runge-Kutta 算法 a) y' '2 y' y te t ,0 t 1, y(0) y' (0) 0, h 0.1
t
设 u1 (t ) y(t ), u2 (t ) y (t ) ,则将方程转换为方程组
'
-5-
u1' (t ) u2 (t )
' u2 (t ) 2u2 (t ) u1 (t ) t (et 1)
初始条件为
u1 (0) 0, u2 (0) 0
编写 MATLAB 程序 function[t,y] = Runge_Kutta4s(ydot_fun,t0,y0,h,N) %标准四阶Runge_Kutta公式,其中, %ydot_fun为一阶微分方程的函数; %t0为初始点; %y0为初始向量(列向量) ; %h为区间步长; %N为区间的个数; %t为Tn构成的向量; %y为Yn构成的矩阵。 t = zeros(1,N+1);y = zeros(length(y0),N+1); t(1) = t0;y(:,1) = y0; for n = 1 :N t(n+1) = t(n) + h; k1 = h * feval(ydot_fun,t(n),y(:,n)); k2 = h * feval(ydot_fun,t(n)+1/2 * h,y(:,n)+1/2 * k1); k3 = h * feval(ydot_fun,t(n)+1/2 * h,y(:,n)+1/2 * k2); k4 = h * feval(ydot_fun,t(n)+h,y(:,n)+k3); y(:,n+1) = y(:,n) + 1/6 * (k1 + k2 + k3 + k4); end 运行后有 >> odefun = inline('[y(2);2*y(2)-y(1)+t*(exp(t)-1)]','t','y'); >> [t,y] = Runge_Kutta4s(odefun,0,[0;0],0.1,10) t= Columns 1 through 9 0 0.8000 Columns 10 through 11 0.9000 1.0000 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
EXERCISE SET 5.4 P280 1、 a) y' te 2 y,0 t 1, y(0) 0, h 0.5
3t
编写 MATLAB 程序,如下 function[t,y] = Euler_r(ydot_fun,t0,y0,h,N) %改进Euler公式,其中, %ydot_fun为一阶微分方程的函数; %t0,y0为初始条件; %h为区间步长; %N为区间的个数; %t为Tn构成的向量; %y为Yn构成的向量. t = zeros(1,N+1);y = zeros(1,N+1); t(1) = t0;y(1) = y0; for n = 1:N t(n+1) = t(n) + h; ybar = y(n) + h * feval(ydot_fun,t(n),y(n)); y(n+1) = y(n) +h/2 (feval(ydot_fun,t(n),y(n))+feval(ydot_fun,t(n+1),ybar)); end 运行后 >> ydot_fun = inline('t*exp(3*t)-2*y','t','y'); >> [t,y]=Euler_r(ydot_fun,0,1,0.5,2) t= 0 0.5000 1.0000
-6-
y= Columns 1 through 9 0 0.0285 0 0.2106 Columns 10 through 11 0.0403 0.0022 0.0078 0.0198 0.0414 0.0768 0.1312 0.0000 0.0001 0.0005 0.0016 0.0039 0.0083 0.0160
则有
-1-
i 1 2
ti 0.500 1.000
wi 0.000 000 0 1.120 422 3
y(ti) 0.283 616 5 3.219 099 3
b)c)d)类似进行即可。
5、 y '
2 y t 2et ,1 t 2, y(1) 1 t
a)h=0.1 根据 Algorithm 5.1,利用课本作者网站上的关于本书的 MATLAB 程序 ALG051.M 运行该程序,在命令行窗口出现如下: This is Eulers Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 (2/t)*y+t^2*exp(t) Input left and right endpoints on separate lines. 1 2 Input the initial condition 0 Input a positive integer for the number of subintervals 10 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 EULERS METHOD t 1.000 1.100 1.200 1.300 1.400 1.500 1.600 1.700 1.800 w 0.0000000 0.2718282 0.6847556 1.2769783 2.0935477 3.1874451 4.6208178 6.4663964 8.8091197
-3-
*
y= 1.0000 1.0602 5.5515
b)c)d)类似进行
10、4 阶 Runge-Kutta 法求 1 题 选 d)进行 d) y' cos 2t sin 3t ,0 t 1, y(0) 1, h 0.25 根据 Algorithm 5.2,利用课本作者网站上的关于本书的 MATLAB 程序 ALG052.M This is the Runge-Kutta Order Four Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 cos(2*t)+sin(3*t) Input left and right endpoints on separate lines. 0 1 Input the initial condition 1 Input a positive integer for the number of subintervals 4 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 RUNGE-KUTTA FOURTH ORDER METHOD t 0.000 0.250 0.500 0.750 1.000 w 1.0000000 1.3291650 1.7305336 2.0415436 2.1180636
《数值分析》第五章实验报告
2010/5/7
EXERCISE SET 5.2 P263 1、Euler 法 1) y' te 3t 2 y 根据 Algorithm 5.1,利用课本作者网站上的关于本书的 MATLAB 程序 ALG051.M 运行该程序,在命令行窗口出现如下: This is Eulers Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 t*exp(3*t)-2*y Input left and right endpoints on separate lines. 0 1 Input the initial condition 1 Input a positive integer for the number of subintervals 2 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 EULERS METHOD t 0.000 0.500 1.000 w 1.0000000 0.0000000 1.1204223
-4-
EXERCISE SET 5.6 P266 4、使用 Adams 4 阶预测校正算法求 1 题 a) y' te 2 y,0 t 1, y(0) 0, h 0.2
3t
根据 Algorithm 5.4,利用课本作者网站上的关于本书的 MATLAB 程序 ALG054.M This is Adams-Bashforth Predictor Corrector Method Input the function F(t,y) in terms of t and y For example: y-t^2+1 t*exp(3*t)-2*y Input left and right endpoints on separate lines. 0 1 Input the initial condition 0 Input an integer > 3 for the number of subintervals 5 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 ADAMS-BASHFORTH FOURTH ORDER PREDICTOR CORRECTOR METHOD t 0.000 0.200 0.400 0.600 0.800 1.000 w 0.0000000 0.0269059 0.1510468 0.4966479 1.3408657 3.2450881
参考文献: 1、 《数值分析》第七版 (美)Richard L. Burden, J. Douglas Faires 著 冯烟利, 朱海燕译 高等教育出版社 2、 《数值分析与实验》 薛毅编著 北京工业大学出版社
-7-
1.900 11.7479965 2.000 15.3982357 则有 i 1 5 6 9 10 ti 1.1 1.5 1.6 1.9 2.0 wi 0.2718282 3.1874451 4.6208178 11.7479965 15.3982357 y(ti) 0.345920 3.96767 5.70296 14.3231 18.6831
b)c)d)类似进行即可
EXERCISE SET 5.9 P322 2、方程组的 Runge-Kutta 算法 a) y' '2 y' y te t ,0 t 1, y(0) y' (0) 0, h 0.1
t
设 u1 (t ) y(t ), u2 (t ) y (t ) ,则将方程转换为方程组
'
-5-
u1' (t ) u2 (t )
' u2 (t ) 2u2 (t ) u1 (t ) t (et 1)
初始条件为
u1 (0) 0, u2 (0) 0
编写 MATLAB 程序 function[t,y] = Runge_Kutta4s(ydot_fun,t0,y0,h,N) %标准四阶Runge_Kutta公式,其中, %ydot_fun为一阶微分方程的函数; %t0为初始点; %y0为初始向量(列向量) ; %h为区间步长; %N为区间的个数; %t为Tn构成的向量; %y为Yn构成的矩阵。 t = zeros(1,N+1);y = zeros(length(y0),N+1); t(1) = t0;y(:,1) = y0; for n = 1 :N t(n+1) = t(n) + h; k1 = h * feval(ydot_fun,t(n),y(:,n)); k2 = h * feval(ydot_fun,t(n)+1/2 * h,y(:,n)+1/2 * k1); k3 = h * feval(ydot_fun,t(n)+1/2 * h,y(:,n)+1/2 * k2); k4 = h * feval(ydot_fun,t(n)+h,y(:,n)+k3); y(:,n+1) = y(:,n) + 1/6 * (k1 + k2 + k3 + k4); end 运行后有 >> odefun = inline('[y(2);2*y(2)-y(1)+t*(exp(t)-1)]','t','y'); >> [t,y] = Runge_Kutta4s(odefun,0,[0;0],0.1,10) t= Columns 1 through 9 0 0.8000 Columns 10 through 11 0.9000 1.0000 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000
EXERCISE SET 5.4 P280 1、 a) y' te 2 y,0 t 1, y(0) 0, h 0.5
3t
编写 MATLAB 程序,如下 function[t,y] = Euler_r(ydot_fun,t0,y0,h,N) %改进Euler公式,其中, %ydot_fun为一阶微分方程的函数; %t0,y0为初始条件; %h为区间步长; %N为区间的个数; %t为Tn构成的向量; %y为Yn构成的向量. t = zeros(1,N+1);y = zeros(1,N+1); t(1) = t0;y(1) = y0; for n = 1:N t(n+1) = t(n) + h; ybar = y(n) + h * feval(ydot_fun,t(n),y(n)); y(n+1) = y(n) +h/2 (feval(ydot_fun,t(n),y(n))+feval(ydot_fun,t(n+1),ybar)); end 运行后 >> ydot_fun = inline('t*exp(3*t)-2*y','t','y'); >> [t,y]=Euler_r(ydot_fun,0,1,0.5,2) t= 0 0.5000 1.0000
-6-
y= Columns 1 through 9 0 0.0285 0 0.2106 Columns 10 through 11 0.0403 0.0022 0.0078 0.0198 0.0414 0.0768 0.1312 0.0000 0.0001 0.0005 0.0016 0.0039 0.0083 0.0160
则有
-1-
i 1 2
ti 0.500 1.000
wi 0.000 000 0 1.120 422 3
y(ti) 0.283 616 5 3.219 099 3
b)c)d)类似进行即可。
5、 y '
2 y t 2et ,1 t 2, y(1) 1 t
a)h=0.1 根据 Algorithm 5.1,利用课本作者网站上的关于本书的 MATLAB 程序 ALG051.M 运行该程序,在命令行窗口出现如下: This is Eulers Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 (2/t)*y+t^2*exp(t) Input left and right endpoints on separate lines. 1 2 Input the initial condition 0 Input a positive integer for the number of subintervals 10 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 EULERS METHOD t 1.000 1.100 1.200 1.300 1.400 1.500 1.600 1.700 1.800 w 0.0000000 0.2718282 0.6847556 1.2769783 2.0935477 3.1874451 4.6208178 6.4663964 8.8091197
-3-
*
y= 1.0000 1.0602 5.5515
b)c)d)类似进行
10、4 阶 Runge-Kutta 法求 1 题 选 d)进行 d) y' cos 2t sin 3t ,0 t 1, y(0) 1, h 0.25 根据 Algorithm 5.2,利用课本作者网站上的关于本书的 MATLAB 程序 ALG052.M This is the Runge-Kutta Order Four Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 cos(2*t)+sin(3*t) Input left and right endpoints on separate lines. 0 1 Input the initial condition 1 Input a positive integer for the number of subintervals 4 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 RUNGE-KUTTA FOURTH ORDER METHOD t 0.000 0.250 0.500 0.750 1.000 w 1.0000000 1.3291650 1.7305336 2.0415436 2.1180636
《数值分析》第五章实验报告
2010/5/7
EXERCISE SET 5.2 P263 1、Euler 法 1) y' te 3t 2 y 根据 Algorithm 5.1,利用课本作者网站上的关于本书的 MATLAB 程序 ALG051.M 运行该程序,在命令行窗口出现如下: This is Eulers Method. Input the function F(t,y) in terms of t and y For example: y-t^2+1 t*exp(3*t)-2*y Input left and right endpoints on separate lines. 0 1 Input the initial condition 1 Input a positive integer for the number of subintervals 2 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 EULERS METHOD t 0.000 0.500 1.000 w 1.0000000 0.0000000 1.1204223
-4-
EXERCISE SET 5.6 P266 4、使用 Adams 4 阶预测校正算法求 1 题 a) y' te 2 y,0 t 1, y(0) 0, h 0.2
3t
根据 Algorithm 5.4,利用课本作者网站上的关于本书的 MATLAB 程序 ALG054.M This is Adams-Bashforth Predictor Corrector Method Input the function F(t,y) in terms of t and y For example: y-t^2+1 t*exp(3*t)-2*y Input left and right endpoints on separate lines. 0 1 Input the initial condition 0 Input an integer > 3 for the number of subintervals 5 Choice of output method: 1. Output to screen 2. Output to text file Please enter 1 or 2 1 ADAMS-BASHFORTH FOURTH ORDER PREDICTOR CORRECTOR METHOD t 0.000 0.200 0.400 0.600 0.800 1.000 w 0.0000000 0.0269059 0.1510468 0.4966479 1.3408657 3.2450881
参考文献: 1、 《数值分析》第七版 (美)Richard L. Burden, J. Douglas Faires 著 冯烟利, 朱海燕译 高等教育出版社 2、 《数值分析与实验》 薛毅编著 北京工业大学出版社
-7-