实验一-MATLAB语言基础实验_第1页
实验一-MATLAB语言基础实验_第2页
实验一-MATLAB语言基础实验_第3页
实验一-MATLAB语言基础实验_第4页
实验一-MATLAB语言基础实验_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实验一 MATLAB语言基础实验 1、 matlab的基本操作(1) 键入常数矩阵输入命令 a=1 2 3a = 1 2 3 a=1;2;3a =123 b=1 2 5b =1 2 5 b=1 2 5; b=1 2 5; c=a*bc =1 2 52 4 103 6 15 c=a*b? Error using = mtimesInner matrix dimensions must agree. a=1 2 3;4 5 6;7 8 0a =4 1 2 34 4 5 65 7 8 0 a2ans =6 30 36 156 66 81 427 39 54 69分析实验结果可以知道a=1 2 3 表

2、示行矩阵 a=1;2;3 表示列矩阵b=1 2 5 显示行矩阵 b=1 2 5; 不显示行矩阵但录入a 表示a矩阵的转置 c=a*b 矩阵的乘法(需满足矩阵乘法的条件) “;”表示换行a2 表示a矩阵的平方 a0.5 表示a开根号(2)作循环命令程序 makesum=0; for i=1:1:100makesum=makesum+i;end makesummakesum =5050从1加到100,每步的间隔为1(1+2+3+100)(3)分别执行下列命令 a=1 2 3;4 5 6;7 8 0a =1 2 3 4 5 67 8 0 poly(a) poly 求多项式的系数(由已知根求多项式的系

3、数)ans =1.0000 -6.0000 -72.0000 -27.0000 rank(a) rank 求矩阵的秩ans =3 det(a) det 矩阵的行列式ans =27.0000 trace(a) trace 矩阵的迹ans =6 inv(a) inv 求矩阵的逆ans = -1.7778 0.8889 -0.1111 1.5556 -0.7778 0.2222 -0.1111 0.2222 -0.1111 eig(a) eig 求矩阵的特征值ans =12.1229 -0.3884 -5.73457.1.2 MATLAB语言的数值运算1. 基本矩阵运算(1) 创建数值矩阵 a=1

4、2 3;4 5 6;7 8 9a =1 2 3 4 5 6 7 8 9 a(3,2) 显示a矩阵的第三行第二列ans =8 a(:,1) 显示a矩阵的第一列ans = 1 4 7 t=0:10; u=0:0.1:10; tt =0 1 2 3 4 5 6 7 8 9 10 uu =Columns 1 through 7 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 Columns 8 through 14 0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000 Columns 15 through 21 1.4

5、000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 Columns 22 through 28 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 Columns 29 through 35 2.8000 2.9000 3.0000 3.1000 3.2000 3.3000 3.4000 Columns 36 through 42 3.5000 3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 Columns 43 through 49 4.2000 4.3000 4.400

6、0 4.5000 4.6000 4.7000 4.8000 Columns 50 through 56 4.9000 5.0000 5.1000 5.2000 5.3000 5.4000 5.5000 Columns 57 through 63 5.6000 5.7000 5.8000 5.9000 6.0000 6.1000 6.2000 Columns 64 through 70 6.3000 6.4000 6.5000 6.6000 6.7000 6.8000 6.9000 Columns 71 through 77 7.0000 7.1000 7.2000 7.3000 7.4000

7、7.5000 7.6000 Columns 78 through 84 7.7000 7.8000 7.9000 8.0000 8.1000 8.2000 8.3000 Columns 85 through 91 8.4000 8.5000 8.6000 8.7000 8.8000 8.9000 9.0000 Columns 92 through 98 9.1000 9.2000 9.3000 9.4000 9.5000 9.6000 9.7000 Columns 99 through 101以0.1为间隔从0到10 a(:,3)=2;3;4; aa =1 2 2 4 5 3 7 8 4 b=

8、1 1+2i;3+4i 3;将第三列改为234 bb =1.0000 1.0000 + 2.0000i3.0000 + 4.0000i 3.0000 产生复数矩阵 a=ones(3,3); b=zeros(2,2); c=eye(4); magic(4); aa =1 1 1 1 1 1 1 1 1产生一个全为1的矩阵 bb =0 0 00将矩阵置0 cc =1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1置成单位矩阵magic(4)ans =16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1产生一个矩阵他的行和列对角线和相同 a=0 1 0;0 0 1

