Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Matt J
Matt J il 18 Mar 2022
Modificato: Matt J il 20 Mar 2022
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 Commenti
Matt J
Matt J il 20 Mar 2022
Modificato: Matt J il 20 Mar 2022
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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by