試驗一MATLAB語言基礎(chǔ)實驗_第1頁
試驗一MATLAB語言基礎(chǔ)實驗_第2頁
試驗一MATLAB語言基礎(chǔ)實驗_第3頁
試驗一MATLAB語言基礎(chǔ)實驗_第4頁
試驗一MATLAB語言基礎(chǔ)實驗_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、 試驗一 MATLAB 語言基礎(chǔ)實驗(軟件仿真)1、 MATLAB的基本操作1、 實驗?zāi)康模?) 學(xué)習(xí)了解MATLAB語言環(huán)境(2) 練習(xí)MATLAB命令的基本操作(3) 練習(xí)m文件的基本操作2、 實驗內(nèi)容 (練習(xí)MATLAB命令的基本操作中的內(nèi)容)1)常規(guī)矩陣輸入>> a=1 2 3a = 1 2 3>> a=1;2;3a = 1 2 3>> b=1 2 5b = 1 2 5>> b=1 2 5;>> aa = 1 2 3>> a'ans = 1 2 3>> bb = 1 2 5>> b&

2、#39;ans = 1 2 5>> c=a*bc = 1 2 5 2 4 10 3 6 15>> c=a*b'? Error using => *Inner matrix dimensions must agree.>> a=1 2 3;4 5 6;7 8 0a = 1 2 3 4 5 6 7 8 0>> a2ans = 30 36 15 66 81 42 39 54 69>> a0.5ans = 0.5977 + 0.7678i 0.7519 + 0.0979i 0.5200 - 0.4680i 1.4102 + 0.

3、1013i 1.7741 + 0.6326i 1.2271 - 0.7467i 1.2757 - 1.0289i 1.6049 - 1.0272i 1.1100 + 1.6175i2)作循環(huán)命令程序>> makesum=0; for i=1:1:100 makesum=makesum+i; end>> makesummakesum = 50503)分別執(zhí)行下列命令>> a=1 2 3;4 5 6;7 8 0a = 1 2 3 4 5 6 7 8 0>> poly(a)ans = 1.0000 -6.0000 -72.0000 -27.0000&g

4、t;> rank(a)ans = 3>> det(a)ans = 27>> trace(a)ans = 6>> inv(a)ans = -1.7778 0.8889 -0.1111 1.5556 -0.7778 0.2222 -0.1111 0.2222 -0.1111>> eig(a)ans = 12.1229 -0.3884 -5.73454)練習(xí)m文件的基本操作>> penddemo倒立擺控制系統(tǒng):二、MATLAB的數(shù)值運算1、 實驗?zāi)康模?) 學(xué)習(xí)MATLAB語言的基本矩陣運算(2) 學(xué)習(xí)MATLAB語言的點運算(3)

5、學(xué)習(xí)復(fù)雜運算2、 實驗內(nèi)容(1) 基本矩陣運算1)創(chuàng)建數(shù)值矩陣>>a=1 2 3;4 5 6;7 8 9;>> aa = 1 2 3 4 5 6 7 8 9>> a(3,2)ans = 8>> a(:,1)ans = 1 4 7>>t=0:10t = Columns 1 through 10 0 1 2 3 4 5 6 7 8 9 Column 11 10>> u=0:0.1:10u = Columns 1 through 6 0 0.1000 0.2000 0.3000 0.4000 0.5000 Columns 7 t

6、hrough 12 0.6000 0.7000 0.8000 0.9000 1.0000 1.1000 Columns 13 through 18 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 Columns 19 through 24 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000 Columns 25 through 30 2.4000 2.5000 2.6000 2.7000 2.8000 2.9000 Columns 31 through 36 3.0000 3.1000 3.2000 3.3000 3.4000

