对目标进行最大化
所有求解器都会尝试最小化目标函数。如果您有最大化问题,即以下形式的问题:
,
然后定义 并最小化 。
例如,要计算 在 附近的最大值,请计算
[x,fval] = fminunc(@(x)-tan(cos(x)),5)
Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance. <stopping criteria details>
x = 6.2832
fval = -1.5574
最大值为 1.5574
(报告的 fval
的负值),并出现在 x = 6.2832
。此答案是正确的,因为取五位数时,最大值为 ,该值出现在 处。