1、一:题目重述2()2 +()=+ 定 义 区 间为 : 0,2 (0)=1,u(2)=0,当 =1000时 ,求 和 ()二:解题过程 2.1求出差分方程差分方程为:Au=f=1 2 3 0 0 998 999,=123998999,=1+0223998999+10002其中: = 2000 =1,2,3999,= 2000,=12,=,=+,=22+2.2用追赶法编程求解差分方程function x=chase() tic;%开始计时n=999;%对 a,b,c,f进行赋值a=zeros(n-1,1);a=a-4000000/pi2;c=zeros(n-1,1);c=c-4000000/pi
2、2;b=zeros(n,1);f=zeros(n,1);qx=(x)sin(x);fx=(x)cos(x)+sin(x)*cos(x);x2=zeros(n,1);%记录 u(x)的真实值error=zeros(n,1);%记录误差for i=1:nb(i)=8000000/pi2+qx(pi*i/2000);f(i)=fx(pi*i/2000);x2(i)=cos(pi*i/2000);endf(1)=f(1)+4000000/pi2;% 对 A进行分解,追赶法u(1)=b(1); for i=2:n if(u(i-1)=0) l(i-1)=a(i-1)/u(i-1); u(i)=b(i)-
3、l(i-1)*c(i-1); else end end L=eye(n)+diag(l,-1); U=diag(u)+diag(c,1); x=zeros(n,1); y=x; % 求解 Ly=b ,追赶法第一步,消去最下面的斜行y(1)=f(1); for i=2:n y(i)=f(i)-l(i-1)*y(i-1); end % 求解 Ux=y,追赶法第二步 if(u(n)=0) x(n)=y(n)/u(n); end for i=n-1:-1:1 x(i)=(y(i)-c(i)*x(i+1)/u(i); endtime=toc;%计时结束,并赋值disp(运算时间为:);disp(time
4、);%列出计算结果result=x x2 error;disp( 数值解 真实解 误差项);disp(result);三:计算结果3.1 Matlab运行的结果(图 1)图 13.2整理后的部分结果(表 1)x=i*/2000 数值解 真实值 误差i=1 0.999998766488219 0.999998766299704 0.000000000188515 2 0.999995065578381 0.999995065201858 0.000000000376523 3 0.999988897279619 0.999988896715596 0.000000000564023 4 0.99
5、9980261607153 0.999980260856137 0.000000000751016 5 0.999969158582291 0.999969157644790 0.000000000937501 6 0.999955588232430 0.999955587108950 0.000000001123480 7 0.999939550591052 0.999939549282101 0.000000001308951 8 0.999921045697731 0.999921044203816 0.000000001493915 9 0.999900073598126 0.9999
6、00071919754 0.000000001678372 493 0.714838961127553 0.714838924546119 0.000000036581434 494 0.713739638835332 0.713739602276421 0.000000036558911 495 0.712638555461295 0.712638518925205 0.000000036536090 496 0.711535713722255 0.711535677209285 0.000000036512970 497 0.710431116339366 0.71043107984981
7、3 0.000000036489553 498 0.709324766038112 0.709324729572274 0.000000036465838 499 0.708216665548303 0.708216629106476 0.000000036441827 500 0.707106817604067 0.707106781186548 0.000000036417519 501 0.705995224943845 0.705995188550928 0.000000036392917 502 0.704881890310382 0.704881853942361 0.000000
8、036368021 503 0.703766816450721 0.703766780107891 0.000000036342830 504 0.702650006116195 0.702649969798849 0.000000036317346 505 0.701531462062425 0.701531425770856 0.000000036291569 506 0.700411187049307 0.700411150783806 0.000000036265501 507 0.699289183841008 0.699289147601868 0.000000036239140
9、508 0.698165455205962 0.698165418993473 0.000000036212489 509 0.697040003916856 0.697039967731308 0.000000036185548 990 0.015707318277898 0.015707317311821 0.000000000966077 991 0.014136696907518 0.014136696038033 0.000000000869485 992 0.012566040656241 0.012566039883353 0.000000000772888 993 0.0109
10、95353399505 0.010995352723218 0.000000000676287 994 0.009424639012826 0.009424638433144 0.000000000579682 995 0.007853901371785 0.007853900888711 0.000000000483074 996 0.006283144352021 0.006283143965559 0.000000000386462 997 0.004712371829222 0.004712371539373 0.000000000289849 998 0.003141587679113 0.003141587485880 0.000000000193233 999 0.001570795777448 0.001570795680831 0.000000000096617 表 1四:结论分析计算结果说明:1. 当步长足够长时(N=1000),利用差分方程解出的数值解和真实值极为接近,误差在 10-8数量级以上,效果非常好!2. 运行效率很高,使用追赶法解这个线性方程组,matlab 的运行时间极短,只有 0.046秒。