資源描述:
《MATLAB上機(jī)實(shí)驗(yàn)(答案).doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、MATLAB工具軟件實(shí)驗(yàn)(1)(1)生成一個(gè)4×4的隨機(jī)矩陣,求該矩陣的特征值和特征向量。程序:A=rand(4)[L,D]=eig(A)結(jié)果:A=0.95010.89130.82140.92180.23110.76210.44470.73820.60680.45650.61540.17630.48600.01850.79190.4057L=-0.7412-0.2729-0.1338i-0.2729+0.1338i-0.5413-0.3955-0.2609-0.4421i-0.2609+0.4421i0.5416-0.4062-0.0833+0.4672i-0.0833-0.46
2、72i0.4276-0.35950.64720.6472-0.4804D=2.323000000.0914+0.4586i00000.0914-0.4586i00000.2275(2)給出一系列的a值,采用函數(shù)畫(huà)一組橢圓。程序:a=0.5:0.5:4.5;%a的絕對(duì)值不能大于5t=[0:pi/50:2*pi]';%用參數(shù)t表示橢圓方程X=cos(t)*a;Y=sin(t)*sqrt(25-a.^2);plot(X,Y)結(jié)果:(3)X=[9,2,-3,-6,7,-2,1,7,4,-6,8,4,0,-2],(a)寫(xiě)出計(jì)算其負(fù)元素個(gè)數(shù)的程序。程序:X=[9,2,-3,-6,7,-2,1
3、,7,4,-6,8,4,0,-2];L=X<0;A=sum(L)結(jié)果:A=5(b)寫(xiě)出一段程序,使其能夠找出向量x中的最大、最小元素。(不能使用min和max命令)程序:X=[9,2,-3,-6,7,-2,1,7,4,-6,8,4,0,-2];xmin=999;xmax=-999;fori=1:length(X)ifxmin>X(i)xmin=X(i);endifxmax4、:0.0001:pi;y=sin(x);forn=1:ky=y+sin((2*n+1)*x)/(2*n+1);endplot(x,y)結(jié)果:MATLAB工具軟件實(shí)驗(yàn)(2)(1)應(yīng)用simulink實(shí)現(xiàn)下列系統(tǒng)的仿真,并試試改變信號(hào)源后的結(jié)果。略。(2)利用simulink解二階微分方程其中u(t)為單位階躍函數(shù)框圖:結(jié)果:(3)求矩陣的行列式、逆和特征值。程序:symsa11a12a21a22;A=[a11,a12;a21,a22]B=det(A),C=inv(A),D=eig(A)結(jié)果:A=[a11,a12][a21,a22]B=a11*a22-a12*a21C=[a22/(a
5、11*a22-a12*a21),-a12/(a11*a22-a12*a21)][-a21/(a11*a22-a12*a21),a11/(a11*a22-a12*a21)]D=1/2*a11+1/2*a22+1/2*(a11^2-2*a11*a22+a22^2+4*a12*a21)^(1/2)1/2*a11+1/2*a22-1/2*(a11^2-2*a11*a22+a22^2+4*a12*a21)^(1/2)(4)簡(jiǎn)化程序:symsx;f=(x^(-3)+6*x^(-2)+12*x^(-1)+8)^(1/3);g1=simple(f)g2=simple(g1)結(jié)果:g1=(2*x+
6、1)/xg2=2+1/x(5)計(jì)算積分程序:symsx;symsareal;%將a定義為實(shí)符號(hào)變量f=2^(-(a*x)^2)int(f,x,2,inf)結(jié)果:f=2^(-a^2*x^2)ans=-1/2*pi^(1/2)*(-signum(a)+erf(2*a*log(2)^(1/2)))/a/log(2)^(1/2)MATLAB工具軟件實(shí)驗(yàn)(3)(1)對(duì)函數(shù),用梯形法、辛普森法計(jì)算積分:,并討論分割區(qū)間數(shù)n對(duì)誤差的影響。其中S的精確值取為4.。程序:formatlongn=10:10:100;forii=1:10x=0:2/n(ii):2;f=sqrt(1+exp(x));s
7、=trapz(x,f)err(ii)=4.-s;endfigure(1)plot(n,err)f1=inline('sqrt(1+exp(x))');quad(f1,0,2)結(jié)果:s=4.834ans=4.512Figure1(2)對(duì)x=[00.10.20.30.40.50.60.70.80.91];y=[-0.4471.9783.286.167.087.347.669.569.489.3011.2];進(jìn)行線性,三階多項(xiàng)式插值。程序:x=[00.10.20.30.40.50.60