【正文】
radients as in fminunc. fun ? x = fminsearch(inline(39。sin(x39。39。*x)39。),x0) ? Inline function ? function f = myfun(x) ? f = ... % Compute function value at x exitflag Describes the exit condition: ? ? 0 indicates that the function converged to a solution x. ? ?0 indicates that the maximum number of function evaluations or iterations was reached. ? ? 0 indicates that the function did not converge to a solution. output ? A structure whose fields contain information about the optimization: ? ? – The number of iterations taken. ? ? – The algorithm used. ? ? – The number of function evaluations. Examples ? function f = myfun(x) ? f = sin(x) + 3。 ? x = fminsearch(39。myfun39。,2) ? f = inline(39。sin(x)+339。)。 ? x = fminsearch(f,2)。 兩個(gè)函數(shù)的比較 ? The function to be minimized must be may only give local solutions. ? fminunc only minimizes over the real numbers, that is, x must only consist of real numbers and f(x) must only return real numbers. When x has plex variables, they must be split into real and imaginary parts. ? fminsearch is generally less efficient than fminunc for problems of order greater than two. However, when the problem is highly discontinuous, fminsearch may be more robust. ? fminsearch can often handle discontinuity. fminsearch may only give local solutions. ? fminsearch only minimizes over the real numbers, x must only consist f real numbers and f(x) must only return real numbers. When x has plex variables, they must be split into real and imaginary parts. 例題 ? 例 53 在 [0, 5]上求下面函數(shù)的最小值 ? 解:先自定義函數(shù):在 MATLAB編輯器中建立M文件為: ? function f = myfun(x) ? f = (x3).^2 1。 ? 保存為 ,然后在命令窗口鍵入命令: ? x=fminbnd(@myfun,0,5) ? 則結(jié)果顯示為: ? x = ? 3 1)3x()x(f 3 ???X=fminsearch(39。2*x(1)^3+4*x(1)*x(2)^310*x(1)*x(2)+x(2)^239。, [0,0]) ? 結(jié)果為 ? X = ? 或在 MATLAB編輯器中建立函數(shù)文件 ? function f=myfun(x) ? f=2*x(1)^3+4*x(1)*x(2)^310*x(1)*x(2)+x(2)^2。 ? 保存為 ,在命令窗口鍵入 ? X=fminsearch (39。myfun39。, [0,0]) 或 X=fminsearch(@myfun, [0,0]) ? 結(jié)果為: X = 222132131 xxx10xx4x2y ?????例 54 求的最小值點(diǎn) 作業(yè) ?例 1計(jì)算下面函數(shù)在區(qū)間 (0, 1)內(nèi)的最小值。 ?例 2 求的最小值。 222121 xxx2x3)x(f ???x3e xl o gxxc o sx)x(f ???