Matlab实验报告终极版.docx
《Matlab实验报告终极版.docx》由会员分享,可在线阅读,更多相关《Matlab实验报告终极版.docx(48页珍藏版)》请在冰豆网上搜索。
![Matlab实验报告终极版.docx](https://file1.bdocx.com/fileroot1/2023-1/28/cdd0e270-5780-4823-a980-92f2ab26b1dd/cdd0e270-5780-4823-a980-92f2ab26b1dd1.gif)
Matlab实验报告终极版
(此文档为word格式,下载后您可任意编辑修改!
)
实验一Matlab的基本操作
一、验证所有例题内容
例1.1:
>>Time=[111212345678910]
Time=111212345678910
>>X_Data=[2.323.43;4.375.98]
X_Data=2.32003.4300
4.37005.9800
例1.2:
>>g=[1234];(85360)(1+(exp
(1))^2)
z1=0.0558
>>x=[21+2*i;-0.455]
x=2.0000+0.0000i1.0000+2.0000i
-0.4500+0.0000i5.0000+0.0000i
(2)>>z2=(log(x+sqrt(1+x^2)))2
z2=0.7114-0.0253i0.8968+0.3658i
0.2139+0.9343i1.1541-0.0044i
(3)>>a=[-3:
0.1:
3]
a=Columns1through9
-3.0000-2.9000-2.8000-2.7000-2.6000-2.5000-2.4000-2.3000-2.2000
Columns10through18
-2.1000-2.0000-1.9000-1.8000-1.7000-1.6000-1.5000-1.4000-1.3000
Columns19through27
-1.2000-1.1000-1.0000-0.9000-0.8000-0.7000-0.6000-0.5000-0.4000
Columns28through36
-0.3000-0.2000-0.100000.10000.20000.30000.40000.5000
Columns37through45
0.60000.70000.80000.90001.00001.10001.20001.30001.4000
Columns46through54
1.50001.60001.70001.80001.90002.00002.10002.20002.3000
Columns55through61
2.40002.50002.60002.70002.80002.90003.0000
>>m1=linspace(0.3,0.3,61)
m1=Columns1through9
0.30000.30000.30000.30000.30000.30000.30000.30000.3000
Columns10through18
0.30000.30000.30000.30000.30000.30000.30000.30000.3000
Columns19through27
0.30000.30000.30000.30000.30000.30000.30000.30000.3000
Columns28through36
0.30000.30000.30000.30000.30000.30000.30000.30000.3000
Columns37through45
0.30000.30000.30000.30000.30000.30000.30000.30000.3000
Columns46through54
0.30000.30000.30000.30000.30000.30000.30000.30000.3000
Columns55through61
0.30000.30000.30000.30000.30000.30000.3000
>>m2=linspace(-0.3,-0.3,61)
m2=Columns1through9
-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000
Columns10through18
-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000
Columns19through27
-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000
Columns28through36
-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000
Columns37through45
-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000
Columns46through54
-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000
Columns55through61
-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000-0.3000
>>z2=(power(exp
(1),m1.*a)-power(exp
(1),m2.*a))2.*sin(a+m1)+log((a+m1)2)
z2=Columns1through4
0.7388+3.1416i0.7696+3.1416i0.7871+3.1416i0.7913+3.1416i
Columns5through8
0.7822+3.1416i0.7602+3.1416i0.7254+3.1416i0.6784+3.1416i
Columns9through12
0.6196+3.1416i0.5496+3.1416i0.4688+3.1416i0.3780+3.1416i
Columns13through16
0.2775+3.1416i0.1680+3.1416i0.0497+3.1416i-0.0771+3.1416i
Columns17through20
-0.2124+3.1416i-0.3566+3.1416i-0.5104+3.1416i-0.6752+3.1416i
Columns21through24
-0.8536+3.1416i-1.0497+3.1416i-1.2701+3.1416i-1.5271+3.1416i
Columns25through28
-1.8436+3.1416i-2.2727+3.1416i-2.9837+3.1416i-37.0245+0.0000i
Columns29through32
-3.0017+0.0000i-2.3085+0.0000i-1.8971+0.0000i-1.5978+0.0000i
Columns33through36
-1.3575+0.0000i-1.1531+0.0000i-0.9723+0.0000i-0.8083+0.0000i
Columns37through40
-0.6567+0.0000i-0.5151+0.0000i-0.3819+0.0000i-0.2561+0.0000i
Columns41through44
-0.1374+0.0000i-0.0255+0.0000i0.0792+0.0000i0.1766+0.0000i
Columns45through48
0.2663+0.0000i0.3478+0.0000i0.4206+0.0000i0.4841+0.0000i
Columns49through52
0.5379+0.0000i0.5815+0.0000i0.6145+0.0000i0.6366+0.0000i
Columns53through56
0.6474+0.0000i0.6470+0.0000i0.6351+0.0000i0.6119+0.0000i
Columns57through60
0.5777+0.0000i0.5327+0.0000i0.4774+0.0000i0.4126+0.0000i
Column61
0.3388+0.0000i
6、已知:
,
求下列表达式的值。
(1),其中I为单位矩阵;
(2)和
(3)和
(4)和
(5)和
答:
>>A=[1234-4;34787;3657];B=[13-1;203;3-27];
>>A+6*B
ans=1852-10
467105
215349
>>I=eye(3);
>>A-B+I
ans=1231-3
32884
0671
>>A*B
ans=684462
309-72596
154-5241
>>A.*B
ans=121024
680261
9-13049
>>A^3
ans=3722623382448604
247370149188600766
78688454142118820
>>A.^3
ans=172839304-64
39304343658503
27274625343
>>AB
ans=16.4000-13.60007.6000
35.8000-76.200050.2000
67.0000-134.000068.0000
>>A\B
ans=-0.03130.3029-0.3324
0.0442-0.03230.1063
0.0317-0.11580.1558
>>[A,B]
ans=1234-413-1
34787203
36573-27
>>[A([1,3],:
);B^2]
ans=1234-4
3657
451
11019
20-540
实验二Matlab的数值计算和符号运算
一、上机验证实验
A、开启PC机,进入MATLAB语言
B、帮助命令的使用,查找sqrt函数的使用方法
答:
>>returnsthesquarerootofeachelementofthearrayX.
B=sqrt(X)
C、矩阵运算
(1)已知A=[12;34];B=[55;78];求A^2*B
答:
ans=105115
229251
(2)矩阵除法。
已知A=[123;456;789];B=[100;020;003];求AB,A\B
答:
>>A=[123;456;789];B=[100;020;003];
>>AB
ans=1.00001.00001.0000
4.00002.50002.0000
7.00004.00003.0000
>>A\B
警告:
矩阵接近奇异值,或者缩放错误。
结果可能不准确。
RCOND=1.541976e-18。
ans=1.0e+16*
-0.45041.8014-1.3511
0.9007-3.60292.7022
-0.45041.8014-1.3511
(3)矩阵的转置及共轭转置。
已知A=[15+i,2-i,1;6*i,4,9-i];求A.',A'
答:
>>A=[15+i,2-i,1;6*i,4,9-i];
>>A.'
ans=15.0000+1.0000i0.0000+6.0000i
2.0000-1.0000i4.0000+0.0000i
1.0000+0.0000i9.0000-1.0000i
>>A'
ans=15.0000-1.0000i0.0000-6.0000i
2.0000+1.0000i4.0000+0.0000i
1.0000+0.0000i9.0000+1.0000i
(4)使用冒号选出指定元素。
已知A=[123;456;789];求A中第3列前2个元素;A中所有第2行的元素;
答:
>>A=[123;456;789];
>>A(1:
2,3)
ans=3
6
>>A(2,1:
3)
ans=456
(5)方括号[]。
用magic函数生成一个4阶魔术矩阵,删除该矩阵的第四列。
答:
>>A=magic(4)
A=162313
511108
97612
414151
>>A(:
4)=[]
A=1623
51110
976
41415
D、多项式
(1)求多项式的根
答:
>>P=[];
>>roots(P)
ans=2.0000+0.0000i
-1.0000+1.0000i
-1.0000-1.0000i
(2)已知A=[1.2350.9;51.756;3901;1234],求矩阵A的特征多项式;
答:
>>A=[1.2350.9;51.756;3901;1234];
>>B=poly(A)
B=1.0000-6.9000-77.2600-86.1300604.5500
(3)P(s)=1.0000s^4-6.9000s^3-77.2600s^2-86.1300s+604.5500
求矩阵多项式中未知数为20时的值;
答:
>>C=polyval(B,20)
C=7.2778e+04
(4)把矩阵A作为未知数代入到多项式中;
答:
>>D=polyval(B,A)
D=1.0e+03*
0.3801-0.4545-1.99510.4601
-1.99510.2093-1.9951-2.8880
-0.4545-4.89780.60450.4353
0.43530.0841-0.4545-1.1617
2.上机练习实验
(1)利用returnsacolumnvectorwhoseelementsaretherootsofthe
polynomialc.
r=roots(c)
>>P=[];
>>roots(P)
ans=0.5917+0.4864i
0.5917-0.4864i
-0.2167+0.6158i
-0.2167-0.6158i
(2)令A是一个维度mxn的矩陣.解释max(A)和min(max(A))分別是什么意思?
答:
max(A):
表示由A矩阵每一列最大值组成的一横向量;min(max(A)):
表示得到的横向量之中的最小值。
>>A=rand(3,4)
A=0.81470.91340.27850.9649
0.90580.63240.54690.1576
0.12700.09750.95750.9706
>>max(A)
ans=0.90580.91340.95750.9706
>>min(max(A))
ans=0.9058
(3)令x是一个维度n的向量.解释find(x>0.8*max(x))是什么意思?
答:
find(x>0.8*max(x))的意思是从向量中找出大于最大值0.8倍的所有数据得位置。
>>x=[1;2;3;4;5;6];
>>a=find(x>0.8*max(x))
a=
5
6
(4)令x=[2356]和y=-1:
2而z=x.^y,解释z的值是什么?
答:
>>x=[2356];
>>y=-1:
2
y=-1012
>>z=x.^y
z=0.50001.00005.000036.0000
(5)试用解析解和数值解的方法求解微分方程
x"(t)=-2x(t)-3x'(t)+exp(-5t)
y"(t)=2x(t)-3y(t)-4x'(t)-4y'(t)-sint
x(0)=1,x'(0)=2,y(0)=3,y'(0)=4
解析解:
>>[x,y]=dsolve('D2x=(-2)*x-3*Dx+exp(-5*t),D2y=2*x-3*y-4*Dx-4*Dy-sint','x(0)=1,Dx(0)=2,y(0)=3,Dy(0)=4')
x=-(exp(-2*t)*(20*exp(t)*((3*exp(-4*t))4-514)-20*exp(-3*t)+200))60
y=-(exp(-3*t)*(sint-(21*exp(-2*t))2-sint*exp(3*t)+3*exp(t)*((20*exp(-3*t))3-2003)+6*exp(2*t)*((3*exp(-4*t))4-514)-6*exp(2*t)*(sint2+(exp(-4*t)*(12*t-8*sint*exp(5*t)+41))16-46516)+6*t*exp(2*t)*((3*exp(-4*t))4-514)+1712))6
(6)计算y=sinx+sin2x+sin3x,在x=π6处得值。
答:
>>symsx;
>>f=sin(x)+sin(2*x)+sin(3*x);
>>subs(f,x,pi6)
ans=3^(12)2+32
(7)用符号方法求积分
答:
>>symsx;
>>f=1(1+(x^4)+(x^8));
>>int(f,x)
ans=-(3^(12)*(atan((2*3^(12)*x)(3*((2*x^2)3-23)))-atanh((2*3^(12)*x)(3*((2*x^2)3+23)))))6
(8)用符号方法求下列极限:
答:
>>symsx;
>>f=(x*(power(exp
(1),sin(x))+1)-2*(power(exp
(1),tan(x))-1))(power(sin(x),3));
>>limit(f,x,0)
ans=-Inf
(9)用3次多项式方法插值计算1-100之间整数的平方根。
N
1
4
9
16
25
36
49
64
81
100
平方根
1
2
3
4
5
6
7
8
9
10
答:
>>n=(1:
10).^2;
>>f=sqrt(n);
>>interp1(n,f,(1:
100),‘cubic’)
ans=Columns1through7
1.00001.37291.71252.00002.24052.45512.6494
Columns8through14
2.82923.00003.16363.31863.46613.60693.7422
Columns15through21
3.87294.00004.12374.24354.35994.47304.5832
Columns22through28
4.69074.79584.89885.00005.09935.19665.2921
Columns29through35
5.38575.47775.56815.65705.74465.83095.9160
Columns36through42
6.00006.08296.16476.24546.32496.40356.4810
Columns43through49
6.55776.63346.70826.78236.85566.92817.0000
Columns50through56
7.07127.14167.21137.28047.34877.41647.4835
Columns57through63
7.55007.61597.68127.74597.81027.87397.9372
Columns64through70
8.00008.06238.12428.18558.24648.30688.3668
Columns71through77
8.42638.48548.54418.60248.66038.71788.7749
Columns78through84
8.83178.88818.94429.00009.05559.11079.1655
Columns85through91
9.22019.27449.32849.38219.43549.48849.5412
Columns92through98
9.59359.64569.69739.74869.79969.85029.9005
Columns99through100
9.950510.0000
(10)有3个多项式
,试进行下列操作:
求P(x)=P1(x)P2(x)。
求的根。
当x取矩阵A的每一元素时,求的值。
其中:
答:
>>P1=[12405];P2=[123];
>>P=conv(P1,P2)
P=141114171015
>>poly2sym(P)
ans=x^6+4*x^5+11*x^4+14*x^3+17*x^2+10*x+15
>>roots(P)
ans=-1.3156+1.6837i
-1.3156-1.6837i
-1.0000+1.4142i
-1.0000-1.4142i
0.3156+0.9978i
0.3156-0.9978i
>>A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];
>>polyva