




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、第一章 實(shí)驗(yàn)內(nèi)容1.2.例1-1 x=0:0.5:360*pi/180;plot(x,sin(x),x,cos(x);例1-2 p=3,7,9,0,-23; x=roots(p) x = -1.8857 -0.7604 + 1.7916i -0.7604 - 1.7916i 1.0732 例1-3 quad(x.*log(1+x),0,1)ans =0.2500例 1-4 a=2,-3,1;8,3,2;45,1,-9; b=4;2;17; x=inv(a)*bx = 0.4784 -0.87930.40543.(1)help inv inv Matrix inverse. inv(X) is
2、the inverse of the square matrix X. A warning message is printed if X is badly scaled ornearly singular(2)help plot plot Linear plot. plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a sca
3、lar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X(3)help max max Largest component. For vectors, max(X) is the largest element in X. For matrices, max(X) is a row vector containing the maximum element from each column. For N-D arrays, max(X)
4、operates along the firstnon-singleton dimension.(4)help round round Round towards nearest integer.round(X) rounds the elements of X to the nearest integers.4.(1) x=0:pi/10:2*pi;y=sin(x)y = Columns 1 through 10 0 0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 0.3090 Columns 11 through 20 0.0
5、000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878 -0.3090 Column 21 -0.0000(2)根據(jù)提示操作,選擇y變量,并繪制y圖形,生成了如下圖形,圖形是一個(gè)正弦函數(shù)圖像。思考練習(xí)1.與其他窗口程序的啟動(dòng)與退出類似,雙擊圖標(biāo)打開,單擊X圖標(biāo)關(guān)閉2. MATLAB是矩陣實(shí)驗(yàn)室(Matrix Laboratory)的簡(jiǎn)稱用于算法開發(fā)、數(shù)據(jù)可視化、數(shù)據(jù)分析以及數(shù)值計(jì)算的高級(jí)技術(shù)計(jì)算語言和交互式環(huán)境。它將數(shù)值分析、矩陣計(jì)算、科學(xué)數(shù)據(jù)可視化以及非線性動(dòng)態(tài)系統(tǒng)的建模和仿真等諸多強(qiáng)大功能集成在一個(gè)易于使用的視
6、窗環(huán)境中,為科學(xué)研究、工程設(shè)計(jì)以及必須進(jìn)行有效數(shù)值計(jì)算的眾多科學(xué)領(lǐng)域提供了一種全面的解決方案。3.如果一個(gè)命令行很長,需要分成多行輸入,可以在第一個(gè)物理行之后加上三個(gè)小黑點(diǎn)并按下enter鍵,然后接著在下一個(gè)物理航繼續(xù)輸入命令的其他部分。三個(gè)小黑點(diǎn)稱為續(xù)行符,即把下面的物理行看作該行的邏輯繼續(xù)。4.help命令只搜索出那些與關(guān)鍵字完全匹配的結(jié)果,lookfor命令對(duì)搜索范圍內(nèi)的小文件進(jìn)行關(guān)鍵字搜索,條件比較寬松。5.假如建立了一個(gè)變量fac,同時(shí)在當(dāng)前目錄下建立了一個(gè)M文件fac.m文件。如果在命令窗口輸入fac,按照MATLAB的搜索順序,應(yīng)該在屏幕上顯示fac的值。如果沒有建立fac變量,
7、則執(zhí)行fac.m文件。第二章 實(shí)驗(yàn)指導(dǎo) 1.(1)w=sqrt(2)*(1+0.34245*10-6)w = 1.4142(2)a=3.5; b=5; c=-9.8 x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2)/(tan(b+c)+a)x =0.9829(3) a=3.32; b=-7.9; y=2*pi*a2*(1-pi/4)*b-(0.8333-pi/4)*a)y = -128.4271(4) t=2,1-3*i;5,-0.65t = 2.0000 1.0000 - 3.0000i 5.0000 -0.6500 z=0.5*exp(2*t)*log(t+sqrt(1+
8、t2)z = 1.0e+04 * 0.0057 - 0.0007i 0.0049 - 0.0027i 1.9884 - 0.3696i 1.7706 - 1.0539i2.A=-1,5,-4;0,7,8;3,61,7;B=8,3,-1;2,5,3;-3,2,0;(1)A+6*Bans = 47 23 -10 12 37 26 -15 73 7A2-B+eyeans = -18 -216 18 23 533 11022 868 526(2) A*Bans = 14 14 16 -10 51 21 125 328 180 A.*Bans = -8 15 4 0 35 24 -9 122 0 B*A
9、ans = -11 0 -15 7 228 53 3 -1 28(3) A/Bans = 1.2234 -0.9255 2.9787 -0.9468 2.3511 -0.9574 4.6170 3.8723 13.8936 BAans = -0.5106 -8.6170 -1.1277 0.7340 17.5745 1.8085 -0.8830 -21.2128 0.4043(4) A,Bans = -1 5 -4 8 3 -1 0 7 8 2 5 3 3 61 7 -3 2 0 A(1,3,:);B2ans = -1 5 -4 3 61 7 73 37 1 17 37 13 -20 1 93
10、. A=23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9,54,3.14 23.0000 10.0000 -0.7780 0 41.0000 -45.0000 65.0000 5.0000 32.0000 5.0000 0 32.00006.0000 -9.0000 54.0000 3.1400(1) k=find(10=A&A C=A(:,1:2)C = 23 10 41 -45 32 5 6 -9 D=A(2:4,3:4)D = 65.0000 5.0000 0 32.0000 54.0000 3.1400 E=B*CE = 1.0e+03 * 0.914
11、1 -0.2239 1.2080 2.71501.1330 -0.1930(3) E E&Dans = 1 1 0 1 1 1 E|Dans = 1 1 1 1 1 1Eans = 0 0 0 0 0 0 Dans = 0 0 1 0 0 04. H=hilb(5); P=pascal(5); Hh=det(H) Hh = 3.7493e-012 Hp=det(P) Hp = 1 Th=cond(H) Th = 4.7661e+005 Tp=cond(P) Tp = 8.5175e+003 條件數(shù)越趨近于1,矩陣的性能越好,所以帕斯卡矩陣性能更好。5. A=-29,6,18;20,5,12;-
12、8,8,5A= -2961820512-885V,D=eig(A)V= 0.71300.28030.2733 -0.6084-0.78670.87250.34870.55010.4050D= -25.316900 0-10.51820 0016.8351V為A的特征向量,D為A的特征值。它們之間滿足A*V=V*D思考練習(xí)1. 在MATLAB中6+7i是一個(gè)復(fù)數(shù)常量,6+7*i則是一個(gè)表達(dá)式。i是虛數(shù)單位,而I是單 位向量。 2. A.*B表示A和B單個(gè)元素之間對(duì)應(yīng)相乘,A*B是按矩陣乘法的規(guī)則乘。 A./B表示A矩陣除以B矩陣的對(duì)應(yīng)元素,B.A等價(jià)于A./B。 A/B表示A *inv(B)而B
13、A表示inv(B)* A,對(duì)于矩陣運(yùn)算一般兩式不等。 3.(1) A(7)= (2) abs(x) (3) reshape(x,3,4) (4) k=find(t=0); t(k)=0(5) ones(size(A) (6) diag(A) B= diag(diag(A) 4. 3+randn(25,20) 5.(1) A=1,-1,2,-3;5,1,-4,2;3,0,5,2;11,15,0,9A = 1 -1 2 -3 5 1 -4 2 3 0 5 2 11 15 0 9 diag(A)ans = 1 1 5 9 triu(A)ans = 1 -1 2 -3 0 1 -4 2 0 0 5 2
14、 0 0 0 9 tril(A)ans = 1 0 0 0 5 1 0 0 3 0 5 0 11 15 0 9 inv(A)ans = 0.1308 0.1395 0.0593 -0.0006 0.0785 -0.1163 -0.1244 0.0797 0.0378 -0.0930 0.1105 0.0087 -0.2907 0.0233 0.1349 -0.0209 det(A)ans = -1.7200e+03 rank(A)ans = 4 norm(A,1)ans =20 norm(A,2)ans = 21.3196 norm(A,inf)ans = 35 cond(A,1)ans =
15、10.7558 cond(A)ans = 7.6905 cond(A,inf)ans = 16.4419 trace(A)ans =16(2) B=0.43,43,2;-8.9,4,21B = 0.4300 43.0000 2.0000 -8.9000 4.0000 21.0000 diag(B)ans = 0.4300 4.0000 triu(B)ans = 0.4300 43.0000 2.0000 0 4.0000 21.0000 tril(B)ans = 0.4300 0 0 -8.9000 4.0000 0 inv(B)Error using invMatrix must be sq
16、uare. det(B)Error using detMatrix must be square. rank(B)ans = 2 norm(B,1)ans = 47 norm(B,2)ans = 43.4271 norm(B,inf)ans = 45.4300 cond(B,1)Error using cond (line 35)A is rectangular. Use the 2 norm. cond(B,2)ans = 1.9354 cond(B,inf)Error using cond (line 35)A is rectangular. Use the 2 norm.lo9 trac
17、e(B)Error using trace (line 13)Matrix must be square.6. A=34,NaN,Inf,-Inf,-pi,eps,0; all(A)ans = 0 any(A)ans = 1 isnan(A)ans = 0 1 0 0 0 0 0 isinf(A)ans = 0 0 1 1 0 0 0 isfinite(A)ans = 1 0 0 0 1 1 17.結(jié)構(gòu)矩陣,結(jié)構(gòu)矩陣名.成員名=表達(dá)式,其中表達(dá)式應(yīng)理解為矩陣表達(dá)式 建立單元矩陣和一般矩陣相似,只是矩陣元素用大括號(hào)括起來。8用稀疏存儲(chǔ)方式可以可以節(jié)省內(nèi)存空間; 運(yùn)算規(guī)則上,稀疏矩陣與普通矩陣一樣
18、,只是矩陣的存儲(chǔ)方式不同。在運(yùn)算過程中,稀疏存儲(chǔ)矩陣可以直接參與運(yùn)算。當(dāng)參與運(yùn)算的對(duì)象不全是稀疏存儲(chǔ)矩陣時(shí),所得結(jié)果一般是完全存儲(chǔ)形式。第三章 實(shí)驗(yàn)指導(dǎo)1. n = input(n請(qǐng)輸入一個(gè)任意三位數(shù):);if n = 1000 | fix(n) = n error(輸入不合要求,請(qǐng)輸入三位整數(shù)。)enddig = (k)rem(fix(n/10k),10);n1 = arrayfun(dig,0:2);fprintf(反向結(jié)果是:%i%i%in,n1)請(qǐng)輸入一個(gè)任意三位數(shù):369反向結(jié)果是:9632.(1)用if 語句實(shí)現(xiàn) x=input(輸入一個(gè)百分制成績);if x=90;disp(A)
19、; elseif x=80;disp(B); elseif x=70 disp(C); elseif x=60; disp(D); else disp (E)end輸入一個(gè)百分制成績89B用switch語句實(shí)現(xiàn)x=input(輸入一個(gè)百分制成績); switch fix(x/10)case 9,10 disp(A);case 8disp(B)case 7disp(C)case6disp (D)otherwisedisp(E)end輸入一個(gè)百分制成績56E3、a=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20b=max(a)c=min(a)b
20、=0c=0for i=1:20 if a(i)b b=a(i); end if a(i)5 n=5 a(n,:) disp(輸入超出范圍);else a(n,:)end 請(qǐng)輸入一個(gè)數(shù):5ans = 0.8913 0.4447 0.1763 0.8936 0.1389 0.1988請(qǐng)輸入一個(gè)數(shù):6n = 5ans = 0.4660 0.6721 0.8318 0.1897 0.1509 0.5936輸入超出范圍7、f1.m 代碼如下function m=f1(n)m=n+10*log(n2+5);f2.m 代碼如下:function m=f2(n)m=0;for i=1:nm=m+i*(i+1)
21、;end在command界面中輸入:y1=f1(40)/(f1(30)+f1(20)y1 = 0.6390 y2=f2(40)/(f2(30)+f2(20)y2 =1.76628、函數(shù)文件factor1.m代碼如下:function f=factor1(k)if k=1f=1;elsef=factor1(k-1)+k;end函數(shù)文件factor2.m代碼如下:function f=factor2(k)if k=1f=1;elsef=factor2(k-1)2+k2;end函數(shù)文件factor3.m代碼如下:function f=factor3(k)if k=1f=1;else f=factor
22、31/(k-1)+1/k;end 思考練習(xí)1、用MATLAB語言編寫的程序稱為M文件。書P57下部。2、N=1,2,3,4,5N = 1 2 3 4 5 A=N.*2A = 2 4 6 8 10 B=N./4B = 0.2500 0.5000 0.7500 1.0000 1.2500 C=1./NC = 1.0000 0.5000 0.3333 0.2500 0.2000 D=1./(N./2)./(N./2)/4D =1.0000 0.2500 0.1111 0.0625 0.04003、M文件B=0;for i=1:20A(i)=fix(99-10+1)*rand(1)+10);B=A(i
23、)+B;endB=B/20;for i=1:20if A(i) factor3輸入一個(gè)數(shù)1000A = 0.9995 factor3輸入一個(gè)數(shù)10000A =0.9999(2)M文件A=0;n=input(輸入一個(gè)數(shù));for i=1:1000A=1/(4)i)+A;endA輸出結(jié)果:輸入一個(gè)數(shù)10000A = 0.9999 factor3輸入一個(gè)數(shù)100A = 0.3333 factor3輸入一個(gè)數(shù)1000A = 0.3333 factor3輸入一個(gè)數(shù)10000A =0.33335、M文件function m,n=chengji(A,B)m=A.*B;n=A*B;輸出程序及結(jié)果: a=1 2
24、 3;4 5 6;7 8 9; b=-1 0 1;1 -1 0;0 1 1m,n=chengji(a,b);disp(a.*b=);disp(m);disp(a*b= );disp(n);b = -1 0 1 1 -1 0 0 1 1a.*b= -1 0 3 4 -5 0 0 8 9a*b= 1 1 4 1 1 10 1 1 16第四章 實(shí)驗(yàn)指導(dǎo)1.(1)t=-5:0.1:5y=t-t.3/6plot(t,y)(2)t=-10:0.1:10x=sin(t)/8y=cos(t)/sqrt(32)plot(x,y)2.t=-pi:pi/50:piy=(1+exp(-t).(-1)subplot(2
25、,2,1)bar(t,y,g)title(bar(t,y,b);axis(-4,4,0,1)subplot(2,2,2);stairs(t,y,b)title(stairs(t,y,b);axis(-4,4,0,1)subplot(2,2,3);stem(t,y,k)title(stem(t,y,k);axis(-4,4,0,1) subplot(2,2,4);loglog(t,y,m);title(loglog(t,y,m)3.(1)t=-pi:pi/50:pir=5*cos(t)+4polar(t,r,-*)(2)t=-pi/3:pi/50:pi/3r=5*sin(t).*sin(t).*
26、(cos(t).(-1)polar(t,r,-*)4.(1)t=0:pi/50:2*pix=exp(-t/20).*cos(t)y=exp(-t/20).*sin(t)z=tplot3(x,y,z)title(Line in 3-D Space)xlabel(X);ylabel(Y);zlabel(Z)grid on思考練習(xí)2.(1) t=-4:0.1:4y=exp(-0.5*(t).2)plot(t,y)(2)t=-2*pi:pi/50:2*pix=t.*sin(t)y=t.*cos(t)plot(x,y)3.x=-1:0.1:1y1=2*x-0.5plot(x,y1)hold onm=0:
27、pi/50:pit=sin(3*m).*cos(m)y2=sin(3*m).*sin(m)plot(t,y2)hold off4.(1)plot格式:x=-pi:pi/50:piy=sin(1/x)y=sin(x).(-1)plot(x,y)(2) fplot格式:fplot(x).(-1),-0.01,0.01,1e-4)(3) 比較,plot格式的曲線會(huì)比較直觀看到曲線在某一范圍的變化以及曲線走向,但是fplot格式的曲線則是非常簡(jiǎn)化的描述了曲線的主要部分5.(1)t=-4*pi:pi/50:4*pir=12*t.(-0.5)polar(t,r,-*)(2)t=-pi/6:pi/100:p
28、i/6r=3*a*sin(t).*cos(t).*(sin(t).3+(cos(t).3)polar(t,r,-*)6.(1)x,y=meshgrid(-8:0.1:8)z=4*(x.2+y.2)/13mesh(x,y,z)(2)x,y=meshgrid(-3:0.1:3)z=-5*(1+x.2+y.2).(-1)mesh(x,y,z)第五章 實(shí)驗(yàn)指導(dǎo)1.(1)A=randn(10,5)A = 0.0983 2.2294 0.0662 0.0000 1.1921 0.0414 0.3376 0.6524 -0.0549 -1.6118 -0.7342 1.0001 0.3271 0.9111 -0.0245 -0.0308 -1.6642 1.0826 0.5946 -1.9488 0.2323 -0.5900 1.0061 0.3502 1.0205 0.4264 -0.2781 -0.6509 1.2503 0.8617 -0.3728 0.4227 0.2571 0.9298 0.0012 -0.2365 -1.6702 -0.9444 0.2398 -0.0708 2.0237 0.4716 -1.3218 -0.6904 -2.4863 -2.2584 -1.2128 0.9248 -0.6516 0.5812 mean(A
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 廣西特產(chǎn)購銷協(xié)議書
- 拆除球場(chǎng)重建協(xié)議書
- 房屋轉(zhuǎn)移互換協(xié)議書
- 店面合同解除協(xié)議書
- 指尖傳媒就業(yè)協(xié)議書
- 拆除設(shè)施補(bǔ)償協(xié)議書
- 廣告信息發(fā)布協(xié)議書
- 整車出口資質(zhì)協(xié)議書
- 畜牧場(chǎng)消毒防疫補(bǔ)充協(xié)議
- 海外留學(xué)咨詢服務(wù)合伙人合作協(xié)議
- 第四課:印巴戰(zhàn)爭(zhēng)
- 電氣設(shè)備-開篇緒論匯編
- 武漢綠地中心項(xiàng)目技術(shù)管理策劃書(48頁)
- 婚無遠(yuǎn)慮必有財(cái)憂法商思維營銷之婚姻篇74張幻燈片
- 紅外圖像處理技術(shù)課件
- 小學(xué)一年級(jí)人民幣學(xué)具圖片最新整理直接打印
- 投擲:原地投擲壘球
- 港口碼頭常用安全警示標(biāo)志
- 密閉式周圍靜脈輸液技術(shù)PPT課件
- 電梯快車調(diào)試方法
- 主要材料損耗率表
評(píng)論
0/150
提交評(píng)論