《matlab上机实验答案.docx》由会员分享,可在线阅读,更多相关《matlab上机实验答案.docx(13页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、三、假设已知矩阵,试给出相应的MATLAB命令,将其全部偶数行提取出来,赋给矩阵,用命令生成矩阵,用上述命令检验一下结果是不是正确。 A=magic(8)A =64 2 3 61 60 6 7 57 9 55 54 12 13 51 50 16 17 47 46 20 21 43 42 24 40 26 27 37 36 30 31 33 32 34 35 29 28 38 39 25 41 23 22 44 45 19 18 48 49 15 14 52 53 11 10 56 8 58 59 5 4 62 63 1 B=A(2:2:end,:)B =9 55 54 12 13 51 50
2、16 40 26 27 37 36 30 31 33 41 23 22 44 45 19 18 48 8 58 59 5 4 62 63 1五、选择合适的步距绘制出下面的图形。(1),其中; (2),其中。1 t=-1:0.0001:1;y=sin(1./t);plot(t,y)Warning: Divide by zero. 2 t=-pi:0.001:pi;y=sin(tan(t)-tan(sin(t);plot(t,y)七、试求出如下极限。(1); (2); (3)。(1) syms x;f=(3x+9x)(1/x);limit(f,x,inf) ans =9(2) syms x y;f
3、=x*y/(sqrt(x*y+1)-1);limit(limit(f,x,0),y,0) ans =2(3) syms x y;f=(1-cos(x2+y2)/(x2+y2)*exp(x2+y2);limit(limit(f,x,0),y,0) ans =0九、假设,试求。 syms x y t;f=int(exp(-t2),t,0,x*y);F=x./y.*diff(f,x,2)+2.*diff(diff(f,x,1),y,1)+diff(f,y,2) F =-6*x2*y2*exp(-x2*y2)+2*exp(-x2*y2)-2*x3*y*exp(-x2*y2)ans = -2*exp(-
4、x2*y2)*(3*x2*y2-1+x3*y)十一、试求出以下的曲线积分。 (1),为曲线, 。 (2),其中为正向上半椭圆。1 syms t a ;x=a*(cos(t)+t*sin(t);y=a*(sin(t)-t*cos(t);I=int(x2+y2)*sqrt(diff(x,t)2+diff(y,t)2),t,0,2*pi)I =2*a2*pi2*(a2)(1/2)+4*a2*pi4*(a2)(1/2) simple(I)ans =2*a3*pi2+4*a3*pi42syms x y a b c t; x=c*cos(t)/a; y=c*sin(t)/b; P=y*x3+exp(y);
5、 Q=x*y3+x*exp(y)-2*y; f=diff(x,t);diff(y,t); I=int(P Q*f,t,0,pi)I =-2/15*c*(-2*c4+15*b4)/b4/a simple(I)ans =4/15*c5/b4/a-2*c/a十三、试对矩阵进行Jordan变换,并得出变换矩阵。 A=-2,0.5,-0.5,0.5;0,-1.5,0.5,-0.5;2,0.5,-4.5,0.5;2,1,-2,-2A = -2.0000 0.5000 -0.5000 0.5000 0 -1.5000 0.5000 -0.5000 2.0000 0.5000 -4.5000 0.5000 2
6、.0000 1.0000 -2.0000 -2.0000 V,J=jordan(A)V = 0 0.5000 0.5000 -0.2500 0 0 0.5000 1.0000 0.2500 0.5000 0.5000 -0.2500 0.2500 0.5000 1.0000 -0.2500J = -4 0 0 0 0 -2 1 0 0 0 -2 10 0 0 -2十五、假设已知矩阵如下,试求出,。 syms t; A=-4.5,0,0.5,-1.5;-0.5,-4,0.5,-0.5;1.5,1,-2.5,1.5;0,-1,-1,-3; simple(expm(A*t)ans = 1/2/exp
7、(t)3-1/2*t/exp(t)3+1/2/exp(t)5+1/2*t2/exp(t)3, 1/2/exp(t)5-1/2/exp(t)3+t/exp(t)3, 1/2*t/exp(t)3+1/2*t2/exp(t)3, 1/2/exp(t)5-1/2/exp(t)3-1/2*t/exp(t)3+1/2*t2/exp(t)3 1/2*t/exp(t)3+1/2/exp(t)5-1/2/exp(t)3, 1/2/exp(t)3+1/2/exp(t)5, 1/2*t/exp(t)3, 1/2*t/exp(t)3+1/2/exp(t)5-1/2/exp(t)3 1/2*t/exp(t)3-1/2/
8、exp(t)5+1/2/exp(t)3, -1/2/exp(t)5+1/2/exp(t)3, 1/exp(t)3+1/2*t/exp(t)3, 1/2*t/exp(t)3-1/2/exp(t)5+1/2/exp(t)3 -1/2*t2/exp(t)3, -t/exp(t)3, -1/2*t2/exp(t)3-t/exp(t)3, 1/exp(t)3-1/2*t2/exp(t)3 A=-4.5,0,0.5,-1.5;-0.5,-4,0.5,-0.5;1.5,1,-2.5,1.5;0,-1,-1,-3; syms t;j=syms(sqrt(-1); A1=simple(expm(A*j*t)-e
9、xpm(-A*j*t)/(2*j)function F=funm(A,fun,x)V,J=jordan(A);v1=0,diag(J,1);V2=find(v1=0),length(v1)+1;for i=1:length(v2)-1 v_lambda(i=J(v2(i),v2(i);v_n(i)=v2(i+1)-v2(i);endm=length(v_lambda);F=sym();for i=1:m J1=J(v2(i):v2(i)+v_n(i)-1,v2(i):v2(i)+v_n(i)-1); fJ=funJ(J1,fun,x);F=diagm(F,fJ);endF=V*F*inv(V)
10、;function fJ=funJ(J,fun,x)lam=J(1,1);f1=fun;fJ=subs(fun,x,lam)*eye(size(J);H=diag(diag(J,1),1);H1=H;for i=2:length(J) f1=diff(f1,x);a1=subs(f1,x,lam);fJ=fJ+a1*H1;H1=H1*H/i;endfunction A=diagm(A1,A2)A=A1;n,m=size(A);n1,m1=size(A2);A(n+1:n+n1,m+1:m+m1)=A2; A=-4.5,0,0.5,-1.5;-0.5,-4,0.5,-0.5;1.5,1,-2.5
11、,1.5;0,-1,-1,-3; syms x t;A1=funm(sym(A),exp(A*t)*sin(A2*exp(A*t)*t),x)第二部分一、 对下列的函数进行Laplace变换。(1);(2);(3)。(1) syms t a;f=sin(a*t)/t;F=laplace(f)F =atan(a/s)(2) syms a t;f=t5*sin(a*t);F=simple(laplace(f)F =120/(s2+a2)3*sin(6*atan(a/s)(3) syms a t;f=(t.8)*cos(a*t);F=simple(laplace(f)F =40320/(s2+a2)
12、(9/2)*cos(9*atan(a/s)三、用数值求解函数求解下述一元和二元方程的根,并对得出的结果进行检验。(1);(2)。1 syms t x;t=solve(exp(-(x+1)2+pi/2)*sin(5*x+2)t =-2/5检验: subs(exp(-(x+1)2+pi/2)*sin(5*x+2),x,t)ans =02 syms x;y1=solve(x2+y2+x*y)*exp(-x2-y2-x*y)=0,y)y1 = (-1/2+1/2*i*3(1/2)*x (-1/2-1/2*i*3(1/2)*x g=simple(subs(x2+y2+x*y)*exp(-x2-y2-x*
13、y)=0,y,y1)g =(x2+(-1/2+1/2*i*3(1/2)2*x2+x2*(-1/2+1/2*i*3(1/2)*exp(-x2-(-1/2+1/2*i*3(1/2)2*x2-x2*(-1/2+1/2*i*3(1/2)=0(x2+(-1/2-1/2*i*3(1/2)2*x2+x2*(-1/2-1/2*i*3(1/2)*exp(-x2-(-1/2-1/2*i*3(1/2)2*x2-x2*(-1/2-1/2*i*3(1/2)=0五、试求出下面函数的Fourier变换,对得出的结果再进行Fourier反变换,观察是否能得出原来函数。(1);(2)。(1) syms x; f=x2*(3*s
14、ym(pi)-2*abs(x); F=fourier(f)F =-6*(4+pi2*dirac(2,w)*w4)/w4 ifourier(F)ans =x2*(-4*x*heaviside(x)+3*pi+2*x)(2) syms t; f=t2*(t-2*sym(pi)2; F=fourier(f)F =2*pi*(4*i*pi*dirac(3,w)-4*pi2*dirac(2,w)+dirac(4,w) ifourier(F)ans =x2*(-2*pi+x)2七、试求解下面的非线性规划问题。 function y=exc6fun6(x);y=exp(x(1)*(4*x(1)2+2*x(2
15、)2+4*x(1)*x(2)+2*x(2)+1); function c,ce=exc6fun6a(x);ce=;c=x(1)+x(2);x(1)*x(2)-x(1)-x(2)+1.5;-10-x(1)*x(2); A=;B=;Aeq=;Beq=;xm=-10;-10;xM=10;10;x0=(xm+xM)/2; ff=optimset;ff.TolX=1e-10;ff.TolFun=1e-20; x=fmincon(exc6fun6,x0,A,B,Aeq,Beq,xm,xM,exc6fun6a,ff); Maximum number of function evaluations excee
16、ded; increase OPTIONS.MaxFUNevals; x= 0.910i=1;x=x0;while(1) x,a,b=fmincon(exc6fun6,x,A,B,Aeq,Beq,xm,Xm,exc6fun6a,ff);If b0,break;end i=i+1;endx= 1.645 -1.900i= 5九、试求出微分方程的解析解通解,并求出满足边界条件的解析解。 syms x ;y=dsolve(D2y-(2-1/x)*Dy+(1-1/x)*y=x2*exp(-5*x),x) y = exp(x)*C2+exp(x)*log(x)*C1+1/1296*(6*exp(6*x)
17、*Ei(1,6*x)+11+30*x+36*x2)*exp(-5*x) syms xy=dsolve(D2y-(2-1/x)*Dy+(1-1/x)*y=x2*exp(-5*x),.y(1)=sym(pi),y(sym(pi)=1,x)y =-1/1296*exp(x)*(6*exp(1)*Ei(1,6)+77*exp(-5)-1296*sym(pi)/exp(1)+1/1296*exp(x)*log(x)*(6*Ei(1,6)*exp(6*sym(pi)+6)+77*exp(6*sym(pi)-1296*sym(pi)*exp(6*sym(pi)+5)+3*sqrt(-1)*pi*csgn(s
18、ym(pi)*exp(6*sym(pi)+6)-6*Ei(1,6*sym(pi)*exp(6*sym(pi)+6)-3*sqrt(-1)*pi*exp(6*sym(pi)+6)-3*sqrt(-1)*pi*csgn(6*sqrt(-1)*sym(pi)*exp(6*sym(pi)+6)-30*sym(pi)*exp(6)+3*sqrt(-1)*pi*csgn(sym(pi)*csgn(6*sqrt(-1)*sym(pi)*exp(6*sym(pi)+6)-36*sym(pi)2*exp(6)-11*exp(6)+1296*exp(5*sym(pi)+6)/log(sym(pi)*exp(-6*
19、sym(pi)-6)+1/1296*(6*exp(6*x)*Ei(1,6*x)+11+30*x+36*x2)*exp(-5*x)十一、考虑著名的化学反应方程组,选定,且,绘制仿真结果的三维相轨迹,并得出其在x-y平面上的投影。在实际求解中建议将作为附加参数,同样的方程若设,时,绘制出状态变量的二维图和三维图。 global a;global b;global c; a=0.2;b=0.2;c=5.7;t0=0,150;t,x=ode45(rossler,t0,0,0,0);plot(t,x),figure;plot3(x(:,1),x(:,2),x(:,3);grid; a=0.2;b=0.5;c=10; t0=0,150;t,x=ode45(rossler,t0,0,0,0);plot(t,x),figure; plot3(x(:,1),x(:,2),x(:,3);grid;十三、考虑简单的线性微分方程,且方程的初值为,试用Simulink搭建起系统的仿真模型,并绘制出仿真结果曲线。 t,x,y=sim(second13,0,10); plot(t,x) figure;plot(t,y)