




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、MATLAB 程式設(shè)計進階篇一般數(shù)學(xué)函數(shù)的處理與分析張智星/jang臺大資工系 多媒體檢索實驗室MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析函數(shù)的函數(shù)nMATLAB 可對數(shù)學(xué)函數(shù)進行各種運算與分析,例如:n作圖n求根n優(yōu)化:求函數(shù)的極大或極小值n數(shù)值積分n求解微分方程式n如何表示此種被分析的函數(shù)?n字串n函數(shù)握把 (function handles)n匿名函數(shù) (anonymous function)Functions ofFunctions!MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析一維數(shù)學(xué)函數(shù)的範(fàn)例nMATL
2、AB 是以 M 檔案(副檔名為 m)來表示一個函數(shù)n例如,內(nèi)建於MATLAB目錄的 humps.m 可用來計算下列函數(shù):n更多資訊:n欲顯示此檔案的位置 which humpsn欲顯示此檔案的內(nèi)容 type humps604. 0)9 . 0(101. 0)3 . 0(1)(22xxxfMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析提示nMATLAB 常被用到的測試函數(shù)nhumps:單輸入函數(shù)npeaks:雙輸入函數(shù)n函式和函數(shù)都代表functions,兩者常會混用,若要正名,可區(qū)分如下:n函數(shù):通常用來表示mathematic functionsn函式:通常用來表示subroutin
3、es or functions in a programming languageWe use 函數(shù) to represent both.MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析數(shù)學(xué)函數(shù)的作圖 n表示函數(shù)的方式n函數(shù)握把:使用 humps 來代表 humps.mn字串:使用 humps 來代表 humps.mn用 fplot 指令進行數(shù)學(xué)函數(shù)作圖n畫出 humps 函數(shù)在 0,2 間的曲線n範(fàn)例:fplot01.msubplot(2,1,1);fplot(humps, 0,2);% 使用字串指定函式subplot(2,1,2);fplot(humps, 0 2);% 使用函式握把
4、來指定函式00.81.82-5005010000.81.82-50050100Less flexible!MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析同時改變 x、y 的區(qū)間n我們可同時改變 x 和 y 的區(qū)間n範(fàn)例:fplot02.mnx 的區(qū)間為0, 1ny 的區(qū)間為5, 25 fplot(humps, 0, 1, 5, 25);grid on% 畫出格線01510152025MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析匿名函式nfplot
5、也接受匿名函式(當(dāng)場指定的函式)n範(fàn)例:fplot021.msubplot(2,1,1);fplot(sin(2*x)+cos(x), -10, 10)% 使用字串指定函式subplot(2,1,2);fplot(x)sin(2*x)+cos(x), -10, 10)% 使用函式握把來指定函式-10-8-6-4-20246810-2-1012-10-8-6-4-20246810-2-1012MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析對多個函數(shù)作圖nfplot 也可同時對多個函數(shù)作圖,其中每個函數(shù)須以一個行向量來表示n範(fàn)例:fplot022.mnx 是行向量(MATLAB 預(yù)設(shè)值)n
6、sin(x), exp(-x) 是二個行向量n每個行向量代表一個函數(shù)(即一條曲線)fplot(x)sin(x), exp(-x), 0, 10)012345678910-1-0.8-0.6-0.4-0.60.81MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析帶有參數(shù)的函數(shù)n匿名函式也可以帶有參數(shù)n範(fàn)例:fplot023.mn此時 “(x)” 不可省略,以便指定自變數(shù)a=1; b=1.1; c=1.2;fplot(x)sin(a*x), sin(b*x), sin(c*x), 0, 10)012345678910-1-0.8-0.6-0.4-0.6
7、0.81Function handle is more flexible!MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析產(chǎn)生 X、Y 座標(biāo)點nfplot 可進行描點作圖,類似 plot(x, y),但x 座標(biāo)點的密度根據(jù)函數(shù)值的變化決定n我們顯示 fplot 所產(chǎn)生的 x 座標(biāo)點n範(fàn)例:fplot03.mn函數(shù)變化平緩處,產(chǎn)生稀疏的點n函數(shù)變化劇烈處,產(chǎn)生緊密的點 x, y = fplot(humps, -1,2);plot(x, y, -o);-1-0.500.511.52-20020406080100MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析產(chǎn)生更密的 X 座標(biāo)點 (1
8、)n若欲產(chǎn)生更密的 x 座標(biāo)點,可在 fplot 指令加入另一個輸入引數(shù),已指定相對容忍度(Tolerance)n範(fàn)例:fplot04.msubplot (2,1,1);fplot(x)sin(1./x), 0.01,0.1);subplot (2,1,2);fplot(x)sin(1./x), 0.01,0.1, 0.0001);MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析產(chǎn)生更密的 X 座標(biāo)點 (2)n在第一圖中,fplot 指令使用預(yù)設(shè)相對容忍度,其值為 0.002。n在第二圖中,相對容忍度被設(shè)為 0.0001,可得到更準(zhǔn)確的圖形,但也要花更多計算及作圖時間。0.010.020
9、.030.040.050.060.070.080.090.1-1-0.500.510.010.020.030.040.050.060.070.080.090.1-1-0.500.51MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析ezplot 指令nezplot指令和fplot指令類似,可進行描點作圖,但使用更為簡便,預(yù)設(shè)的作圖範(fàn)圍為n範(fàn)例8-7:ezplot01.mezplot(x)x3-x2+x);-6-4-20246-300-250-200-150-100-50050100150200 xx3-x2+x2,2MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析平面中的參數(shù)式曲線n
10、ezplot 也可畫出平面中的參數(shù)式曲線 n範(fàn)例8-8:ezplot02.mn參數(shù)式函數(shù)的參數(shù)預(yù)設(shè)範(fàn)圍仍是 ezplot(t)sin(3*t), (t)cos(5*t);-1-0.500.51-0.8-0.6-0.4-0.60.81xyx = sin(3 t), y = cos(5 t)2,2)5cos()3sin(tytx利薩如圖形 (Lissajous Figures)MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析空間中的參數(shù)式曲線nezplot3 可畫出空間中的參數(shù)式曲線 n範(fàn)例8-8:ezplot021.mn參數(shù)式函數(shù)的參數(shù)預(yù)設(shè)範(fàn)圍仍是 ezplot3(t)
11、sin(3*t), (t)cos(5*t), (t)t)2,2tztytx)5cos()3sin(3D利薩如圖形MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析隱函數(shù)作圖nezplot 指令可用於隱函數(shù)作圖n下列範(fàn)例可以畫出n範(fàn)例8-9:ezplot03.mezplot(x,y)x3+2*x2-3*x-y2+15);-6-4-20246-6-4-20246xyx3+2 x2-3 x+5-y2+10 = 001532223yxxxMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析函數(shù)的求根nfzero 指令n用於單變數(shù)函數(shù)的求根n語法x = fzero(fun, x0)nfun 是欲求
12、根的函數(shù)(以字串或函數(shù)握把來表示)nx0 是一個起始點或起始區(qū)間MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析X0 對 fzero 的影響nfzero 指令根據(jù) x0 不同而執(zhí)行下列動作n若 x0 為一個起始點n fzero 會自動找出附近包含零點(即根,或函數(shù)變號點)的區(qū)間n逐步縮小此區(qū)間以找出零點n若 fzero 無法找出此區(qū)間,傳回 NaNn若已知使函數(shù)值不同號的兩點n由 x0 直接指定尋根的區(qū)間n fzero 更快速找到位於此區(qū)間內(nèi)的根 MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析求根範(fàn)例 (1)n找出humps在 x = 1.5 附近的根,並驗算n範(fàn)例8-10:fz
13、ero01.mnfzero 先找到在 1.5 附近變號的兩點(即 1.26 及 1.6697),然後再找出 humps 的零點 x = fzero(humps, 1.5);% 求靠近 1.5 附近的根y = humps(x); % 帶入求值fprintf(humps(%f) = %fn, x , y);humps(1.299550) = 0.000000MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析求根範(fàn)例 (2)n若已知 humps 在 x = -1 及 1 間為異號n令 x0 = -1, 1 為起始區(qū)間來找出 humps 的零點n範(fàn)例8-11:fzero02.mn此時 fzero
14、找到的是另一個零點x = fzero(humps, -1, 1);% 求落於區(qū)間 -1, 1 的根y = humps(x);% 帶入求值fprintf(humps(%f) = %fn, x , y);humps(-0.131618) = 0.000000MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析求根範(fàn)例 (3)n若要畫出以上兩個零點,請見下列範(fàn)例n範(fàn)例8-12:fzero03.mfplot(humps, -1, 2); grid onz1 = fzero(humps, 1.5);z2 = fzero(humps, -1, 1);line(z1, humps(z1), marker,
15、 o, color, r);line(z2, humps(z2), marker, o, color, r);-1-0.500.511.52-20020406080100MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析顯示求解過程的中間結(jié)果 (1)nMATLAB 可以顯示求解過程的中間結(jié)果n使用 optimset 指令來設(shè)定顯示選項n再將 optimset 傳回結(jié)構(gòu)變數(shù)送入 fzeron範(fàn)例8-13:fzero04.mnoptimset 常用於設(shè)定最佳化的選項,下一節(jié)會有比較完整的介紹opt = optimset(disp, iter);% 顯示每個 iteration 的結(jié)果 a =
16、fzero(humps, -1, 1, opt)MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析顯示求解過程的中間結(jié)果 (2) n求零點過程中,找下一點的兩個方法顯示在第四個欄位(Procedure 欄位)n二分法(Bisection)n內(nèi)插法(Interpolation)n可由doc fzero找到所使用的演算法Func-count x f(x) Procedure 1 -1 -5.13779 initial 2 1 16 I initial 3 -0.513876 -4.02235 interpolation 4 0.243062 71.6382 bisection 5 -0.473
17、635 -3.83767 interpolation 6 -0.115287 0.414441 bisection 7 -0.150214 -0.423446 interpolation 8 -0.132562 -0.0226907 interpolation 9 -0.131666 -0.0011492 interpolation 10 -0.131618 1.88371e-007 interpolation 11 -0.131618 -2.7935e-011 interpolation 12 -0.131618 8.88178e-016 interpolation 13 -0.131618
18、 -9.76996e-015 interpolationZero found in the interval: -1, 1.a = -0.1316MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析數(shù)值積分nMATLAB 可用於計算單變函數(shù)定積分nquad:適應(yīng)式 Simpson 積分法(Adaptive Simpson Quadrature)nquadl:適應(yīng)式 Lobatto 積分法(Adaptive Lobatto Quadrature)MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析定積分n計算 humps 在 0, 1 的定積分 q = quad(humps, 0, 1)q
19、= 29.8583nquad 及 quad8 都應(yīng)用遞迴程序n若遞迴次數(shù)達 10 次,兩種方法均會傳回 Infn表示所計算之定積分可能不存在nquad 及 quad8第四個引數(shù)用來指定積分的相對誤差容忍度MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析曲線的長度 (1)nquad 及 quadl 計算曲線的長度n一曲線是由下列參數(shù)化的方程式來表示n t 的範(fàn)圍為 0, 3*pin範(fàn)例:plotCurve.mttzttyttx)()cos()()2sin()(t = 0:0.1:3*pi;plot3(sin(2*t), cos(t), t);MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理
20、與分析曲線的長度 (2)n此曲線的長度等於dtttdtdtdzdtdydtdx3022302221)(sin)2(cos4-1-0.500.51-1-0.500.510246810MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析曲線的長度 (3)n先定義函數(shù) curveLength.m type curveLength.mfunction out = curveLength(t)out = sqrt(4*cos(2*t).2+sin(t).2+1);n曲線長度可計算如下 len = quad(curveLength, 0, 3*pi)len = 17.2220MATLAB 程式設(shè)計進階篇
21、:一般數(shù)學(xué)函數(shù)的處理與分析雙重積分 (1)ndblquad 指令n用來計算雙重積分n欲計算n其中n先建立被積分的函數(shù) integrand.m type integarnd.mfunction out = integrand(x, y)out = y*sin(x) + x*cos(y); maxminmaxmin),(yyxxdxdyyxf)sin()sin(),(yxxyyxfMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析雙重積分 (2)n計算雙重積分result = dblquad( integrand, xMin, xMax, yMin, yMax)n其中nxMin:內(nèi)迴圈積分的下
22、界值nxMax:內(nèi)迴圈積分的上界值nyMin:外迴圈積分的下界值nyMax:外迴圈積分的上界值MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析雙重積分 (3)n範(fàn)例:dblquad01.mn一般的情況下dblquad 會呼叫 quad 計算定積分。若須呼叫更為精確的 quadl,可執(zhí)行下列指令result = dblquad(integrand, xMin, xMax, yMin, yMax, quadl)result = -9.8696xMin = pi;xMax = 2*pi;yMin = 0;yMax = pi;result = dblquad(integrand, xMin, x
23、Max, yMin, yMax)result = -9.8698MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析函數(shù)的優(yōu)化nMATLAB 提供了數(shù)個基本指令來進行數(shù)學(xué)函數(shù)的優(yōu)化,本節(jié)將介紹:n單變數(shù)函數(shù)的最小化: fminbndn多變數(shù)函數(shù)的最小化: fminsearchn設(shè)定最佳化的選項n若讀者有興趣使用較複雜的方法,可以使用最佳化工具箱(Optimization Toolbox)MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析單變函數(shù)的最小化n fminbnd 指令n尋求 humps 在 0.3, 1 中的最小值n範(fàn)例:fminbnd01.mn最小值發(fā)生在 x = 0.637,
24、且最小值為 11.2528x, minValue = fminbnd(humps, 0.3, 1)x = 0.6370minValue = 11.2520.91102030405060708090100MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析尋求最小值的中間過程 (1)n尋求最小值的中間過程n使用 optimset 指令來設(shè)定顯示選項n再將 optimset 傳回結(jié)構(gòu)變數(shù)送入 fminbndn範(fàn)例8-15:fminbnd02.mopt = optimset(disp, iter);% 顯示每個步驟的結(jié)果x, minValue = fminbn
25、d(humps, 0.3, 1, opt)MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析尋求最小值的中間過程 (2) n左表列出x值的變化及相對的函數(shù)值 f(x) n最後一欄位列出求極小值的方法,包含n黃金分割搜尋(Golden Section Search)n拋物線內(nèi)插法(Parabolic Interpolation)nx 值誤差小於 10-4 Func-count x f(x) Procedure 1 0.567376 12.9098 initial 2 0.732624 13.7746 golden 3 0.465248 25.1714 golden 4 0.644416 11
26、.2693 parabolic 5 0.6413 11.2583 parabolic 6 0.637618 11.2529 parabolic 7 0.636985 11.2528 parabolic 8 0.637019 11.2528 parabolic 9 0.637052 11.2528 parabolicOptimization terminated successfully: the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-004 x = 0.6370minValue
27、= 11.2528MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析放鬆誤差管制 (1)n放鬆誤差管制n使 fminbnd 提早傳回計算結(jié)果n由 optimset 達成n下例將 x 的誤差範(fàn)圍提高為 0.1n範(fàn)例8-16:fminbnd03.mopt = optimset( disp, iter, TolX, 0.1); x, minValue = fminbnd(humps, 0.3, 1, opt)MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析放鬆誤差管制 (2) Func-count x f(x) Procedure 1 0.567376 12.9098 initial 2
28、0.732624 13.7746 golden 3 0.465248 25.1714 golden 4 0.644416 11.2693 parabolic 5 0.611083 11.4646 parabolic 6 0.677749 11.7353 parabolic Optimization terminated successfully: the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-001 x = 0.6444minValue = 11.2693MATLAB 程式設(shè)計進
29、階篇:一般數(shù)學(xué)函數(shù)的處理與分析多變數(shù)函數(shù)的極小值:fminsearchnfminsearch 指令n求多變數(shù)函數(shù)的極小值n必須指定一個起始點,讓 fminsearch 求出在起始點附近的局部最小值(Local Minima)nDerivative free Less efficientnMethod: Downhill Simplex Search (DSS), akanNelder-Mead methodnAmoeba methodMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析Downhill Simplex SearchnDSS in WikipedianMany variatio
30、nsnBasic StepsnUse a simplex to explore the objective function, with the operations:nReflectionnExpansionnContractionnShrinkMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析Downhill Simplex SearchnAbout DSSnStrengthsnStraightforward conceptnEasy programmingnNo gradient or derivative needednWeaknessnSlownOnly good for con
31、tinuous objective functionnCould be trapped in local minimaQuiz!MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析多變數(shù)函數(shù)的極小值範(fàn)例n若目標(biāo)函數(shù)為我們必須先產(chǎn)生一個 MATLAB 的函數(shù) objective.m n若起始點為n範(fàn)例:fminsearch01.m 0 , 0 , 0,321xxxx0 = 0, 0, 0;x = fminsearch(objective, x0)332221321)3()2() 1(),(xxxxxxffunction y = objective(x)y = (x(1)-1)2 +(x(2)-
32、2)2 + (x(3)-3)2;x = 1.0000 2.0000 3.0000MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析最佳化選項nMATLAB 最佳化的選項n經(jīng)由另一個輸入引數(shù)(Input Argument)來進入 fminbnd 或 fminsearchn使用語法x = fminbnd(objFun, x1, x2, options)x = fminbnd(x)objFun(x, a), x1, x2, options)或x = fminsearch(objFun, x0, options )x = fminsearch(x)objFun(x, a), x0, options
33、 )n optionsn此結(jié)構(gòu)變數(shù)可代表各種最佳化的選項(或參數(shù))Extra parametersExtra parametersMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析設(shè)定最佳化選項 (1) n如何設(shè)定最佳化選項n用 optimset 指令options = optimset(prop1, value1, prop2, value2, )nprop1、prop2 :欄位名稱 nvalue1、value2 :對應(yīng)的欄位值MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析設(shè)定最佳化選項 (2)n印出最佳化步驟的中間結(jié)果,並放鬆誤差範(fàn)圍 options = optimset(Di
34、sp, iter, TolX, 0.1) Display: iter MaxFunEvals: MaxIter: TolFun: TolX: 0.1000 FunValCheck: OutputFcn: PlotFcns: ActiveConstrTol: MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析設(shè)定最佳化選項 (3)noptions 共有五十多個欄位n如果欄位值顯示是空矩陣,n使用此欄位的預(yù)設(shè)值來進行運算 options = optimset(fminbnd)n顯示非空矩陣的最佳化選項:nDisplay: notifynMaxFunEvals: 500nMaxIter: 500
35、nTolX: 1.0000e-004nFunValCheck: offMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析設(shè)定最佳化選項 (4)n若輸入 options = optimset(fminsearch) n顯示非空矩陣的最佳化選項:nDisplay: notifynMaxFunEvals: 200*numberofvariables nMaxIter: 200*numberofvariablesnTolFun: 1.0000e-004nTolX: 1.0000e-004nFunValCheck: offMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析最佳化選項說明 (1)
36、nDisplay n若為 0 (預(yù)設(shè)值),不顯示中間運算結(jié)果n若不為 0,則顯示運算過程的中間結(jié)果nMaxFunEvals n函數(shù)求值運算(Function Evaluation)的最高次數(shù)n對 fminbnd 的預(yù)設(shè)值是 500n對 fminsearch 的預(yù)設(shè)值是 200 乘上 x0 的長度nMaxIter n最大疊代次數(shù)n對 fminbnd 的預(yù)設(shè)值是 500n對 fminsearch 的預(yù)設(shè)值是 200 乘上 x0 的長度MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析最佳化選項說明 (2)nTolFun n決定終止搜尋的函數(shù)值容忍度n預(yù)設(shè)為 10-4n此選項只被 fminsea
37、rch 用到,fminbnd 並不使用nTolX n終止搜尋的自變數(shù)值容忍度,預(yù)設(shè)為 10-4 MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析提示n最佳化並非一蹴可及,通常一再重覆,最後才能收斂到最佳點n最佳化的結(jié)果和起始點的選定有很大的關(guān)聯(lián),一個良好的起始點n加快最佳化收斂的速度n提高找到全域最佳值(Global Optimum)的機會MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析nSteps for Down-hill Simplex search (DSS)nDefine an objective function myFun(x)nSet initial guess “
38、x0”nStart the search via fminsearchnx=fminsearch(myFun, x0);nVariantsnObjective function myFun(x, prm)nStart the searchnx=fminsearch(x) myFun(x, prm), x0);nx=fminsearch(myFun, x0, , prm);More Examples of DSSOld usageExtra parametersTo be passed to myFun()MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析DSS: Example 1 (1/
39、3)nFermat pointnA point P in a plane such that PA+PB+PC is minimized.nSolutionnAnalytic solutionnP satisfies AFB=BFC=CFA=120onNumerical solutionnAll kinds of optimization methodsQuiz!Properties!MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析DSS: Example 1 (2/3) nObjective functionndist2ABC.mnMain program:ngoMinDist2ABC
40、.mfunction sumDistance=dist2ABC(x)% dist2ABC: The distance sum to points A, B, CA=0 0;B=3 0;C=0 4;sumDistance=norm(x-A)+norm(x-B)+norm(x-C);p0=5 5;% Initial guessp=fminsearch(dist2ABC, p0);Bad idea tohardwire the data pointsMATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析DSS: Example 1 (3/3) MATLAB 程式設(shè)計進階篇:一般數(shù)學(xué)函數(shù)的處理與分析DSS: Example 2 (1/3) nProblem definitionnFind a point P such that the total
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中國公路運輸合同
- 型鋼采購合同協(xié)議
- 家教老師聘用合同書
- 玻璃幕墻安裝合同
- 商品買賣居間合同
- 美國工程設(shè)計服務(wù)合同
- 側(cè)柏買賣合同
- 遼寧輕工職業(yè)學(xué)院《建筑設(shè)備(電)》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣西質(zhì)量工程職業(yè)技術(shù)學(xué)院《醫(yī)用生物化學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 江西機電職業(yè)技術(shù)學(xué)院《深度學(xué)習(xí)實驗》2023-2024學(xué)年第二學(xué)期期末試卷
- 【道 法】學(xué)會自我保護+課件-2024-2025學(xué)年統(tǒng)編版道德與法治七年級下冊
- 買房協(xié)議書樣板電子版
- 河南航空港發(fā)展投資集團有限公司2025年社會招聘題庫
- 綿陽市高中2022級(2025屆)高三第二次診斷性考試(二診)語文試卷(含答案)
- 常州初三強基數(shù)學(xué)試卷
- 《吞咽障礙膳食營養(yǎng)管理規(guī)范》(T-CNSS 013-2021)
- 仁愛七年級下冊英語教學(xué)計劃
- 躁狂的健康宣教
- 第四講國防動員準(zhǔn)備
- 四川省成都市2025屆高三一診考試英語試卷含解析
- 2024年度房地產(chǎn)開發(fā)項目安全生產(chǎn)委托管理協(xié)議范本3篇
評論
0/150
提交評論