1 回答

TA貢獻1833條經(jīng)驗 獲得超4個贊
如果是多元函數(shù)的話,可以參考fminseach
Example 1
The Rosenbrock banana function is a classic test example for multidimensional minimization:
f=x(1)^2+a*x(2)^2; 目標函數(shù)
The minimum is at (1,1) and has the value 0. The traditional starting point is (-1.2,1). The anonymous function shown here defines the function and returns a function handle called banana:
function f=myfun(x,a) 新建著這樣的M文件
banana = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2;
Pass the function handle to fminsearch:
[x,fval] = fminsearch(banana,[-1.2, 1])
用這樣的格式條用fminseach以及M函數(shù), 其中[-1.2,1]為優(yōu)化其實點
This produces 運行以后的結果
x =
1.0000 1.0000
fval = 這個是優(yōu)化點的函數(shù)值
8.1777e-010
This indicates that the minimizer was found to at least four decimal places with a value near zero.
添加回答
舉報