1 回答
TA贡献1833条经验 获得超4个赞
如果是多元函数的话,可以参考fminseach
Example 1
The Rosenbrock banana function is a classic test example for multidimensional minimization:
f=x(1)^2+a*x(2)^2; 目标函数
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函数, 其中[-1.2,1]为优化其实点
This produces 运行以后的结果
x =
1.0000 1.0000
fval = 这个是优化点的函数值
8.1777e-010
This indicates that the minimizer was found to at least four decimal places with a value near zero.
添加回答
举报