Minimum and Maximum value of fitted curve

75 ビュー (過去 30 日間)
Zack Trahem
Zack Trahem 2022 年 3 月 20 日
回答済み: Nipun 2022 年 12 月 20 日
I am trying to find the minimum and maximum value of fitted curve. I will use the min and max point in another calculation. I used 'poly4' fit and its gives 4th order polynomial function. I tried polyder but couldnt go further. How can find the maximum and minimum point of fitted curve?

採用された回答

Image Analyst
Image Analyst 2022 年 3 月 20 日
編集済み: Image Analyst 2022 年 3 月 20 日
So I assume you have the red, fitted curve since you plotted it (if not see first 2 lines below), so why can't you just simply do
coefficients = polyfit(x, y, 4); % fit to a 4th order polynomial.
yfit = polyval(coefficients, x); % Evaluate the fit at the same x values.
minFit = min(yFit); % Find min of fitted curve in the range we have fit it over.
maxFit = max(yFit); % Find max of fitted curve in the range we have fit it over.
If you want, you can use an x in polyval() that has finer resolution than the original x. Something like
numSamplePoints = 2000; % However many you need to get the resolution you want.
xFit = linspace(min(x), max(x), numSamplePoints);
yfit = polyval(coefficients, xFit); % Evaluate the fit at the same x values.
Of course you could get the exact value of the apex just by computing the derivative from the coefficients vector.
  2 件のコメント
Zack Trahem
Zack Trahem 2022 年 3 月 20 日
Thank you so much thats exactly what i looking for:) .just one more thing, that is coresponded x values of for min and max data.
scatter(Bw(:,1),Bw(:,2))
f=fit(length,Bw(:,2),'poly4')
plot(f,length,w0)
c=coeffvalues(f);
yfit=polyval(c,length);
minfit=min(yfit)
maxfit=max(yfit)
for now i made this way and gives the values Thank you again.
Zack Trahem
Zack Trahem 2022 年 3 月 20 日
I solved it thanks a lot!
minindex=find(yfit==minfit);
maxindex=find(yfit==maxfit);
maxPoint=xFit(minindex);
minPoint=xFit(maxindex);

サインインしてコメントする。

その他の回答 (2 件)

Torsten
Torsten 2022 年 3 月 20 日
編集済み: Torsten 2022 年 3 月 20 日
p = polyfit(x,y,4);
dp=polyder(p);
ddp=polyder(dp);
r=roots(dp);
r=r(abs(imag(r) ) < 1e-6);
maxima=r(polyval(ddp,r))<=1e-6 )
minima=r(polyval(ddp,r))>=1e-6 )
Extrema at the boundaries are not accounted for.

Nipun
Nipun 2022 年 12 月 20 日
Use the curve of best fit to find the maximum and minimum flow rates separately during the inflow and the outflow

カテゴリ

Help Center および File ExchangeCurve Fitting Toolbox についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by