Calculating Residuals from polyfit
8 views (last 30 days)
Show older comments
I just wanted to check that I am calculating residuals correctly as I am gettign a different answer compared to mathcad. M is my matrix of data, of which I plot column 1 (x-axis) against column 5 (y axis)
I am performing both 3rd and 5th order polynomial fits
x=M(:,1);
y=M(:,5);
p3=polyfit(x,y,3);
f3=polyval(p3,x);
p5=polyfit(x,y,5);
f5=polyval(p5,x);
plot(x,f3,'b--')
plot(x,f5,'g--')
legend('Zmx','3rd','5th')
%Calc Residuals
y3=y-f3;
y5=y-f5
axes(handles.axes2)
cla
plot(x,y3,'bd--','MarkerSize', 3)
grid on
hold on
plot(x,y5,'rd--','MarkerSize', 3)
legend('3rd','5th')
Is that correct for the residuals e.g. y3 = y-f3 ?? thanks Jason
0 Comments
Accepted Answer
Star Strider
on 9 Apr 2015
It looks correct to me.
5 Comments
Star Strider
on 9 Apr 2015
No worries. I was just curious as to how you managed to get different results from both. There could be slight differences depending on precision and how both deal with floating point approximation errors, but they should be close.
So apparently they’re now both giving the same results and residuals?
More Answers (0)
See Also
Categories
Find more on Particle & Nuclear Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!