我正在使用多项式曲线拟合来分析我的数据(polyfit和polyval),我得到了这样的曲线。我想找到每条曲线的最小点(红点)。如果我使用min(),我将只获得一条曲线。如何获得两点?
你这么厉害
答案 0 :(得分: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