7、 3.5000 Columns 37 through 42 3.6000 3.7000 3.8000 3.9000 4.0000 4.1000 Columns 43 through 48 4.2000 4.3000 4.4000 4.5000 4.6000 4.7000 Columns 49 through 54 4.8000 4.9000 5.0000 5.1000 5.2000 5.3000 Columns 55 through 60 5.4000 5.5000 5.6000 5.7000 5.8000 5.9000 Columns 61 through 66 6.0000 6.1000

8、6.2000 6.3000 6.4000 6.5000 Columns 67 through 72 6.6000 6.7000 6.8000 6.9000 7.0000 7.1000 Columns 73 through 78 7.2000 7.3000 7.4000 7.5000 7.6000 7.7000 Columns 79 through 84 7.8000 7.9000 8.0000 8.1000 8.2000 8.3000 Columns 85 through 90 8.4000 8.5000 8.6000 8.7000 8.8000 8.9000 Columns 91 throu

9、gh 96 9.0000 9.1000 9.2000 9.3000 9.4000 9.5000 Columns 97 through 101 9.6000 9.7000 9.8000 9.9000 10.0000>>a(:,3)=2;3;4a = 1 2 2 4 5 3 7 8 4>>b=1 1+2i;3+4i 3b = 1.0000 1.0000 + 2.0000i 3.0000 + 4.0000i 3.0000 2)創(chuàng)建特殊矩陣 >> a=ones(3,3)a = 1 1 1 1 1 1 1 1 1>> b=zeros(2,2)b = 0 0

10、 0 0>> c=eye(4)c = 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 13)練習(xí)矩陣運算>>a=0 1 0;0 0 1;-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

11、-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.0000 - 0.2696i 0.0000 + 1.6179i 0.0000 + 3.2553i 0.0000 + 2.6374i>> a

12、1=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>> a3=a(1:2,2:3)+c*ba3 = 5 6 8 11>> ar=c/aar = -0.8333 -1.0000 -0.1667 1.0000 1.0000 0>> al=abal = -5.6667 -8.6667 1.0000 2.0000 3.0000 4.00004)練習(xí)矩陣特征運算>> a'ans = 0 0 -6 1 0 -11 0 1 -6>> inv(a)ans

13、= -1.8333 -1.0000 -0.1667 1.0000 0 0 0 1.0000 0>> diag(a)ans = 0 0 -6>> tril(a)ans = 0 0 0 0 0 0 -6 -11 -6>> inv(a)ans = -1.8333 -1.0000 -0.1667 1.0000 0 0 0 1.0000 0>> poly(a)ans = 1.0000 6.0000 11.0000 6.0000>> rank(a)ans = 3>> det(a)ans = -6>> trace(a)ans

14、 = -6>> eig(a)ans = -1.0000 -2.0000 -3.0000(2) MATLAB語言點的運算1)練習(xí)點乘與點除>>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./a2ans = 0.2000 0.8000 5.0000 5.0000 1.8000 3.2000 5.0000 5.00002)由點運算完成標(biāo)量函數(shù)運算與作圖>>t=0:2

15、*pi/180:2*pit = 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 0.6283 0.6632 0.6981 0.7330 0.7679 0.8029 Columns 25 through 30 0.8378 0.8727

16、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 Columns 49 through 54 1.6755 1.7104 1.7453 1.7802 1.8151 1.8500 Columns 55 throu

17、gh 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.6180 2.6529 2.6878 Columns 79 through 84 2.7227 2.7576 2.7925 2.8274 2.8623 2.8

18、972 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.5605 3.5954 3.6303 3.6652 3.7001 3.7350 Columns 109 through 114 3.7699 3.8048

19、 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.5728 Columns 133 through 138 4.6077 4.6426 4.6775 4.7124 4.7473 4.7822 Columns

20、 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 5.4803 5.5152 5.5501 5.5851 5.6200 Columns 163 through 168 5.6549 5.6898 5.724

21、7 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.2832>>y1=sin(t)y1 = Columns 1 through 6 0 0.0349 0.0698 0.1045 0.1392 0.1736 Columns 7 through 12 0.2079 0.2419 0.2756 0.3090

