| MATLAB Function Reference | ![]() |
Syntax
x = fminbnd(fun,x1,x2) x = fminbnd(fun,x1,x2,options) x = fminbnd(fun,x1,x2,options,P1,P2,...) [x,fval] = fminbnd(...) [x,fval,exitflag] = fminbnd(...) [x,fval,exitflag,output] = fminbnd(...)
Description
fminbnd 尋找 在固定區間中只有一個變數函數的最小值。
x = fminbnd(fun,x1,x2)
傳回 fun 描述函數函數在區間 x1 < x < x2 中的局部最小者(minimizer) x 值。
x = fminbnd(fun,x1,x2,options)
以定義在結構 options 中的最佳參數做最小化。你可以用 optimset 函數定義這些參數。fminbnd 使用以下這些 options 結構欄位:
Display |
顯示的等級。'off' 不顯示輸入;'iter' 在每次重複(iteration)時顯示輸出;'final' 只顯示最後結果;'notify' (預設) 只在函數不收斂時顯示輸出。 |
MaxFunEvals |
允許函數求值的最多次數。 |
MaxIter |
允許重複(iteration)的最多次數。 |
TolX |
x 的終結容忍度。 |
x = fminbnd(fun,x1,x2,options,P1,P2,...)
提供傳到目標函數的額外參數,P1、P2、etc.,fun(x,P1,P2,...)。如果沒有設定選項,用 options=[] 當作欄位保留。
[x,fval] = fminbnd(...)
傳回目標函數 fun 在 x 計算的值。
[x,fval,exitflag] = fminbnd(...)
傳回描述 fminbnd 跳出狀態的值 exitflag:
| >0 |
表示函數收斂到解答 x。 |
| 0 |
表示到達函數計算次數的最大值。 |
| <0 |
表示函數沒有收斂。 |
[x,fval,exitflag,output] = fminbnd(...)
傳回一個包含最佳化資訊的結構 output:
output.algorithm |
使用的演算法 |
output.funcCount |
函數計算的次數 |
output.iterations |
重複(iteration)的次數 |
Arguments
fun 是要最小化的函數。fun 接受一個純量 x 然後傳回一個純量 f,目標函數在 x 做計算。函數 fun 可以當作函數處理定義。
x = fminbnd(@myfun,x0)
function f = myfun(x) f = ... % Compute function value at x.
x = fminbnd(inline('sin(x*x)'),x0);
Examples
x = fminbnd(@cos,3,4) 以幾個十進位位數計算
,在結束時給一個訊息。
[x,fval,exitflag] =
fminbnd(@cos,3,4,optimset('TolX',1e-12,'Display','off'))
計算
到十進位 12 位數,隱藏結果,傳回在 x 的函數值和值為 1 的 exitflag。
參數 fun 也可以是 inline 函數。找函數
在區間 (0,2) 中的最小值,產生一個 inline 物件 f
f = inline('x.^3-2*x-5');
x = fminbnd(f,0,2)
x =
0.8165
y = f(x)
y =
-6.0887
Algorithm
這個演算法是以 Golden Section search 和 parabolic interpolation 為基礎。一個以同樣的演算法實作的 Fortran 程式可以在[1] 得到。
Limitations
要最小化的函數必須是連續的。fminbnd 可能只給局部的解答。
See Also
fminsearch, fzero, optimset, function_handle (@), inline
References
Forsythe, G. E., M. A. Malcolm, and C. B. Moler, Computer Methods for Mathematical Computations, Prentice-Hall, 1976.
| fmin | fmins | ![]() |