MATLAB运用优化工具解决问题时,怎么定义多元函数。一元的:function=文件名(x);y=2*x^2;..
发布网友
发布时间:2022-10-13 19:23
我来回答
共1个回答
热心网友
时间:2023-11-09 14:25
如果是多元函数的话,可以参考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 proces 运行以后的结果
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.