Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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);

Respuesta aceptada

Matt J
Matt J el 18 de Mzo. de 2022
Editada: Matt J el 20 de Mzo. de 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 comentarios
Matt J
Matt J el 20 de Mzo. de 2022
Editada: Matt J el 20 de Mzo. de 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
Jerry
Jerry el 21 de Mzo. de 2022
This is working perfectly, thank you very much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by