欢迎来到天天文库
浏览记录
ID:37711451
大小:74.00 KB
页数:9页
时间:2019-05-29
《matlab实验9答案详解》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验九数值微积分与方程数值求解一、实验目的1.掌握求数值导数和数值积分的方法2.掌握代数方程数值求解方法3.掌握常微分方程数值求解方法二、实验内容1.程序代码x=1;i=1;f=inline('det([xx^2x^3;12*x3*x^2;026*x])');whilex<=3.01g(i)=f(x);i=i+1;x=x+0.01;endg;t=1:0.01:3.01;dx=diff(g)/0.01;f1=dx(1)f2=dx(101)f3=dx(length(g)-1)运行结果f1=6.0602f2=24.1202f3=54.18022.程序代码f=inli
2、ne('sqrt(cos(t.^2)+4*sin(2*t).^2+1)');I1=quad(f,0,2*pi)g=inline('log(1+x)./(1+x.^2)');I2=quad(g,0,2*pi)运行结果I1=10.4285I2=0.99973.程序代码A=[65-25;9-14-1;342-2;3-902];b=[-413111]';x=Aby=inv(A)*b[L,U]=lu(A);z=U(Lb)运行结果x=0.6667-1.00001.5000-0.0000y=0.6667-1.00001.50000.0000z=0.6667-1.000
3、01.5000-0.00004.程序代码function[x,y]=line_solution(A,b)[m,n]=size(A);y=[];ifnorm(b)>0%非齐次方程组ifrank(A)==rank([A,b])ifrank(A)==ndisp('有唯一解x');x=Ab;elsedisp('有无穷个解,特解x,基础解系y');x=Ab;y=null(A,'r');endelsedisp('无解');x=[];endelse%齐次方程组disp('有零解x');x=zeros(n,1);ifrank(A)4、;y=null(A,'r');endend命令formatratA=[2731;3522;9417];b=[642]';[x,y]=line_solution(A,b)运行结果有无穷个解,特解x,基础解系yWarning:Rankdeficient,rank=2,tol=8.6112e-015.>Inline_solutionat11x=-2/1110/1100y=1/11-9/11-5/111/111001说明,其中为任意常数。5.(1)程序代码functiong=f(x)g=3*x+sin(x)-exp(x);命令fzero('f',1.5)运行结果ans5、=1289/682(2)程序代码functionF=fun(X)x=X(1);y=X(2);z=X(3);F(1)=sin(x)+y^2+log(z)-7;F(2)=3*x+2-z^3+1;F(3)=x+y+z-5;命令>>X=fsolve('myfun',[1,1,1]',optimset('Display','off'))运行结果X=909/10731735/7281106/6256.程序代码functionf=g(u)x=u(1);y=u(2);f=2*x.^3+4*x.*y^3-10*x.*y+y.^2;命令formatlongf=inline('(x6、^3+cos(x)+x*log(x))/exp(x)');[x,fmin1]=fminbnd(f,0,1)[U,fmin2]=fminsearch('g',[0,0])运行结果x=0.52228834066617fmin1=0.39736346499846U=1.001570135316680.83348828276574fmin2=-3.324088491954237.程序代码functionxdot=sys(x,y)xdot=[y(2);(5*y(2)-y(1))/x];命令x0=1.0e-9;xf=20;[x,y]=ode45('sys',[x0,xf]7、,[00]);[x,y]运行结果ans=0.00000000100000000.50000000097500001.00000000095000001.50000000092500002.00000000090000002.50000000087500003.00000000085000003.50000000082500004.00000000080000004.50000000077500005.00000000075000005.50000000072500006.00000000070000006.50000000067500007.0000000008、65000007.5000000006
4、;y=null(A,'r');endend命令formatratA=[2731;3522;9417];b=[642]';[x,y]=line_solution(A,b)运行结果有无穷个解,特解x,基础解系yWarning:Rankdeficient,rank=2,tol=8.6112e-015.>Inline_solutionat11x=-2/1110/1100y=1/11-9/11-5/111/111001说明,其中为任意常数。5.(1)程序代码functiong=f(x)g=3*x+sin(x)-exp(x);命令fzero('f',1.5)运行结果ans
5、=1289/682(2)程序代码functionF=fun(X)x=X(1);y=X(2);z=X(3);F(1)=sin(x)+y^2+log(z)-7;F(2)=3*x+2-z^3+1;F(3)=x+y+z-5;命令>>X=fsolve('myfun',[1,1,1]',optimset('Display','off'))运行结果X=909/10731735/7281106/6256.程序代码functionf=g(u)x=u(1);y=u(2);f=2*x.^3+4*x.*y^3-10*x.*y+y.^2;命令formatlongf=inline('(x
6、^3+cos(x)+x*log(x))/exp(x)');[x,fmin1]=fminbnd(f,0,1)[U,fmin2]=fminsearch('g',[0,0])运行结果x=0.52228834066617fmin1=0.39736346499846U=1.001570135316680.83348828276574fmin2=-3.324088491954237.程序代码functionxdot=sys(x,y)xdot=[y(2);(5*y(2)-y(1))/x];命令x0=1.0e-9;xf=20;[x,y]=ode45('sys',[x0,xf]
7、,[00]);[x,y]运行结果ans=0.00000000100000000.50000000097500001.00000000095000001.50000000092500002.00000000090000002.50000000087500003.00000000085000003.50000000082500004.00000000080000004.50000000077500005.00000000075000005.50000000072500006.00000000070000006.50000000067500007.000000000
8、65000007.5000000006
此文档下载收益归作者所有