Get tangents (+ linear equation of tangents) of turning points in cfit graph
1 次查看(过去 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);
0 个评论
采纳的回答
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!