9、;-6 -11 -6; b=1 2;3 4;5 6; c=1 1 0;0 1 1; v1=c*av1 =0 1 1 -6 -11 -5 v2=a*bv2 =3 4 5 6 -69 -92 v3=c*a*bv3 =8 10 -64 -86 v4=b*cv4 =1 3 2 3 7 4 5 11 6 v5=c*bv5 =4 6 8 10 a2ans = 0 0 1 -6 -11 -6 36 60 25 a(1/2)ans =0.0000 + 0.4894i -0.0000 - 0.5588i -0.0000 - 0.0482i 0.0000 + 0.2891i 0.0000 + 1.0195i -0

10、.0000 - 0.2696i 0.0000 + 1.6179i 0.0000 + 3.2553i 0.0000 + 2.6374i ai=a+b*cai =1 4 2 3 7 5 -1 0 0 a1=a+b*ca1 =1 4 2 3 7 5 -1 0 0 a2=c*b-a(1:2,1:2)a2 =4 5 8 10 a(1:2)取第一列的前两个数 a3=a(1:2,2:3)+c*ba3 =5 6 8 11 ar=a/b? Error using = mrdivideMatrix dimensions must agree. ar=c/aar = -0.8333 -1.0000 -0.1667

11、1.0000 1.0000 0 al=abal = -5.6667 -8.6667 1.0000 2.00003.0000 4.0000 aans = 0 0 -6 1 0 -11 0 1 -6矩阵的转置 inv(a)ans = -1.8333 -1.0000 -0.1667 1.0000 0 0 0 1.0000 0 diag(a)ans =0 0 -6求矩阵a的主对角线并以列的形式表现出来 tril(a)ans =0 0 0 0 0 0 -6 -11 -6产生X矩阵的下三角矩阵 inv(a)ans = -1.8333 -1.0000 -0.1667 1.0000 0 0 0 1.0000

12、0 poly(a)ans =1.0000 6.0000 11.0000 6.0000 rank(a)ans =3 det(a)ans =-6 trace(a)ans = -6 eig(a)ans = -1.0000 -2.0000 -3.0000(2)MATLAB语言的点运算1练习点乘与点除a1=1 2;3 4; a2=0.2*a1; a1 a2ans =1.0000 2.0000 0.2000 0.4000 3.0000 4.0000 0.6000 0.8000把a1,a2按矩阵排列 a1.*a2 a1./a2ans =0.2000 0.8000 5.0000 5.0000 1.8000 3

13、.2000 5.0000 5.0000点乘是矩阵中每个数象乘,点除是矩阵中每个数相除2)由点运算完成标量函数运算与作图t=0:2*pi/180:2*pi 从0数到2以2/180为间隔t =Columns 1 through 6 0 0.0349 0.0698 0.1047 0.1396 0.1745 Columns 7 through 12 0.2094 0.2443 0.2793 0.3142 0.3491 0.3840 Columns 13 through 18 0.4189 0.4538 0.4887 0.5236 0.5585 0.5934 Columns 19 through 24

14、0.6283 0.6632 0.6981 0.7330 0.7679 0.8029 Columns 25 through 30 0.8378 0.8727 0.9076 0.9425 0.9774 1.0123 Columns 31 through 36 1.0472 1.0821 1.1170 1.1519 1.1868 1.2217 Columns 37 through 42 1.2566 1.2915 1.3265 1.3614 1.3963 1.4312 Columns 43 through 48 1.4661 1.5010 1.5359 1.5708 1.6057 1.6406 Co

15、lumns 49 through 54 1.6755 1.7104 1.7453 1.7802 1.8151 1.8500 Columns 55 through 60 1.8850 1.9199 1.9548 1.9897 2.0246 2.0595 Columns 61 through 66 2.0944 2.1293 2.1642 2.1991 2.2340 2.2689 Columns 67 through 72 2.3038 2.3387 2.3736 2.4086 2.4435 2.4784 Columns 73 through 78 2.5133 2.5482 2.5831 2.6

16、180 2.6529 2.6878 Columns 79 through 84 2.7227 2.7576 2.7925 2.8274 2.8623 2.8972 Columns 85 through 90 2.9322 2.9671 3.0020 3.0369 3.0718 3.1067 Columns 91 through 96 3.1416 3.1765 3.2114 3.2463 3.2812 3.3161 Columns 97 through 102 3.3510 3.3859 3.4208 3.4558 3.4907 3.5256 Columns 103 through 108 3

