计算物理结课报告姓名:___________学号:___________班级:___________指导老师:___________所用工具:Matlab8.0。3(A).用龙贝格法编程计算积分:∫()()()要求误差不超过。程序代码:functiony=question3(a,b,f,w)a1=b-a;f1=subs(f,a);f2=subs(f,b);Y=(f1+f2)*a1*0.5;T(1,1)=Y;Y1=f1+f2;k=2;w0=1;whileabs(w0)wh=a1./(2^(k-1));u=0;forj=1:2^(k-1)+1;z=a+h*(j-1);f4=subs(f,z);u=u+f4;endT(k,1)=(2*u-Y1)*h*0.5;w0=T(k,1)-T(k-1);k=k+1;endfori=2:k-1forj=i:k-1T(j,i)=((4^(i-1))*T(j,i-1)-T(j-1,i-1))./((4^(i-1))-1);endendy=T(k-1,k-1);y=vpa(y,7);运行结果:5.(B)试用二级欧拉近似法计算取步长h=0.1。程序代码:functionY0=question5(f,x0,y0,b,h)symsty;n=floor((b-x0)./h)+1;x(1)=x0;Y(1)=y0;f1=subs(f,'t',x(1));f1=subs(f1,'y',Y(1));Y(2)=Y(1)+h*f1;fori=3:nx(i-1)=x(i-2)+h;f2=subs(f,'t',x(i-1));f2=subs(f2,'y',Y(i-1));Y(i)=Y(i-2)+2*h*f2;endY0=Y(n);Y0=vpa(Y0,6);运行结果:symsty;f=1+exp(-t)*sin(y);Y0=question5(f,0,0,1,0.1)Y0=1.284857.(B)设(),试用二分法求该方程在区间[0.5,1.5]内根的近似值。程序代码:functionx0=Dichotomy(a,b,z,w)s=z;while(b-a)wz1=subs(z,a);c=(a+b)/2;z2=subs(s,c);ifz1*z20a=c;elseb=c;endendx0=c;x0=vpa(x0,6);运行结果:8.(B)利用牛顿迭代法求解在的根的近似值。程序代码:functionx1=Newton(x0,f,w1)z=diff(sym(f));w2=0.1;i=0;whilew2w1xa=subs(f,x0);xb=subs(z,x0);x1=x0-xa./xb;w2=abs(x1-x0);x0=x1;i=i+1;ifi=200break;endendx1=vpa(x1,8);运行结果:10.(B)在某次实验中,需要观察水分的渗透速度,测得时间t与水的重量W的数据如下:t/s1248163264W/g4.224.023.854.593.443.022.59设已知t和W的关系为,试用最小二乘法确定参数A,s.先需要对求对数化为线性方程:.程序代码:T=[1248163264];W=[4.224.023.854.593.443.022.59];fori=1:7T1(i)=log(T(i));W1(i)=log(W(i));end[f,a,b]=Niehe2(T1,W1);A=exp(a);s=b;plot(T,W,'*');holdont=0:0.01:65;w=A*(t.^s);plot(t,w);holdonlegend('节点','图像');function[f,a,b]=Nihe(x,y)m=length(x);z1=0;z2=0;z3=0;z4=0;z5=0;z6=0;fori=1:mz2=z2+x(i);z3=z3+y(i);z5=z5+x(i)*x(i);z6=z6+y(i)*x(i);endz1=z1+m;z4=z4+z2;a=(z3*z5-z2*z6)/(z1*z5-z2*z4);b=(z1*z6-z3*z4)/(z1*z5-z2*z4);symst;f=a+b*t;f=collect(f);f=vpa(f,6);运行结果: