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

3 次查看(过去 30 天)
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by