17、.5605 3.5954 3.6303 3.6652 3.7001 3.7350 Columns 109 through 114 3.7699 3.8048 3.8397 3.8746 3.9095 3.9444 Columns 115 through 120 3.9794 4.0143 4.0492 4.0841 4.1190 4.1539 Columns 121 through 126 4.1888 4.2237 4.2586 4.2935 4.3284 4.3633 Columns 127 through 132 4.3982 4.4331 4.4680 4.5029 4.5379 4.

18、5728 Columns 133 through 138 4.6077 4.6426 4.6775 4.7124 4.7473 4.7822 Columns 139 through 144 4.8171 4.8520 4.8869 4.9218 4.9567 4.9916 Columns 145 through 150 5.0265 5.0615 5.0964 5.1313 5.1662 5.2011 Columns 151 through 156 5.2360 5.2709 5.3058 5.3407 5.3756 5.4105 Columns 157 through 162 5.4454

19、5.4803 5.5152 5.5501 5.5851 5.6200 Columns 163 through 168 5.6549 5.6898 5.7247 5.7596 5.7945 5.8294 Columns 169 through 174 5.8643 5.8992 5.9341 5.9690 6.0039 6.0388 Columns 175 through 180 6.0737 6.1087 6.1436 6.1785 6.2134 6.2483 Column 181 6.2832y1=sin(t)y1 =Columns 1 through 6 0 0.0349 0.0698 0

20、.1045 0.1392 0.1736 Columns 7 through 12 0.2079 0.2419 0.2756 0.3090 0.3420 0.3746 Columns 13 through 18 0.4067 0.4384 0.4695 0.5000 0.5299 0.5592 Columns 19 through 24 0.5878 0.6157 0.6428 0.6691 0.6947 0.7193 Columns 25 through 30 0.7431 0.7660 0.7880 0.8090 0.8290 0.8480 Columns 31 through 36 0.8

21、660 0.8829 0.8988 0.9135 0.9272 0.9397 Columns 37 through 42 0.9511 0.9613 0.9703 0.9781 0.9848 0.9903 Columns 43 through 48 0.9945 0.9976 0.9994 1.0000 0.9994 0.9976 Columns 49 through 54 0.9945 0.9903 0.9848 0.9781 0.9703 0.9613 Columns 55 through 60 0.9511 0.9397 0.9272 0.9135 0.8988 0.8829 Colum

22、ns 61 through 66 0.8660 0.8480 0.8290 0.8090 0.7880 0.7660 Columns 67 through 72 0.7431 0.7193 0.6947 0.6691 0.6428 0.6157 Columns 73 through 78 0.5878 0.5592 0.5299 0.5000 0.4695 0.4384 Columns 79 through 84 0.4067 0.3746 0.3420 0.3090 0.2756 0.2419 Columns 85 through 90 0.2079 0.1736 0.1392 0.1045

23、 0.0698 0.0349 Columns 91 through 96 0.0000 -0.0349 -0.0698 -0.1045 -0.1392 -0.1736 Columns 97 through 102 -0.2079 -0.2419 -0.2756 -0.3090 -0.3420 -0.3746 Columns 103 through 108 -0.4067 -0.4384 -0.4695 -0.5000 -0.5299 -0.5592 Columns 109 through 114 -0.5878 -0.6157 -0.6428 -0.6691 -0.6947 -0.7193 C

24、olumns 115 through 120 -0.7431 -0.7660 -0.7880 -0.8090 -0.8290 -0.8480 Columns 121 through 126 -0.8660 -0.8829 -0.8988 -0.9135 -0.9272 -0.9397 Columns 127 through 132 -0.9511 -0.9613 -0.9703 -0.9781 -0.9848 -0.9903 Columns 133 through 138 -0.9945 -0.9976 -0.9994 -1.0000 -0.9994 -0.9976 Columns 139 t

25、hrough 144 -0.9945 -0.9903 -0.9848 -0.9781 -0.9703 -0.9613 Columns 145 through 150 -0.9511 -0.9397 -0.9272 -0.9135 -0.8988 -0.8829 Columns 151 through 156 -0.8660 -0.8480 -0.8290 -0.8090 -0.7880 -0.7660 Columns 157 through 162 -0.7431 -0.7193 -0.6947 -0.6691 -0.6428 -0.6157 Columns 163 through 168 -

