1

我正在使用多项式曲线拟合来分析我的数据(polyfit 和 polyval),我得到了这样的曲线。我想找到每条曲线的最小点(红点)。如果我使用 min() 我将只得到一条曲线。如何获得两个点?

固化配件

非常感谢你

4

1 回答 1

4

简单的:

% Your polynomial coefficients
c = [-1 4 5 2 6 2 4 5];

% Find real roots of its derivative
R = roots( [numel(c)-1 : -1 : 1] .* c(1:end-1) );
R = R(imag(R)==0);

% Compute and sort function values of these extrema
if ~isempty(R)

    [yExtrema, indsExtrema] = sort(polyval(c, R));
    xExtrema = R(indsExtrema);

    % Extract the two smallest ones
    yMins = yExtrema(1:2);
    xMins = xExtrema(1:2);

else
    yMins = [];
    xMins = [];

end
于 2013-09-11T07:34:51.903 回答