Get tangents (+ linear equation of tangents) of turning points in cfit graph

1 回表示 (過去 30 日間)
Jerry
Jerry 2022 年 3 月 18 日
コメント済み: Jerry 2022 年 3 月 21 日
Hello,
I plotted a cfit graph with the matlab curveFitterTool. The original graph was fitted via polynomial fit of the 9th grade.
Now I am trying to plot and get the equation of the tangents of turning points of the derivated graph of the cfit graph.
I already got the 2nd derivation graph via "differentiate" function. There are turning points, if the second derivation = 0 and the third derivation =/ 0. But theres no clear polynomial equation for the fitted graph, so there are problems to filter the turning points.
Is there any way to get the turning point tangents and their linear equation of my derivated cfit-graph without having constand polynomial variable values?
%% Polynomial Fit Grad 9
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'poly9' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'x', 'Interpreter', 'none' );
ylabel( 'y', 'Interpreter', 'none' );
grid on
%% Derivation
[fStrich,fStrichStrich] = differentiate(fitresult,xData);

採用された回答

Matt J
Matt J 2022 年 3 月 18 日
編集済み: Matt J 2022 年 3 月 20 日
p=flip(coeffvalues(ft));
dp=polyder(p);
ddp=polyder(dp);
dddp=polyder(ddp); %3rd derivative
r=roots(ddp);
turingpoints=r(abs(polyval(dddp,r))>=tolerance)
  8 件のコメント
Matt J
Matt J 2022 年 3 月 20 日
編集済み: Matt J 2022 年 3 月 20 日
I brushed out the defective-looking x,y data and reattached it here. I apply the method that I originally posted (plus Torsten's modification) and get the results below. There seem to be 3 turning points
load data
s=1e14; %scale factor
x=x/s;
y=y/s;
p=polyfit(x,y,9);
plot(s*x(1:10:end),s*y(1:10:end),'.',s*x,s*polyval(p,x),'-');
legend('Original Data','Fit','location','southeast')
dp=polyder(p);
ddp=polyder(dp);
dddp=polyder(ddp); %3rd derivative
r=roots(ddp);
turningpoints=r(abs(polyval(dddp,r))>=1e-6 & abs(imag(r )) < 1e-6)*s
turningpoints = 3×1
1.0e+14 * 2.4232 1.3979 1.0582
Jerry
Jerry 2022 年 3 月 21 日
This is working perfectly, thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by