26、0.5878 -0.5592 -0.5299 -0.5000 -0.4695 -0.4384 Columns 169 through 174 -0.4067 -0.3746 -0.3420 -0.3090 -0.2756 -0.2419 Columns 175 through 180 -0.2079 -0.1736 -0.1392 -0.1045 -0.0698 -0.0349 Column 181 -0.0000 y2=cos(t)y2 =Columns 1 through 6 1.0000 0.9994 0.9976 0.9945 0.9903 0.9848 Columns 7 throu

27、gh 12 0.9781 0.9703 0.9613 0.9511 0.9397 0.9272 Columns 13 through 18 0.9135 0.8988 0.8829 0.8660 0.8480 0.8290 Columns 19 through 24 0.8090 0.7880 0.7660 0.7431 0.7193 0.6947 Columns 25 through 30 0.6691 0.6428 0.6157 0.5878 0.5592 0.5299 Columns 31 through 36 0.5000 0.4695 0.4384 0.4067 0.3746 0.3

28、420 Columns 37 through 42 0.3090 0.2756 0.2419 0.2079 0.1736 0.1392 Columns 43 through 48 0.1045 0.0698 0.0349 0.0000 -0.0349 -0.0698 Columns 49 through 54 -0.1045 -0.1392 -0.1736 -0.2079 -0.2419 -0.2756 Columns 55 through 60 -0.3090 -0.3420 -0.3746 -0.4067 -0.4384 -0.4695 Columns 61 through 66 -0.5

29、000 -0.5299 -0.5592 -0.5878 -0.6157 -0.6428 Columns 67 through 72 -0.6691 -0.6947 -0.7193 -0.7431 -0.7660 -0.7880 Columns 73 through 78 -0.8090 -0.8290 -0.8480 -0.8660 -0.8829 -0.8988 Columns 79 through 84 -0.9135 -0.9272 -0.9397 -0.9511 -0.9613 -0.9703 Columns 85 through 90 -0.9781 -0.9848 -0.9903

30、-0.9945 -0.9976 -0.9994 Columns 91 through 96 -1.0000 -0.9994 -0.9976 -0.9945 -0.9903 -0.9848 Columns 97 through 102 -0.9781 -0.9703 -0.9613 -0.9511 -0.9397 -0.9272 Columns 103 through 108 -0.9135 -0.8988 -0.8829 -0.8660 -0.8480 -0.8290 Columns 109 through 114 -0.8090 -0.7880 -0.7660 -0.7431 -0.7193

31、 -0.6947 Columns 115 through 120 -0.6691 -0.6428 -0.6157 -0.5878 -0.5592 -0.5299 Columns 121 through 126 -0.5000 -0.4695 -0.4384 -0.4067 -0.3746 -0.3420 Columns 127 through 132 -0.3090 -0.2756 -0.2419 -0.2079 -0.1736 -0.1392 Columns 133 through 138 -0.1045 -0.0698 -0.0349 -0.0000 0.0349 0.0698 Colum

32、ns 139 through 144 0.1045 0.1392 0.1736 0.2079 0.2419 0.2756 Columns 145 through 150 0.3090 0.3420 0.3746 0.4067 0.4384 0.4695 Columns 151 through 156 0.5000 0.5299 0.5592 0.5878 0.6157 0.6428 Columns 157 through 162 0.6691 0.6947 0.7193 0.7431 0.7660 0.7880 Columns 163 through 168 0.8090 0.8290 0.8

33、480 0.8660 0.8829 0.8988 Columns 169 through 174 0.9135 0.9272 0.9397 0.9511 0.9613 0.9703 Columns 175 through 180 0.9781 0.9848 0.9903 0.9945 0.9976 0.9994 Column 181 1.0000y=y1.*y2y =Columns 1 through 6 0 0.0349 0.0696 0.1040 0.1378 0.1710 Columns 7 through 12 0.2034 0.2347 0.2650 0.2939 0.3214 0.

34、3473 Columns 13 through 18 0.3716 0.3940 0.4145 0.4330 0.4494 0.4636 Columns 19 through 24 0.4755 0.4851 0.4924 0.4973 0.4997 0.4997 Columns 25 through 30 0.4973 0.4924 0.4851 0.4755 0.4636 0.4494 Columns 31 through 36 0.4330 0.4145 0.3940 0.3716 0.3473 0.3214 Columns 37 through 42 0.2939 0.2650 0.2

