freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

[工學(xué)]第一講-matlab入門簡介(編輯修改稿)

2024-11-09 14:18 本頁面
 

【文章內(nèi)容簡介】 le 條件式; 運(yùn)算式; end 也就是說,只要條件示成立,運(yùn)算式就會一再被執(zhí)行。例如先前產(chǎn)生調(diào)和數(shù)列的例子,我們可用 while圈改寫如下 : x = zeros(1,6)。 % x是一個 16的零矩陣 i = 1。 while i = 6, x(i) = 1/i。 i = i+1。 end format short ? 邏輯命令 最簡單的邏輯命令是 if, ..., end, 其基本形式為: if 條件式; 運(yùn)算式; end if rand(1,1) , disp(39。Given random number is greater than .39。)。 end Given random number is greater than . ? 集合多個命令于一個 M檔案 若要一次執(zhí)行大量的 MATLAB命令,可將這些命令存放于一個副檔名為 m的檔案,并在MATLAB提示號下鍵入此檔案的主檔名即可。此種包含 MATLAB命令的檔案都以 m為副檔名,因此通稱 M檔案( Mfiles)。 例如一個名為 M檔案,包含一連串的 MATLAB命令,那幺只要直接鍵入 test, 即可執(zhí)行其所包含的命令: pwd % 顯示現(xiàn)在的目錄 ans = D:\MATLAB5\bin cd c:\data\mlbook % 進(jìn)入 type % 顯示 % This is my first test Mfile. % Roger Jang, March 3, 1997 fprintf(39。Start of !\n39。)。 for i = 1:3, fprintf(39。i = %d i^3 = %d\n39。, i, i^3)。 end fprintf(39。End of !\n39。)。 test % 執(zhí)行 Start of ! i = 1 i^3 = 1 i = 2 i^3 = 8 i = 3 i^3 = 27 End of ! 小提示:第一注解行( H1 help line ) 的前兩行是注解,可以使程序易于了解與管理。特別要說明的是,第一注解行通常用來簡短說明此 M 檔案的功能,以便 lookfor 能以關(guān)鍵字比對的方式來找出此 M 檔案。舉例來說, 的第一注解行包含 test 這個字,因此如果鍵入 lookfor test , MATLAB 即可列出所有在第一注解行包含 test 的 M 檔案,因而 也會被列名在內(nèi)。 嚴(yán)格來說, M檔案可再細(xì)分為命令集( Scripts) 及函數(shù)( Functions)。 前述的,其效用和將命令逐一輸入完全一樣,因此若在命令集可以直接使用工作空間的變數(shù),而且在命令集中設(shè)定的變數(shù),也都在工作空間中看得到。函數(shù)則需要用到輸入引數(shù)( Input arguments) 和輸出引數(shù)( Output arguments) 來傳遞資訊,這就像是C語言的函數(shù),或是 FORTRAN語言的副程序( Subroutines)。 舉例來說,若要計(jì)算一個正整數(shù)的階乘( Factorial), 我們可以寫一個如下的 MATLAB函數(shù)并將之存檔于 : function output = fact(n) % FACT Calculate factorial of a given positive integer. output = 1。 for i = 1:n, output = output*i。 end 其中 fact是函數(shù)名, n是輸入引數(shù), output是輸出引數(shù),而 i則是此函數(shù)用到的暫時變數(shù)。要使用此函數(shù),直接鍵入函數(shù)名及適當(dāng)輸入引數(shù)值即可: y = fact(5) y = 120 (當(dāng)然,在執(zhí)行 fact之前,你必須先進(jìn)入。)在執(zhí)行 fact(5)時,MATLAB會跳入一個下層的暫時工作空間( Temperary workspace), 將變數(shù) n的值設(shè)定為 5,然后進(jìn)行各項(xiàng)函數(shù)的內(nèi)部運(yùn)算,所有內(nèi)部運(yùn)算所產(chǎn)生的變數(shù)(包含輸入引數(shù) n、 暫時變數(shù) i, 以及輸出引數(shù) output) 都存在此暫時工作空間中。運(yùn)算完畢后, MATLAB會將最后輸出引數(shù) output的值設(shè)定給上層的變數(shù) y, 并將清除此暫時工作空間及其所含的所有變數(shù)。換句話說,在呼叫函數(shù)時,你只能經(jīng)由輸入引數(shù)來控制函數(shù)的輸入,經(jīng)由輸出引數(shù)來得到函數(shù)的輸出,但所有的暫時變數(shù)都會隨著函數(shù)的結(jié)束而消失,你并無法得到它們的值。 小提示:有關(guān)階乘函數(shù) 前面(及后面)用到的階乘函數(shù)只是純粹用來說明 MATLAB 的函數(shù)觀念。若實(shí)際要計(jì)算一個正整數(shù) n 的階乘(即 n! )時,可直接寫成 prod(1:n) ,或是直接呼叫g(shù)amma 函數(shù): gamma(n 1) 。 MATLAB( Recursive), 也就是說,一個函數(shù)可以呼叫它本身。舉例來說, n! = n*(n1)!, 因此 function output = fact(n) % FACT Calculate factorial of a given positive integer recursively. if n == 1, % Terminating condition output = 1。 return。 end output = n*fact(n1)。 束條件( Terminating condition), 否則此函數(shù)將會一再呼叫自己,永遠(yuǎn)不會停止,直到電腦的記憶體被耗盡為止。以上例而言, n==1即滿足結(jié)束條件,此時我們直接將 output設(shè)為 1,而不再呼叫此函數(shù)本身。 ? 搜尋路徑 在前一節(jié)中, d:\mlbook。 如果不先進(jìn)入這個目錄, MATLAB就找不到你要執(zhí)行的 M檔案。如果希望 MATLAB不論在何處都能執(zhí)行 , 那幺就必須將d:\mlbook加入 MATLAB的搜尋路徑( Search path) 上。要檢視 MATLAB的搜尋路徑,鍵入path即可: path MATLABPATH d:\matlab5\toolbox\matlab\general d:\matlab5\toolbox\matlab\ops d:\matlab5\toolbox\matlab\lang d:\matlab5\toolbox\matlab\elmat d:\matlab5\toolbox\matlab\elfun d:\matlab5\toolbox\matlab\specfun d:\matlab5\toolbox\matlab\matfun d:\matlab5\toolbox\matlab\datafun d:\matlab5\toolbox\matlab\polyfun d:\matlab5\toolbox\matlab\funfun d:\matlab5\toolbox\matlab\sparfun d:\matlab5\toolbox\matlab\graph2d d:\matlab5\toolbox\matlab\graph3d d:\matlab5\toolbox\matlab\specgraph d:\matlab5\toolbox\matlab\graphics d:\matlab5\toolbox\matlab\uitools d:\matlab5\toolbox\matlab\strfun d:\matlab5\toolbox\matlab\iofun d:\matlab5\toolbox\matlab\timefun d:\matlab5\toolbox\matlab\datatypes d:\matlab5\toolbox\matlab\dde d:\matlab5\toolbox\matlab\demos d:\matlab5\toolbox\tour d:\matlab5\toolbox\simulink\simulink d:\matlab5\toolbox\simulink\blocks d:\matlab5\toolbox\simulink\simdemos d:\matlab5\toolbox\simulink\dee d:\matlab5\toolbox\local 此搜尋路徑會依已安裝的工具箱( Toolboxes)不同而有所不同。要查詢某一命令是在搜尋路徑的何處,可用 which命令: which expo d:\matlab
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1