MATLAB实验代码与运行结果.docx
《MATLAB实验代码与运行结果.docx》由会员分享,可在线阅读,更多相关《MATLAB实验代码与运行结果.docx(27页珍藏版)》请在冰点文库上搜索。
![MATLAB实验代码与运行结果.docx](https://file1.bingdoc.com/fileroot1/2023-6/20/61ad4f90-0795-487f-a9fa-c50d877ae42f/61ad4f90-0795-487f-a9fa-c50d877ae42f1.gif)
MATLAB实验代码与运行结果
MATLAB实验代码及运行结果
第一部分MATLAB语言编程、科学绘图与基本数学问题求解
第二题
>>A=[1234;4321;2341;3241]
A=
1234
4321
2341
3241
>>B=[1+4j,2+3j,3+2j,4+1j;4+1j,3+2j,2+3j,1+4j;2+3j,3+2j,4+1j,1+4j;3+2j,2+3j,4+1j,1+4j]
B=
1.0000+4.0000i2.0000+3.0000i3.0000+2.0000i4.0000+1.0000i
4.0000+1.0000i3.0000+2.0000i2.0000+3.0000i1.0000+4.0000i
2.0000+3.0000i3.0000+2.0000i4.0000+1.0000i1.0000+4.0000i
3.0000+2.0000i2.0000+3.0000i4.0000+1.0000i1.0000+4.0000i
>>A(5,6)=5
A=
123400
432100
234100
324100
000005
第三题
>>A=magic(8);
A=
642361606757
955541213515016
1747462021434224
4026273736303133
3234352928383925
4123224445191848
4915145253111056
858595462631
B=A(2:
2:
end,:
)
B=
955541213515016
4026273736303133
4123224445191848
858595462631
第四题
>>formatlong;sum(2.^[0:
63])
ans=
1.844674407370955e+19
>>sum(sym
(2).^[0:
63])
ans=
184********709551615
第五题
(1)
>>x=[-1:
0.001:
1];y=sin(1./x);plot(x,y)
(2)
>>t=[-pi:
0.005:
pi];y=sin(tan(t))-tan(sin(t));plot(t,y)
第六题
[x,y]=meshgrid(-2:
0.1:
2);z=1./(sqrt((1-x).^2+y.^2))+1./(sqrt((1+x).^2+y.^2));subplot(224),surf(x,y,z),shadingflat;subplot(221),surf(x,y,z),view(0,90);subplot(222),surf(x,y,z),view(90,0);subplot(223),surf(x,y,z),view(0,0)
>>
Warning:
Dividebyzero.
Warning:
Dividebyzero.
xx=[-2:
0.1:
-1.2,-1.1:
0.02:
-0.9,-0.8:
0.1:
0.8,0.9:
0.02:
1.1,1.2:
0.1:
2];yy=[-1:
0.1:
-0.2,-0.1:
0.02:
0.1,0.2:
0.1:
1];[x,y]=meshgrid(xx,yy);z=1./((sqrt(1-x).^2+y.^2))+1./(sqrt((1+x).^2+y.^2));subplot(224),surf(x,y,z),shadingflat;zlim([0,15]);subplot(221),surf(x,y,z),view(0,90);subplot(222),surf(x,y,z),view(90,0);subplot(223),surf(x,y,z),view(0,0)
第七题
(1)
>>symsx;f=(3^x+9^x)^(1/x);limit(f,x,inf)
ans=
9
(2)
>>symsxy;f=x*y/(sqrt(x*y+1)-1);limit(limit(f,y,0),x,0)
ans=
2
(3)
>>symsxy;f=(1-cos(x^2+y^2))/((x^2+y^2)*exp(x^2+y^2));limit(limit(f,y,0),x,0)
ans=
0
第八题
第一步新建脚本
functionresult=paradiff(y,x,t,n)
ifmod(n,1)~=0,error('nshouldpositiveinnteger,pleasecorrect')
elseifn==1,result=diff(y,t)/diff(x,t);
elseresult=diff(y,x,t,n-1)/diff(x,t);end,end
(1)
symst;x=log(cos(t));y=cos(t)-t*sin(t);f=simplify(paradiff(y,x,t,1))
f=
(cos(t)*(2*sin(t)+t*cos(t)))/sin(t)
(2)
symst;f=(cos(t)*(2*sin(t)+t*cos(t)))/sin(t);f1=diff(f)
f1=
(cos(t)*(3*cos(t)-t*sin(t)))/sin(t)-t*cos(t)-(cos(t)^2*(2*sin(t)+t*cos(t)))/sin(t)^2-2*sin(t)
t=pi/3;f1=(cos(t)*(3*cos(t)-t*sin(t)))/sin(t)-t*cos(t)-(cos(t)^2*(2*sin(t)+t*cos(t)))/sin(t)^2-2*sin(t)
f1=
-2.6651
第九题
>>symsxyt;f=int(exp(-t^2),t,0,x*y);F=(x/y)*(diff(f,x,2))-2*(diff(diff(f,x,1),y,1))+diff(f,y,2)
F=
2*x^2*y^2*exp(-x^2*y^2)-2*x^3*y*exp(-x^2*y^2)-2*exp(-x^2*y^2)
第十题
(1)
>>symsnm;limit(symsum(1/((2*m)^2-1),m,1,n),n,inf)
ans=
1/2
(2)
>>symsmn;limit(symsum(n*(1/(n^2+m*pi)),m,1,n),n,inf)
ans=
1第十一题
(1)
>>symst;symsapositive;x=a*(cos(t)+t*sin(t));y=a*(sin(t)-t*cos(t));I=int((x^2+y^2)*sqrt(diff(y,t)^2+diff(x,t)^2),t,0,2*pi)
I=
2*pi^2*a^3*(2*pi^2+1)
(2)
>>symstxy;symsacbpositive;x=c*cos(t)/a;y=c*sin(t)/b;F=[y*x^3+exp(y),x*y^3+x*exp(y)-2*y];ds=[diff(x,t);diff(y,t)];I=int(F*ds,t,pi,0)
I=
(2*c*(15*b^4-2*c^4))/(15*a*b^4)
第十二题
>>symsabcde;A=[a^4,a^3,a^2,a,1;b^4,b^3,b^2,b,1;c^4,c^3,c^2,c,1;d^4,d^3,d^2,d,1;e^4,e^3,e^2,e,1];simplify(det(A))
ans=
(a-b)*(a-c)*(a-d)*(b-c)*(a-e)*(b-d)*(b-e)*(c-d)*(c-e)*(d-e)
第十三题
>>A=[20.5-0.50.5;0-1.50.5-0.5;2,0.5-4.50.5;21-2-2];[V,J]=jordan(sym(A))
V=
[0,1/8,1/2,3/8]
[0,0,-2,-3]
[-1/6,1/24,-1/2,1/8]
[-1/6,1/24,-5/2,9/8]
J=
[-4,0,0,0]
[0,2,0,0]
[0,0,-2,1]
[0,0,0,-2]
第十四题
编写函数代码
functionX=lyapsym(A,B,C)
ifnargin==2,C=B;B=A';end
[nr,nc]=size(C);A0=kron(A,eye(nc))+kron(eye(nr),B');
try
C1=C';x0=-inv(A0)*C1(:
);X=reshape(x0,nc,nr)';
catch,error('singularmatrixfound.'),end
>>A=[3-6-405;142-24;-63-673;-13100-110;04034];B=[3-21;-2-92;-2-19];C=-[-21-1;412;5-61;6-4-4;-66-3];X=lyap(A,B,C),norm(A*X+X*B+C);X=lyapsym(sym(A),B,C),norm(A*X+X*B+C)
X=
4.056914.5128-1.5653
-0.0356-25.07432.7408
-9.4886-25.93234.4177
-2.6969-21.64502.8851
-7.7229-31.91003.7634
X=
[434641749950/107136516451,4664546747350/321409549353,-503105815912/321409549353]
[-3809507498/107136516451,-8059112319373/321409549353,880921527508/321409549353]
[-1016580400173/107136516451,-8334897743767/321409549353,1419901706449/321409549353]
[-288938859984/107136516451,-6956912657222/321409549353,927293592476/321409549353]
[-827401644798/107136516451,-10256166034813/321409549353,1209595497577/321409549353]
(2)
>>A=[3-6-405;142-24;-63-673;-13100-110;04034];
B=[3-21;-2-92;-2-19];C=-[-21-1;412;5-61;6-4-4;-66-3];
X=lyap(A,B,C),norm(A*X+X*B+C)
X=
4.056914.5128-1.5653
-0.0356-25.07432.7408
-9.4886-25.93234.4177
-2.6969-21.64502.8851
-7.7229-31.91003.7634
ans=
3.4356e-13
第十五题
>>symst;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];B=simplify(expm(A*t))
B=
[(exp(-5*t)*(exp(2*t)-t*exp(2*t)+t^2*exp(2*t)+1))/2,(exp(-5*t)*(2*t*exp(2*t)-exp(2*t)+1))/2,(t*exp(-3*t)*(t+1))/2,-(exp(-5*t)*(exp(2*t)+t*exp(2*t)-t^2*exp(2*t)-1))/2]
[(exp(-5*t)*(t*exp(2*t)-exp(2*t)+1))/2,(exp(-5*t)*(exp(2*t)+1))/2,(t*exp(-3*t))/2,(exp(-5*t)*(t*exp(2*t)-exp(2*t)+1))/2]
[(exp(-5*t)*(exp(2*t)+t*exp(2*t)-1))/2,(exp(-5*t)*(exp(2*t)-1))/2,(exp(-3*t)*(t+2))/2,(exp(-5*t)*(exp(2*t)+t*exp(2*t)-1))/2]
[-(t^2*exp(-3*t))/2,-t*exp(-3*t),-(t*exp(-3*t)*(t+2))/2,-(exp(-3*t)*(t^2-2))/2]
>>C=simplify(sin(A*t))
C=
[-sin((9*t)/2),0,sin(t/2),-sin((3*t)/2)]
[-sin(t/2),-sin(4*t),sin(t/2),-sin(t/2)]
[sin((3*t)/2),sin(t),-sin((5*t)/2),sin((3*t)/2)]
[0,-sin(t),-sin(t),-sin(3*t)]
>>D=simplify(expm(A*t)*sin(A^2*expm(A*t)*t))
D=
[(exp(-5*t)*sin((t*exp(-5*t)*(9*t*exp(2*t)-15*exp(2*t)+25))/2)*(2*t*exp(2*t)-exp(2*t)+1))/2+(exp(-5*t)*sin((t*exp(-3*t)*(9*t^2-12*t+2))/2)*(exp(2*t)+t*exp(2*t)-t^2*exp(2*t)-1))/2+(exp(-5*t)*sin((t*exp(-5*t)*(17*exp(2*t)-21*t*exp(2*t)+9*t^2*exp(2*t)+25))/2)*(exp(2*t)-t*exp(2*t)+t^2*exp(2*t)+1))/2+(t*exp(-3*t)*sin((t*exp(-5*t)*(3*exp(2*t)+9*t*exp(2*t)-25))/2)*(t+1))/2,(exp(-5*t)*sin((t*exp(-5*t)*(9*exp(2*t)+25))/2)*(2*t*exp(2*t)-exp(2*t)+1))/2+(exp(-5*t)*sin((t*exp(-5*t)*(18*t*exp(2*t)-21*exp(2*t)+25))/2)*(exp(2*t)-t*exp(2*t)+t^2*exp(2*t)+1))/2+(exp(-5*t)*sin(3*t*exp(-3*t)*(3*t-2))*(exp(2*t)+t*exp(2*t)-t^2*exp(2*t)-1))/2+(t*exp(-3*t)*sin((t*exp(-5*t)*(9*exp(2*t)-25))/2)*(t+1))/2,(exp(-5*t)*sin((3*t*exp(-3*t)*(3*t-2))/2)*(2*t*exp(2*t)-exp(2*t)+1))/2-(exp(-5*t)*sin((t*exp(-3*t)*(-9*t^2+3*t+4))/2)*(exp(2*t)-t*exp(2*t)+t^2*exp(2*t)+1))/2+(exp(-5*t)*sin((t*exp(-3*t)*(9*t^2+6*t-10))/2)*(exp(2*t)+t*exp(2*t)-t^2*exp(2*t)-1))/2+(t*exp(-3*t)*sin((3*t*exp(-3*t)*(3*t+4))/2)*(t+1))/2,(exp(-5*t)*sin((t*exp(-5*t)*(9*t*exp(2*t)-15*exp(2*t)+25))/2)*(2*t*exp(2*t)-exp(2*t)+1))/2-(exp(-5*t)*sin((t*exp(-5*t)*(exp(2*t)+21*t*exp(2*t)-9*t^2*exp(2*t)-25))/2)*(exp(2*t)-t*exp(2*t)+t^2*exp(2*t)+1))/2-(exp(-5*t)*sin((t*exp(-3*t)*(-9*t^2+12*t+16))/2)*(exp(2*t)+t*exp(2*t)-t^2*exp(2*t)-1))/2+(t*exp(-3*t)*sin((t*exp(-5*t)*(3*exp(2*t)+9*t*exp(2*t)-25))/2)*(t+1))/2]
[(exp(-5*t)*sin((t*exp(-5*t)*(17*exp(2*t)-21*t*exp(2*t)+9*t^2*exp(2*t)+25))/2)*(t*exp(2*t)-exp(2*t)+1))/2-(exp(-5*t)*sin((t*exp(-3*t)*(9*t^2-12*t+2))/2)*(t*exp(2*t)-exp(2*t)+1))/2+(t*exp(-3*t)*sin((t*exp(-5*t)*(3*exp(2*t)+9*t*exp(2*t)-25))/2))/2+(exp(-5*t)*sin((t*exp(-5*t)*(9*t*exp(2*t)-15*exp(2*t)+25))/2)*(exp(2*t)+1))/2,(exp(-5*t)*sin((t*exp(-5*t)*(18*t*exp(2*t)-21*exp(2*t)+25))/2)*(t*exp(2*t)-exp(2*t)+1))/2-(exp(-5*t)*sin(3*t*exp(-3*t)*(3*t-2))*(t*exp(2*t)-exp(2*t)+1))/2+(t*exp(-3*t)*sin((t*exp(-5*t)*(9*exp(2*t)-25))/2))/2+(exp(-5*t)*sin((t*exp(-5*t)*(9*exp(2*t)+25))/2)*(exp(2*t)+1))/2,(exp(-3*t)*sin((3*t*exp(-3*t)*(3*t-2))/2))/2+(exp(-5*t)*sin((3*t*exp(-3*t)*(3*t-2))/2))/2+(exp(-3*t)*sin((t*exp(-3*t)*(-9*t^2+3*t+4))/2))/2-(exp(-5*t)*sin((t*exp(-3*t)*(-9*t^2+3*t+4))/2))/2+(exp(-3*t)*sin((t*exp(-3*t)*(9*t^2+6*t-10))/2))/2-(exp(-5*t)*sin((t*exp(-3*t)*(9*t^2+6*t-10))/2))/2+(t*exp(-3*t)*sin((3*t*exp(-3*t)*(3*t+4))/2))/2-(t*exp(-3*t)*sin((t*exp(-3*t)*(-9*t^2+3*t+4))/2))/2-(t*exp(-3*t)*sin((t*exp(-3*t)*(9*t^2+6*t-10))/2))/2,(exp(-5*t)*sin((t*exp(-3*t)*(-9*t^2+12*t+16))/2)*(t*exp(2*t)-exp(2*t)+1))/2-(exp(-5*t)*sin((t*exp(-5*t)*(exp(2*t)+21*t*exp(2*t)-9*t^2*exp(2*t)-25))/2)*(t*exp(2*t)-exp(2*t)+1))/2+(t*exp(-3*t)*sin((t*exp(-5*t)*(3*exp(2*t)+9*t*exp(2*t)-25))/2))/2+(exp(-5*t)*sin((t*exp(-5*t)*(9*t*exp(2*t)-15*exp(2*t)+25))/2)*(exp(2*t)+1))/2]
[(exp(-5*t)*sin((t*exp(-5*t)*(17*exp(2*t)-21*t*exp(2*t)+9*t^2*exp(2*t)+25))/2)*(exp(2*t)+t*exp(2*t)-1))/2-(exp(-5*t)*sin((t*exp(-3*t)*(9*t^2-12*t+2))/2)*(exp(2*t)+t*exp(2*t)-1))/2+exp(-3*t)*sin((t*exp(-5*t)*(3*exp(2*t)+9*t*exp(2*t)-25))/2)*(t/2+1)+(exp(-5*t)*sin((t*exp(-5*t)*(9*t*exp(2*t)-15*exp(2*t)+25))/2)*(exp(2*t)-1))/2,exp(-3*t)*sin((t*exp(-5*t)*(9*exp(2*t)-25))/2)*(t/2+1)+(exp(-5*t)*sin((t*exp(-5*t)*(9*exp(2*t)+25))/2)*(exp(2*t)-1))/2+(exp(-5*t)*sin((t*exp(-5*t)*(18*t*exp(2*t)-21*exp(2*t)+25))/2)*(exp(2*t)+t*exp(2*t)-1))/2-(exp(-5*t)*sin(3*t*exp(-3*t)*(3*t-2))*(exp(2*t)+t*exp(2*t)-1))/2,exp(-3*t)*sin((3*t*exp(-3*t)*(3*t+4))/2)*(t/2+1)-(exp(-5*t)*sin((t*exp(-3*t)*(9*t^2