[英]Matlab question about finding the absolute maximum value of a function between a given interval
假设我有一个 function f=@(x) -1/x^2。 我需要找到[1,2]之间的最大值。 所以答案是 1,因为如果 x=1,abs(-1/x^2) 的最大值
是否有一个 matlab/octave 内置功能,它采用 function、间隔并返回一个数字?
您的问题是非线性规划问题的一个实例。
在基本倍频程中,您可以为此使用sqp
function: https://octave.org/doc/v6.2.0/Nonlinear-Programming.html#Nonlinear-Programming
例子:
f = @(x) -1 ./ (x .^ 2);
Min = sqp( 1.5, % Initial guess. I chose middle of proposed range
f, % The function to be minimized
[], % Function representing equality constraint. Not used here.
[], % Function representing inequality constraint. Not used here.
1, % Lower bound of 1 for x
2 % Upper bound of 2 for x
)
% output: Min = 1
或者,还有来自 optim 包/工具箱的fmincon
(分别在octave / matlab中),其工作方式类似。 如果您特别追求 octave/matlab 互操作性,这可能是一个更好的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.