22、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.8660 0.8829 0.8988 0.9135 0.9272 0.9397 Columns 37 through 42 0.9511 0

23、.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 Columns 61 through 66 0.8660 0.8480 0.8290 0.8090 0.7880 0.7660 Columns 67

24、 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 0.0698 0.0349 Columns 91 through 96 0.0000 -0.0349 -0.0698 -0.1045 -

25、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 Columns 115 through 120 -0.7431 -0.7660 -0.7880 -0.8090 -0.8290 -0.848

26、0 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 through 144 -0.9945 -0.9903 -0.9848 -0.9781 -0.9703 -0.9613 Columns 14

27、5 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 -0.5878 -0.5592 -0.5299 -0.5000 -0.4695 -0.4384 Columns 169 through 17

28、4 -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 through 12 0.9781 0.9703 0.9613 0.9511 0.9397 0.9272 Columns 13 t

29、hrough 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.3420 Columns 37 through 42 0.3090 0.2756 0.2419 0.2079 0.1736

30、 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.5000 -0.5299 -0.5592 -0.5878 -0.6157 -0.6428 Columns 67 throu

31、gh 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 -0.9945 -0.9976 -0.9994 Columns 91 through 96 -1.0000 -0.999

32、4 -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 -0.6947 Columns 115 through 120 -0.6691 -0.6428 -0.6157 -0.

33、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 Columns 139 through 144 0.1045 0.1392 0.1736 0.2079 0.2419 0.2756

34、 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.8480 0.8660 0.8829 0.8988 Columns 169 through 174 0.9135 0.92

35、72 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.0000>>y=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.3473 Columns 13 through 18 0.3716 0.3940 0.4145 0.4

36、330 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.2347 0.2034 0.1710 0.1378 Columns 43 through 48 0.10

37、40 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 Columns 67 through 72 -0.4973 -0.4997 -0.4997 -0.4

38、973 -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 96 -0.0000 0.0349 0.0696 0.1040 0.1378 0.1710 Colum

39、ns 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.4636 0.4494 Columns 121 through 126 0.4330 0.4145 0.39

40、40 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 150 -0.2939 -0.3214 -0.3473 -0.3716 -0.3940 -0.414

41、5 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 -0.3473 -0.3214 -0.2939 -0.2650 -0.2347 Columns 17

42、5 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: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.2000 Columns 13 through 18 1.3000 1.

43、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.0296>>g2=(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 -1.0339 Columns

44、13 through 18 -1.0313 -1.0290 -1.0270 -1.0253 -1.0238 -1.0225 Columns 19 through 20 -1.0213 -1.0202>>plot(g2)>>xlabel('real g2(w)')>>ylabel('imag g2(w)')>>axis('square')(3) 多項式運算1)建立多項式向量>>ap=1 3 3 1a p= 1 3 3 1>> b=-1 -2 -3b = -1 -2 -3>

45、>bp=poly(b)bp = 1 6 11 62)練習(xí)多項式乘與求根>>p=conv(ap,bp)p = 1 9 32 58 57 29 6>> roots(p)ans = -3.0000 -2.0000 -1.0003 -1.0000 + 0.0003i -1.0000 - 0.0003i -0.9997 3)練習(xí)多項式運算>>a=1 2 3 4a = 1 2 3 4>> b=1 -1b =1 -1>>c=a+zeros(1,length(a)-length(b) bc = 1 2 4 3>>poly2str(c,'x')ans = x3 + 2 x2 + 4 x + 3>> polyvalm(a,3)ans =583、 MATLAB的符號運算1、 實驗?zāi)康模?) 學(xué)習(xí)MATLAB語言的基本符號運算(2) 學(xué)習(xí)MATLAB語言的矩陣符號運算2、 實驗內(nèi)容(1) 基本符號運算1)符號微分、積分>>syms t>> f1=sin(2*t)f1 =sin(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論