




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、會(huì)計(jì)學(xué)1數(shù)組及運(yùn)算課時(shí)數(shù)組及運(yùn)算課時(shí)Matlab及其應(yīng)用2第1頁(yè)/共36頁(yè)Matlab及其應(yīng)用3第2頁(yè)/共36頁(yè)Matlab及其應(yīng)用4第3頁(yè)/共36頁(yè)Matlab及其應(yīng)用5xxey10 xx為一維數(shù)組涉及數(shù)組的運(yùn)算為“點(diǎn)運(yùn)算”第4頁(yè)/共36頁(yè)Matlab及其應(yīng)用6第5頁(yè)/共36頁(yè)Matlab及其應(yīng)用7%This segment demonstrate the creation of 1-D numerical arraya=2 pi/2 sqrt(3) 3+5ib=0:2:20c=2:12d=0:1.5:10e=linspace(1.1,9.6,12)f=logspace(2,4,11)%Th
2、is segment demonstrate the access of 1-D numerical arrayx1=a(3)x2=a(1)/b(3)x3=c(2 4 6)x4=d(2:6)x5=e(10:-2:1)x6=e(find(e5)x7=f(1 3 5 7 8 6 4 2)%This segment demonstrate the assignment of 1-D numerical arrayx3(2)=0 x4(1 3 5)=0 0 0 x4(2 4)=0第6頁(yè)/共36頁(yè)Matlab及其應(yīng)用8“邏輯1”標(biāo)識(shí)(確切說(shuō)不是標(biāo)識(shí),而是邏輯數(shù)組應(yīng)用)n尋訪與賦值第7頁(yè)/共36頁(yè)Matl
3、ab及其應(yīng)用9%-Creation of the 2-D array-a=3;b=5;c=1 a a+b*i b;pi sin(pi) b*i id=c;e=c(:,1:2)+i*d(1:2,:)narr3; %call script M-file am%-Access of the 2-D array-f=am(2,3)g=am(2:4:16) %按行顯,按列存h=am(:,2)k=am(:)%-Assignment of the 2-D array-am(3,2)=0am(2 8 12)=0 0 0am(:)=0%-This is the scripts to create the 2-D
4、 array-am=1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16;第8頁(yè)/共36頁(yè)Matlab及其應(yīng)用10第9頁(yè)/共36頁(yè)Matlab及其應(yīng)用11第10頁(yè)/共36頁(yè)Matlab及其應(yīng)用12 數(shù)組運(yùn)算 矩陣運(yùn)算 指令 含義 指令 含義 A. 非共軛轉(zhuǎn)置 A 共軛轉(zhuǎn)置 A.n A元素的n次冪 An 矩陣自乘n次 pAp為底A元素為冪 pA 標(biāo)量的A乘方 A./BA,B對(duì)應(yīng)元素除 A/B A右除B B.A 與上面等價(jià) BAA左除B,于上不同exp(A)e為底A元素為指數(shù)expm(A) A的矩陣指數(shù)函數(shù)log(A)A的元素求對(duì)數(shù)logm(A) A的矩陣對(duì)數(shù)函數(shù)sqrt(
5、A)A元素求平方根sqrtm(A) A的陣平方根函數(shù) A#BA、B對(duì)應(yīng)元素間的關(guān)系運(yùn)算,#運(yùn)算符。 ABA、B對(duì)應(yīng)元素間的邏輯運(yùn)算,邏輯符。第11頁(yè)/共36頁(yè)Matlab及其應(yīng)用13第12頁(yè)/共36頁(yè)Matlab及其應(yīng)用14%-methods of diag-a=diag(2 3 4 5)b=diag(2 3,-1)x=diag(b)u=diag(b,-1)%-methods of eye-c=eye(3)d=eye(3,2)e=eye(size(a)%-methods of magic-f=magic(3)%-methods of ones-g=ones(3)h=ones(2,3)k=one
6、s(size(a)%-methods of zeros-l=zeros(3)m=zeros(2,3)n=zeros(size(a)%-methods of rand-%The rand function generates arrays of random % numbers whose elements are%uniformly distributed in the interval (0,1).o=rand(3)p=rand(3,4)q=rand(size(a)y = 10; z = 50;randnum = y + (z-y) * rand(5)%-methods of randn-%
7、The randn function generates arrays of % random numbers whose elements are %normally distributed with mean 0, variance and % standard deviation are 1.r=randn(3)s=randn(3,4)t=randn(size(a)第13頁(yè)/共36頁(yè)Matlab及其應(yīng)用15A=reshape(1:9,3,3)A(5,5)=21A(:,6)=12A=A(:,1:6,1:6)B=ones(2,12)AB=A;BC=zeros(5,2)AC=A,C第14頁(yè)/共
8、36頁(yè)Matlab及其應(yīng)用16 指令 含義 cat把大小相同的數(shù)組,按某一方向迭加為高維數(shù)組 diag提取對(duì)角線元素,或生成對(duì)角陣。 flipud以數(shù)組水平中線翻轉(zhuǎn)180 fliplr以數(shù)組垂直中線翻轉(zhuǎn)180 kron按 Kronecker 乘法產(chǎn)生 “積” 數(shù)組 repmat按指定行或列鋪放數(shù)組,以形成更大的數(shù)組 reshape在總元素不變的情況下,改變數(shù)組的大小 rot90逆時(shí)針旋轉(zhuǎn)二維數(shù)組90 tril提取數(shù)組下三角部分,并生成下三角陣 triu提取數(shù)組上三角部分,并生成上角陣第15頁(yè)/共36頁(yè)Matlab及其應(yīng)用17a=-4:4b=reshape(a,3,3)c=b+i*bd=be=c
9、f=flipud(b) %flip up and downg=fliplr(b) %flip left and righth=cat(1,f,g) %cat the f and g in the 1st dimension,Columnk=cat(2,f,g) %cat the f and g in the 2nd dimension,Rowl=cat(3,f,g) %cat the f and g in the 3rd dimension%K = kron(X,Y) returns the Kronecker tensor product of X and Y%If X is 2-by-3,
10、 then kron(X,Y) is % X(1,1)*Y X(1,2)*Y X(1,3)*Y% X(2,1)*Y X(2,2)*Y X(2,3)*Y m=kron(d,g)n=kron(g,d)%B = repmat(A,m,n) creates a large matrix B consisting of an %m-by-n tiling of copies of Ap=repmat(b,2,2)第16頁(yè)/共36頁(yè)Matlab及其應(yīng)用18第17頁(yè)/共36頁(yè)Matlab及其應(yīng)用19t=-2*pi:pi/10:2*pi;y=sin(t)./t; %dot divide array opera
11、tion, view the creation of NaN at t=0z=(t=0) %view the creation of logical arraytt=t+z*eps; %eps is the machine zeroyy=sin(tt)./tt;subplot(1,2,1),plot(t,y,r),axis(-7,7,-0.5,1.2),xlabel(t),ylabel=(y),title(figure with flaw)subplot(1,2,2),plot(tt,yy,b),axis(-7,7,-0.5,1.2),xlabel(tt),ylabel=(yy),title(
12、normal figure )r=randn(3,6)logic=abs(r)1.5r(logic)=0s=(find(r=0)r(s)=11i,j=find(r=11);disp(i),disp(j)第18頁(yè)/共36頁(yè)Matlab及其應(yīng)用20t=linspace(0,3*pi,500);y=sin(t); %生成正弦波z1=(t2*pi).*y; %對(duì)t在(0,pi)和(2*pi,3*pi)范圍進(jìn)行數(shù)組運(yùn)算,其余為0w=(tpi/3 & t7*pi/3 & t8*pi/3); %取(pi/3,2*pi/3)和(7*pi/3 , 8*pi/3)范圍wn=w; %對(duì)w作 非 邏輯
13、運(yùn)算z2=w*sin(pi/3)+wn.*z1; %對(duì)正弦波削頂subplot(1,3,1),plot(t,y,r,LineWidth,3),ylabel(y)subplot(1,3,2),plot(t,z1,b,LineWidth,3),axis(0 10 -1 1)subplot(1,3,3),plot(t,z2,g,LineWidth,3),axis(0 10 -1 1)第19頁(yè)/共36頁(yè)Matlab及其應(yīng)用21函函 數(shù)數(shù)功功 能能all如果所有的元素都是非零值,返回如果所有的元素都是非零值,返回1;否則,返回;否則,返回0。any如果有一個(gè)元素為非零值,那么返回如果有一個(gè)元素為非零值,
14、那么返回1;否則,返回;否則,返回0isempty判斷是否空矩陣判斷是否空矩陣isequal判斷兩矩陣是否相同判斷兩矩陣是否相同isreal判斷是否是實(shí)矩陣判斷是否是實(shí)矩陣find返回一個(gè)由非零元素的下標(biāo)組成的向量返回一個(gè)由非零元素的下標(biāo)組成的向量isfinite判斷各元素是否有限數(shù)判斷各元素是否有限數(shù)isinf判斷各元素是否無(wú)窮大判斷各元素是否無(wú)窮大isletter判斷各元素是否字符判斷各元素是否字符isnan判斷各元素是否判斷各元素是否“非數(shù)非數(shù)”isprime判斷各元素是否質(zhì)數(shù)判斷各元素是否質(zhì)數(shù)isspace判斷各元素是否空格判斷各元素是否空格第20頁(yè)/共36頁(yè)Matlab及其應(yīng)用22第
15、21頁(yè)/共36頁(yè)Matlab及其應(yīng)用23空數(shù)組用途:A=reshape(-4:5,2,5)A(:,2,4)=第22頁(yè)/共36頁(yè)Matlab及其應(yīng)用24第23頁(yè)/共36頁(yè)Matlab及其應(yīng)用25第24頁(yè)/共36頁(yè)Matlab及其應(yīng)用26a=123.45; %a is a numerical numberb=123.45; %b is a character arrayc=Matlab programming;whoscfirst=c(1:6) %get the ahead 6 bits of ccinvert=c(end:-1:1) %invert the character of cc(1:6
16、)= c/c+ %assignment of the first 6 bits of cd=and ;e=Matlab ,d,c(1:6),c(7:end) %combination into a new character arrayf=Marys score of ,c, is exelent %the in character is expressed by g=double(f) %convert character array into ASCII(integer)h=char(g) %convert the integer into character array第25頁(yè)/共36頁(yè)
17、Matlab及其應(yīng)用27第26頁(yè)/共36頁(yè)Matlab及其應(yīng)用28clear a=2;w=3;t=0:0.01:10;y=exp(-a*t).*sin(w*t); %calculate the functionymax,imax=max(y); %get the maximum value and index of yttext=t=,num2str(t(imax); %function of num2strytext=y=,num2str(ymax);maxtext=char(maximum:, ttext,ytext) %char transfer into a character arr
18、aytit=y=exp(-,num2str(a),t)*sin(,num2str(w),t);plot(t,zeros(size(t),k) %plot a base line at y=0hold onplot(t,y,b,LineWidth,2) %plot the functionplot(t(imax),ymax,r.,MarkerSize,30) %plot the markertext(t(imax)+0.3,ymax+0.05,maxtext) %output the texttitle(tit),xlabel(t),ylabel(y),hold off第27頁(yè)/共36頁(yè)Matl
19、ab及其應(yīng)用29第28頁(yè)/共36頁(yè)Matlab及其應(yīng)用30第29頁(yè)/共36頁(yè)Matlab及其應(yīng)用31第30頁(yè)/共36頁(yè)Matlab及其應(yīng)用32cstr=char(元胞數(shù)組示例,第一個(gè)元胞(cell)為字符串); %define cstr as a character arrayrnum=reshape(1:9,3,3); %create a 3x3 numerical arrayiconst=1+2i; %iconst is a imaginary constsymfun=sym(sin(-3*t)*exp(-t); %define a symbolic functionCelary1=cst
20、r rnum;iconst symfun %define the four different variables as a cell arrayCelary21,1=cstr; %another methods for the cell array definitionCelary21,2=iconst;Celary22,1=rnum;Celary22,2=symfun;Celary2 %display the cell arrayCelary3=Celary1 Celary2 %column expansion of cell arrayCelary4=Celary1;Celary2 %l
21、ine expansion of cell arrayCelary3(2,:)= %delete the line #2 of the cell arrayCelary3=reshape(Celary3,2,2) %reshape the cell arraycellplot(Celary4,legend) %plot the cell array as a figuretype=Celary4(3,1) %get the 3,1 of the cell arrayCelary43,1=12.36 %make the content of 3,1 in the cell array into
22、12.36item1 item2 item3=deal(Celary42 3 4) %deal function; access cell array with , %item1,item2,item3=deal(Celary42,3,4) is the same as the above line 第31頁(yè)/共36頁(yè)Matlab及其應(yīng)用33第32頁(yè)/共36頁(yè)Matlab及其應(yīng)用34= No.1 house;gh.vol=2000 square meters;gh.para.temp=31.2 30.4 31.6 28.7;29.7 31.1 30.9 29.6;gh.para.humid=62.
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 寵物馴養(yǎng)師崗位面試問(wèn)題及答案
- 2025屆浙江省麗水、湖州、衢州市高二下化學(xué)期末教學(xué)質(zhì)量檢測(cè)試題含解析
- 河北省雄安新區(qū)博奧高級(jí)中學(xué)2025年化學(xué)高二下期末質(zhì)量檢測(cè)試題含解析
- 公司房車(chē)使用管理辦法
- 杭州建筑拆除管理辦法
- 公墓資金使用管理辦法
- 農(nóng)民工權(quán)益保障與工資支付法規(guī)解析
- STM32虛擬仿真綜合實(shí)驗(yàn)平臺(tái)設(shè)計(jì)與應(yīng)用研究
- 兒童文學(xué)的內(nèi)涵與外延探究
- 體育舞蹈課程教學(xué)體系構(gòu)建與技能評(píng)價(jià)標(biāo)準(zhǔn)研究
- 【用Zemax設(shè)計(jì)開(kāi)普勒望遠(yuǎn)鏡的目鏡淺析7900字(論文)】
- 患者出院隨訪統(tǒng)計(jì)分析報(bào)告
- 設(shè)備采購(gòu)售后服務(wù)方案
- 《不寧腿綜合征》課件
- CST仿真技術(shù)交流
- 部編版道德與法治小升初一二三四五六年級(jí)全冊(cè)復(fù)習(xí)簡(jiǎn)答題100道匯編(附答案)
- 幼兒園課程審議下的主題活動(dòng)實(shí)施
- 商業(yè)保理行業(yè)營(yíng)銷(xiāo)策略方案
- 《掃描電子顯微鏡》課件
- 水利水電工程施工截流設(shè)計(jì)說(shuō)明書(shū)
- 變速箱廠總平面布置設(shè)計(jì)設(shè)施規(guī)劃與物流分析課程設(shè)計(jì)
評(píng)論
0/150
提交評(píng)論