Fit equation not correct for x vector
Show older comments
Hi everyone,
I am trying to fit a serie (x,y) of data with a polynomial equation. I have found the equation that fit my data and well reproduce the trend. Nevertheless, the equation solution for the x vector does not give the initial y values. I post the code to be clearer.
Thank you in advance for your help!
x2= [8;8.5;9;9.3;9.5;9.8]; y2=[0.280;0.283;0.287;0.293;0.309;0.350]; curvefit = fit(x2,y2,'poly4','normalize','off'); figure,plot(curvefit,x2,y2) %the fitting weel reproduce data
% equation given by the fitting p1 = 0.005065 ; p2 = 0.0148 ; p3 = 0.01398 ; p4 = 0.008919 ; p5 = 0.2871 ; y2f=p1*x2.^4 + p2*x2.^3 + p3*x2.^2 + p4*x2 + p5; figure,scatter(x2,y2) hold on,plot(x2,y2f) %the y values given by the fitting equation are far from the initial y values
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!