《数值分析习题 .doc》由会员分享,可在线阅读,更多相关《数值分析习题 .doc(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、数值分析习题计算实习2(1) 利用二分法求方程f(x)=(x2+1)(x-1)5=0的根x=1,function x,n=erfenfa(fun,a,b,eps)N=log(b-a)/eps)-1;n=0;x=1/2*(a+b);while (feval(fun,x)=0)&(n=N) if feval(fun,x)*feval(fun,a)=eps x0=x; x=x0-feval(fun,x0)/feval(dfun,x0); n=n+1;end clearclcfun=inline(x2+1)*(x-1)5,x);dfun=inline(2*x*(x-1)5+5*(x2+1)*(x-1)
2、4,x);x0=0;eps=1e-5;x,n=newton(fun,dfun,x0,eps);xnx = 1.0000n =45(3) (3)利用割线法求方程f(x)=(x2+1)(x-1)5=0的根x=1。function x,n=gexianfa(fun,x0,x1,eps)x=x1-feval(fun,x1)/(feval(fun,x1)-feval(fun,x0)*(x1-x0);n=1;while abs(x-x1)=eps x0=x1; x1=x; x=x1-feval(fun,x1)/(feval(fun,x1)-feval(fun,x0)*(x1-x0); n=n+1;endf
3、un=inline(x2+1)*(x-1)5,x);x0=0;x1=1;eps=1e-5;x,n=gexianfa(fun,x0,x1,eps);xnx = 1n = 1(4) (4)利用史蒂芬森法求方程f(x)=(x2+1)(x-1)5=0的根x=1。function x,n=shidifensen(fun,dfun,x0,eps)x=x0-(x0-feval(fun,x0)/feval(dfun,x0)-x0)2/(x0-feval(fun,x0)/feval(dfun,x0)-feval(fun. ,x0-feval(fun,x0)/feval(dfun,x0)/feval(dfun,x
4、0-feval(fun,x0)/feval(dfun,x0)-2*(x0-feval(fun,x0)/feval(dfun,x0)+x0);n=1;while abs(x-x0)=eps x0=x; x=x0-(x0-feval(fun,x0)/feval(dfun,x0)-x0)2/(x0-feval(fun,x0)/feval(dfun,x0)-feval(fun. ,(x0-feval(fun,x0)/feval(dfun,x0)/feval(dfun,x0-feval(fun,x0)/feval(dfun,x0)-2*(x0-feval(fun,x0)/feval(dfun,x0)+x
5、0);n=n+1;end fun=inline(x2+1)*(x-1)5,x);dfun=inline(2*x*(x-1)5+5*(x2+1)*(x-1)4,x);x0=0.5;eps=1e-5;x,n=shidifensen(fun,dfun,x0,eps);xnx = 0.9805n = 2计算实习4(1) 用复合辛普森公式求积分的结果,并n=1;n=10;n=100,n=500fun=inline(x.2.*cos(10.*x),x);a=-1;b=1;n=10; %相应的将n改为1,100,500m=2.*n;h=(b-a)/m;x=a:h:b;sum1=0.0;sum2=0.0;fo
6、r k=1:10 x(2.*k-1)=a+(2.*k-1).*h; sum1=sum1+feval(fun,x(2.*k-1);endfor i=1:9 x(2.*i)=a+(2.*i).*h; sum2=sum2+feval(fun,x(2.*i);endS=h/3.*(fun(a)+fun(b)+4.*h/3.*sum1+2.*h/3.*sum2S = -0.1401(2) 利用龙贝格积分算法求n=1,10,100,500时,积分的值fun=inline(x.2.*cos(x),x);a=-1;b=1;n=1;%相应的将n改为10,100,500esp=1e-6;h=(b-a)/n;T(1
7、)=h/2.*(fun(a)+fun(b);m=1;sum=0.0;j=1:2(m-1);h=h/2;sum=sum+h.*feval(fun,a+(2.*j-1).*h);S(1)=1/2.*T(1)+sum;for i=1:m S(i+1)=S(i)+(S(i)-T(i)/4.i-1;endif abs(S(m+1)-T(m)=esp,break;T=S;m=m+1;endS(m+1)ans = -0.5948ans = -1.1552ans = -0.9930ans = -1.0035 2,用高斯勒让德求积公式计算积分 function f=yy=sin(x)/xformat long;fun=inline(sin(x)/x,x);ga1=2;x1=0;ga2=1,1;x2=-0.,0.;ga3=0.,0.,0.;x3=-0.,0,0.;ga4=0.,0.,0.,0.;x4=-0.,-0.,0.,0.;a=0;b=1;ga=ga3;x=x3;n=length(ga);s=0;for i=1:n t(i)=(b-a)/2*x(i)+(b+a)/2; s=s+(b-a)/2*feval(fun,t(i)*ga(i);ends s = 0.707计算实验5