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

 Akzeptierte Antwort

Star Strider
Star Strider am 9 Apr. 2015

0 Stimmen

It looks correct to me.

5 Kommentare

Jason
Jason am 9 Apr. 2015
Thankyou for confirmation
Star Strider
Star Strider am 9 Apr. 2015
My pleasure.
What is Mathcad giving you? (I haven’t used it in a long time, and so I don’t have it available to compare.) Are the polynomial coefficients the same as those that MATLAB calculates?
For the 5th order polyfit,
matlab gives: p5 =
-347.8636 390.0972 -971.9331 37.2882 -2.3688 0.0123
Mathcad gives:
-341.56157
378.81022
-964.45718
35.05398
-2.07866
Jason
Jason am 9 Apr. 2015
Error on my part, I hadn't included the constant for mathcad! It now exactly matches
Star Strider
Star Strider am 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Particle & Nuclear Physics finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by