35、347 0.2034 0.1710 0.1378 Columns 43 through 48 0.1040 0.0696 0.0349 0.0000 -0.0349 -0.0696 Columns 49 through 54 -0.1040 -0.1378 -0.1710 -0.2034 -0.2347 -0.2650 Columns 55 through 60 -0.2939 -0.3214 -0.3473 -0.3716 -0.3940 -0.4145 Columns 61 through 66 -0.4330 -0.4494 -0.4636 -0.4755 -0.4851 -0.4924

36、 Columns 67 through 72 -0.4973 -0.4997 -0.4997 -0.4973 -0.4924 -0.4851 Columns 73 through 78 -0.4755 -0.4636 -0.4494 -0.4330 -0.4145 -0.3940 Columns 79 through 84 -0.3716 -0.3473 -0.3214 -0.2939 -0.2650 -0.2347 Columns 85 through 90 -0.2034 -0.1710 -0.1378 -0.1040 -0.0696 -0.0349 Columns 91 through

37、96 -0.0000 0.0349 0.0696 0.1040 0.1378 0.1710 Columns 97 through 102 0.2034 0.2347 0.2650 0.2939 0.3214 0.3473 Columns 103 through 108 0.3716 0.3940 0.4145 0.4330 0.4494 0.4636 Columns 109 through 114 0.4755 0.4851 0.4924 0.4973 0.4997 0.4997 Columns 115 through 120 0.4973 0.4924 0.4851 0.4755 0.463

38、6 0.4494 Columns 121 through 126 0.4330 0.4145 0.3940 0.3716 0.3473 0.3214 Columns 127 through 132 0.2939 0.2650 0.2347 0.2034 0.1710 0.1378 Columns 133 through 138 0.1040 0.0696 0.0349 0.0000 -0.0349 -0.0696 Columns 139 through 144 -0.1040 -0.1378 -0.1710 -0.2034 -0.2347 -0.2650 Columns 145 through

39、 150 -0.2939 -0.3214 -0.3473 -0.3716 -0.3940 -0.4145 Columns 151 through 156 -0.4330 -0.4494 -0.4636 -0.4755 -0.4851 -0.4924 Columns 157 through 162 -0.4973 -0.4997 -0.4997 -0.4973 -0.4924 -0.4851 Columns 163 through 168 -0.4755 -0.4636 -0.4494 -0.4330 -0.4145 -0.3940 Columns 169 through 174 -0.3716

40、 -0.3473 -0.3214 -0.2939 -0.2650 -0.2347 Columns 175 through 180 -0.2034 -0.1710 -0.1378 -0.1040 -0.0696 -0.0349 Column 181 -0.0000 plot(t,y y1 y2); w=0.1:0.1:2 以0.1为间隔从0.1到2w = Columns 1 through 6 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 Columns 7 through 12 0.7000 0.8000 0.9000 1.0000 1.1000 1.20

41、00 Columns 13 through 18 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 Columns 19 through 20 1.9000 2.0000 g1=(1+0.5*w*i)/(1-0.5*w*i)g1 =-1.0296g2=(1+0.5*w*i)./(1-0.5*w*i)g2 =Columns 1 through 6 -1.5000 -1.2222 -1.1429 -1.1053 -1.0833 -1.0690 Columns 7 through 12 -1.0588 -1.0513 -1.0455 -1.0408 -1.0370

42、-1.0339 Columns 13 through 18 -1.0313 -1.0290 -1.0270 -1.0253 -1.0238 -1.0225 Columns 19 through 20 -1.0213 -1.0202plot(g2) ;xlabel(real g2(w);横轴 ylabel(imag g2(w) ;竖轴axis(square);产生正方形坐标系(2) 多项式运算1)建立多项式向量ap=1 3 3 1a p=1 3 3 1 b=-1 -2 -3b = -1 -2 -3bp=poly(b)bp = 1 6 11 6以向量为解得特征方程或特征多项式2)练习多项式乘与求根p=conv(ap,bp)p =1 9 32 58 57 29 6两个多项式相乘再展开最后得到的系数就是conv得到的系数 roots(p)ans =-3.0000 -2.0000 -1.0003 -1.0000 + 0.0003i -1.0000 - 0.0003i -0.9997 方程p求根3)练习多项式运算a=1 2 3 4a = 1 2 3 4 b=1 -1b = 1 -1c=a+zeros(1,length(a)-length(b) bc =1 2 4 3Zero定义一个1行2列矩阵 与b再组成一

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论