[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc

上传人:sccc 文档编号:4532005 上传时间:2023-04-26 格式:DOC 页数:41 大小:190.50KB
返回 下载 相关 举报
[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc_第1页
第1页 / 共41页
[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc_第2页
第2页 / 共41页
[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc_第3页
第3页 / 共41页
[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc_第4页
第4页 / 共41页
[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc_第5页
第5页 / 共41页
点击查看更多>>
资源描述

《[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc》由会员分享,可在线阅读,更多相关《[工学]Matlab实验报告湖南工大工程应用软件Matlab实验课.doc(41页珍藏版)》请在三一办公上搜索。

1、实验一 x=1x = 1y=1 2 3 4 5 6 7 8 9 ;z1=1:10,z2=1:2:5;z1 = 1 2 3 4 5 6 7 8 9 10w=linspace(1,10,10); t1=ones(3),t2=ones(1,3),t3=ones(3,1)t1 = 1 1 1 1 1 1 1 1 1t2 = 1 1 1t3 = 1 1 1t4=zeros(3),t5=eye(4)t4 = 0 0 0 0 0 0 0 0 0t5 = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1思考题(1)变量名必须以字母开头,并且只能有字母、数字、下划线等三类符号组成,不能含有空格和标

2、点符号等;变量名区分字母的大小写;变量名不能超过63个字符,超过的部分被忽略;关键字不能作为变量名;最好不要使用教材P22当中表2-1的特殊常量符号作为变量名。 (2)分号的作用:分隔不想显示计算结果的各个语句;矩阵行与行之间的分隔符; 冒号的作用:生成一维数值数组;表示一维数组的全部元素或者多维数组某一维的全部元素。 逗号的作用:分隔想要显示结果的各个语句;变量分隔符;矩阵一行中各个元素的分隔符。 (3)linspace是线性等分函数,格式为A=linspace(a1,an,n),其中a1是向量的首元素,an是尾元素,意义是把向量等分为n个元素。若省略n,则默认生成50个元素。 (4)one

3、s():全1矩阵; zeros():全0矩阵; eye():单位矩阵。a=ones(1,30)a = Columns 1 through 19 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 20 through 30 1 1 1 1 1 1 1 1 1 1 1format compact aa = Columns 1 through 19 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 20 through 30 1 1 1 1 1 1 1 1 1 1 1format long pians = 3.141

4、59265358979 format short pians = 3.1416format long pians = 3.14159265358979 format + pians =+ -pians =- pi sin(pi)ans =+ sin(pi)ans =+ exist (pi)ans =+ pi=0; exist (pi)ans =+ pipi = clear pi exist (pi)ans =+结果分析:EXIST(A) returns: 0 if A does not exist 1 if A is a variable in the workspace 2 if A is

5、an M-file on MATLABs search path. It also returns 2 when A is the full pathname to a file or when A is the name of an ordinary file on MATLABs search path 3 if A is a MEX-file on MATLABs search path 4 if A is a MDL-file on MATLABs search path 5 if A is a built-in MATLAB function 6 if A is a P-file o

6、n MATLABs search path 7 if A is a directory 8 if A is a Java class 实验二A=2,3,4,5,6A = 2 3 4 5 6 B=1;2;3;4;5B = 1 2 3 4 5 A=1:2:10,B=1:10,C=10:-1:1A = 1 3 5 7 9B = 1 2 3 4 5 6 7 8 9 10C = 10 9 8 7 6 5 4 3 2 1A=linspace(1,10), B=linspace(1,30,30)A = Columns 1 through 11 1.0000 1.0909 1.1818 1.2727 1.36

7、36 1.4545 1.5455 1.6364 1.7273 1.8182 1.9091 Columns 12 through 22 2.0000 2.0909 2.1818 2.2727 2.3636 2.4545 2.5455 2.6364 2.7273 2.8182 2.9091 Columns 23 through 33 3.0000 3.0909 3.1818 3.2727 3.3636 3.4545 3.5455 3.6364 3.7273 3.8182 3.9091 Columns 34 through 44 4.0000 4.0909 4.1818 4.2727 4.3636

8、4.4545 4.5455 4.6364 4.7273 4.8182 4.9091 Columns 45 through 55 5.0000 5.0909 5.1818 5.2727 5.3636 5.4545 5.5455 5.6364 5.7273 5.8182 5.9091 Columns 56 through 66 6.0000 6.0909 6.1818 6.2727 6.3636 6.4545 6.5455 6.6364 6.7273 6.8182 6.9091 Columns 67 through 77 7.0000 7.0909 7.1818 7.2727 7.3636 7.4

9、545 7.5455 7.6364 7.7273 7.8182 7.9091 Columns 78 through 88 8.0000 8.0909 8.1818 8.2727 8.3636 8.4545 8.5455 8.6364 8.7273 8.8182 8.9091 Columns 89 through 99 9.0000 9.0909 9.1818 9.2727 9.3636 9.4545 9.5455 9.6364 9.7273 9.8182 9.9091 Column 100 10.0000B = Columns 1 through 19 1 2 3 4 5 6 7 8 9 10

10、 11 12 13 14 15 16 17 18 19 Columns 20 through 30 20 21 22 23 24 25 26 27 28 29 30A=logspace(0,4,5)A = 1 10 100 1000 10000练习:logspace(1,4*pi,10)ans = 1.0e+012 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0005 0.0099 0.1911 3.6844A=1 2 3 4 5,B=3:7,AT=A,BT=B,A = 1 2 3 4 5B = 3 4 5 6 7AT = 1 2 3 4 5BT

11、 = 3 4 5 6 7E1=A+B,E2=A-BE1 = 4 6 8 10 12E2 = -2 -2 -2 -2 -2F=AT-BT,F = -2 -2 -2 -2 -2G1=3*A,G2=B/3,G1 = 3 6 9 12 15G2 = 1.0000 1.3333 1.6667 2.0000 2.3333A=ones(1,10);B=(1:10);BT=B; E1=dot(A,B)E1 = 55 E2=A*BTE2 = 55clear A=1:3,B=3:5,A = 1 2 3B = 3 4 5 E=cross(A,B)E = -2 4 -2A=1 2 3;4 5 6A = 1 2 3 4

12、 5 6B=1 4 7 2 5 8 3 6 9B = 1 4 7 2 5 8 3 6 9 A(1)ans = 1 A(4:end)ans = 5 3 6B(:,1)ans = 1B(:)ans = 1 4 7 2 5 8 3 6 9B(5)ans = 5clear A=1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 B=A(1:3,2:3)B = 2 3 6 7 10 11 C=A(1 3,2 4)C = 2 4 10 12 D=A(1 3;2 4)D = 1 9 5 13clea

13、r A=ones(3,4)A = 1 1 1 1 1 1 1 1 1 1 1 1 B=zeros(3)B = 0 0 0 0 0 0 0 0 0 C=eye(3,2)C = 1 0 0 1 0 0 D=magic(3)D = 8 1 6 3 5 7 4 9 2clear A=ones(3,4)A = 1 1 1 1 1 1 1 1 1 1 1 1 B=zeros(3)B = 0 0 0 0 0 0 0 0 0D=A BD = 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 C=eye(4)C = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1

14、 F=A;CF = 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1clear A=0 1;1 1A = 0 1 1 1 B=2*ones(2)B = 2 2 2 2 cat(1,A,B,A)ans = 0 1 1 1 2 2 2 2 0 1 1 1cat(2,A,B,A)ans = 0 1 2 2 0 1 1 1 2 2 1 1repmat (A,2,2)ans = 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 repmat (A,2)ans = 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1A=

15、1 2;3 -1,B=-1 0;1 2A = 1 2 3 -1B = -1 0 1 2 A+Bans = 0 2 4 1 2*Aans = 2 4 6 -2 2*A-3*Bans = 5 4 3 -8 A*Bans = 1 4-4 -2 format rat;A=1 0 1;2 1 2;0 4 6A = 1 0 1 2 1 2 0 4 6 A1=inv(A)A1 = -1/3 2/3 -1/6 -2 1 0 4/3 -2/3 1/6 A*A1ans = 1 0 0 * 1 0 * * 1 a=1 2 1;3 1 4;2 2 1,b=1 1 2, d=ba = 1 2 1 3 1 4 2 2 1

16、 b = 1 1 2 d = 1 1 2 c1=b*inv(a),c2=b/ac1 = 6/7 3/7 -4/7 c2 = 6/7 3/7 -4/7 c3=inv(a)*d,c4=adc3 = 1 2/7 -4/7 c4 = 1 2/7 -4/7 注意:左除和右除 斜杠向左边倾斜式左除,斜杠向右边倾斜式右除;左除就是左边的数或者矩阵作为分母,右除就是右边的数或者矩阵作为分母。练习:(1)A=6 3 4;-2 5 7;8 -1 -3;B=3;-4;-7;X=ABX = 51/50 -14 243/25 (2)求矩阵的特征值与特征向量使用函数x,numdar=eig(A); (3)矩阵的乘幂与开方

17、 表达式为An,nA和sqrtm(A); (3)矩阵的指数与对数 表达式为expm(A)和logm(A); (4)矩阵的提取与翻转 参照教材P46的表2-10。A=6 3 4;-2 5 7;8 -1 -3;B=3;-4;-7;X=ABX = 51/50 -14 243/25 A1=1 2 3;4 5 6;7 8 9;A2=reshape(10:18,3,3)A2 = 10 13 16 11 14 17 12 15 18 T1(:,:,1)=ones(3);T1(:,:,2)=zeros(3)T1(:,:,1) = 1 1 1 1 1 1 1 1 1 T1(:,:,2) = 0 0 0 0 0

18、0 0 0 0 T2=ones(3,3,2)T2(:,:,1) = 1 1 1 1 1 1 1 1 1 T2(:,:,2) = 1 1 1 1 1 1 1 1 1 T3=cat(3,A1,A2),T4=repmat(A1,1,1,2)T3(:,:,1) = 1 2 3 4 5 6 7 8 9 T3(:,:,2) = 10 13 16 11 14 17 12 15 18 T4(:,:,1) = 1 2 3 4 5 6 7 8 9 T4(:,:,2) = 1 2 3 4 5 6 7 8 9 A=1:6;B=ones(1,6); C1=A+B,C2=A-BC1 = 2 3 4 5 6 7 C2 =

19、0 1 2 3 4 5 C3=A.*B,C4=B./A,C5=A.BC3 = 1 2 3 4 5 6 C4 = 1 1/2 1/3 1/4 1/5 1/6 C5 = 1 1/2 1/3 1/4 1/5 1/6 I=A3,C6=A(I)I = 0 0 0 1 1 1C6 = 4 5 6A1=A-3,I2=A1&AA1 = -2 -1 0 1 2 3 I2 = 1 1 0 1 1 1I3=II3 = 1 1 1 0 0 0练习:A1=1 3;4 2,A2=1 2;2 1,A3=3 5;7 1A1 = 1 3 4 2A2 = 1 2 2 1A3 = 3 5 7 1A(:,:,1)=A1, A(:,:

20、,2)=A2, A(:,:,3)=A3A(:,:,1) = 1 3 4 2A(:,:,2) = 1 2 2 1A(:,:,1) = 1 3 4 2A(:,:,2) = 1 2 2 1A(:,:,1) = 1 3 4 2A(:,:,2) = 1 2 2 1A(:,:,3) = 3 5 7 1B=reshape(A,3,2,2)B(:,:,1) = 1 2 4 1 3 2B(:,:,2) = 2 7 1 5 3 1S1=I like MATLABS1 =I like MATLAB S2=Im a student.S2 =Im a student. S3=S2,and,S1S3 =Im a stud

21、ent.andI like MATLABlength(S1)ans = 13 size (S1)ans = 1 13CS1=abs(S1)CS1 = 73 32 108 105 107 101 32 77 65 84 76 65 66 CS2=double(S1)CS2 = 73 32 108 105 107 101 32 77 65 84 76 65 66 char(CS2)ans =I like MATLABsetstr(CS2)ans =I like MATLAB练习:用char()和向量生成的方法创建如下的字符串 AaBbCcDdXxYyZz 答案:(1)A1= 65 97 66 98

22、91 123 Char(A1) (2) AaBbCcDdXxYyZz实验三 S=1 3 -5 0 9S = 1 3 -5 0 9 S1=0 0 2 3 11S1 = 0 0 2 3 11S2=1 3 -5 4 7S2 = 1 3 -5 4 7 S3=S1+S2S3 = 1 3 -3 7 18S1=2 3 11S1 = 2 3 11 S2=1 3 -5 4 7S2 = 1 3 -5 4 7 S3=conv(S1,S2)S3 = 2 9 10 26 -29 65 77 S4=deconv(S3,S1)S4 = 1 3 -5 4 7 S1=2 4 2S1 = 2 4 2 roots(S1)ans =

23、 -1 -1 S1=2 4 1 -3S1 = 2 4 1 -3 polyval(S1,3)ans = 90 x=1:10x = 1 2 3 4 5 6 7 8 9 10 y=polyval(S1,x)y = Columns 1 through 9 4 31 90 193 352 579 886 1285 1788 Column 10 2407练习:y1=1 0 1;y2=1 3;y3=0 1;y4=1 0 2 1y4 = 1 0 2 1 q,r=deconv(conv(conv(y1,y2),y3),y4)q = 0 1r = 0 0 3 -1 2 x=1:10x = 1 2 3 4 5 6 7 8 9 10 y=16 32 70 142 260 436 682 1010 1432 1960y = Columns 1 through 9 16 32 70 142 260 436 682 1010 1432 Column 10 1960 p1=polyfit(x,y,1)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 教育教学 > 成人教育


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号