资源描述:
《MATLAB实习报告.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、MATLAB实习1.求f(x)=4x6-x+x3-95在(0,100)上最大值、最小值,根。(使用函数fminbnd、roots)。程序:symsxf='4*x.^6+x.^3-x-95';x1=fminbnd(f,0,100)x2=fminbnd('-4*x.^6-x.^3+x+95',0,100)x=x1;minf=eval(f)x=x2;maxf=eval(f)p=[40010-1-95];x=roots(p)结果:x1=0.4432x2=99.9999minf=-95.3258maxf=4.0000e+012x=1.68600.8525+1.4852i0.8525-1.
2、4852i-1.7050-0.8431+1.4514i-0.8431-1.4514i2.求解常微分方程x’’=-x’+x+1,x’(0)=1,x(0)=0(使用函数dsolve)。程序:y=dsolve('D2x=-Dx+x+1','Dx(0)=0,x(0)=0')23MATLAB实习结果:y=exp(1/2*(5^(1/2)-1)*t)*(1/10*5^(1/2)+1/2)+exp(-1/2*(5^(1/2)+1)*t)*(-1/10*5^(1/2)+1/2)-13.已知t=an2+bn,测得对应数据如下:(多项式插值interp1)t=[0,20,40,60,80,100,
3、120,140,160,183.5];n=[0,1153,2045,2800,3466,4068,4621,5135,5619,6152];试求a和b的值。程序:n=[0,1153,2045,2800,3466,4068,4621,5135,5619,6152];t=[0,20,40,60,80,100,120,140,160,183.5];A=polyfit(n,t,2);a=A(1),b=A(2)结果:a=2.5083e-006b=0.01444.请用梯形法、辛普森法分别计算积分值(trapz、quad)程序:F=@(x)sqrt(x.^2+x+1);Q=quad(F,0,
4、1)x=0:0.01:1;y=sqrt(x.^2+x+1);q=trapz(x,y)结果:Q=1.3369q=1.33695.计算二重积分(使用函数dblquad)程序:F=@(x,y)x.^2+y.^2+x*y+2*x+y+1;Q=dblquad(F,0,2,0,1)23MATLAB实习结果:Q=11.33336.矩阵M=[1,2,6;4,2,7;8,9,3],求M的LU分解,QR分解,对角阵,特征值分解。(使用函数lu、qr、shol、eig)程序:A=[123;456;789];[LU]=lu(a)[QR]=qr(a)[XD]=eig(a)结果:L=1U=2.5083e-
5、006Q=1R=2.5083e-006X=1D=2.5083e-0067.a=3,A=4,b=a2,B=b2-1,c=a+A-2B,C=a+B+2c,求C。(使用函数solve)程序:D=solve('a=3,A=4','b=a^2','B=b^2-1','c=a+A-2*B','C=a+B+2*c');C=D.C结果:C=-22323MATLAB实习8.用两种方法求解Ax=b的解。(A为四阶随机矩阵,b为四阶向量,自己创建)。程序:A=fix(50*rand(4))B=fix(50*rand(4,1))ifdet(A)~=0x=ABX=inv(A)*BelseC=B;D=[
6、AC]rref(B)end结果:A=474441461138223630223082403920B=46452044x=-0.85830.04301.31690.6621X=-0.85830.04301.31690.662123MATLAB实习9.,用两种方法求函数的根,并求其极值与零点。程序:y1='x.^3+(x-0.8).^2/(x+1.25).^3-5*(x+1/x)';ezplot(y1,[-100,100])[xmin,ymin]=fminbnd(y1,0,60);yminy2='-x.^3-(x-0.8).^2/(x+1.25).^3+5*(x+1/x)';[xm
7、ax,y]=fminbnd(y2,-50,-20);ymax=-y结果:ymin=-1.1489e+005ymax=-7.8999e+00310、f(x)的定义如下:,写一个matlab函数func1实现该函数。程序:functiony=hs(x)23MATLAB实习x=input('请输入x值:x=');ifx<0&x~=-4y=x.^2+x-6;elseifx>=0&x<10&x~=2&x~=3y=x.^2-5*x+6;elsey=x.^2-x+1;end结果:请输入x值:x=5.6an