Polynomial Regression and finding Standard Error

15 次查看(过去 30 天)
Assign 1.jpg
Please help me double check my work here ♥
x = [-4 7 -5 -9 2 -6 1 10];
y = [13 -3 -16 -19 -12 1 9 -5];
c1 = [length(x) sum(x) sum(x.^2) sum(x.^3) sum(x.^4) sum(x.^5)]';
c2 = [sum(x) sum(x.^2) sum(x.^3) sum(x.^4) sum(x.^5) sum(x.^6)]';
c3 = [sum(x.^2) sum(x.^3) sum(x.^4) sum(x.^5) sum(x.^6) sum(x.^7)]';
c4 = [sum(x.^3) sum(x.^4) sum(x.^5) sum(x.^6) sum(x.^7) sum(x.^8)]';
c5 = [sum(x.^4) sum(x.^5) sum(x.^6) sum(x.^7) sum(x.^8) sum(x.^9)]';
c6 = [sum(x.^5) sum(x.^6) sum(x.^7) sum(x.^8) sum(x.^9) sum(x.^10)]';
N = [c1 c2 c3 c4 c5 c6]
r = [sum(y) sum(x.*y) sum(x.^2.*y) sum(x.^3.*y) sum(x.^4.*y) sum(x.^5.*y)]'
%Solve
a = N\r
%Plotting
xx = linspace(-9,10,500);
yy = polyval(flipud(a),xx);
plot(x,y,'or',xx,yy,'-b')

回答(1 个)

Duncan Carlsmith
Duncan Carlsmith 2024-5-16

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by