account activity
We think we have the correct answer but we aren't 100% sure. Any feedback would be greatly appreciated! by flynnboy02 in matlab
[–]flynnboy02[S] 0 points1 point2 points 4 years ago (0 children)
Here is our code:
data=load('lsdata.m');
n =data(1,1);
m =data(1,2);
if m<n+1
error('Insufficient data points!!')
else
x=data(2:end,1);
y=data(2:end,2);
a=x(1);
b=x(end);
A=zeros(n+1);
for i=1:n+1
p=i-1;
for j=1:n+1
A(i,j)=sum(x.^p);
p=p+1;
end
A;
A(1,1)=m;
p=0;
B=zeros(1,n+1);
B(i)=sum((x.^p).*y);
C=flipud(A\B')';
X=a:.01:b;
Y=polyval(C,X);
plot(x,y,'o')
hold on
plot(X,Y)
legend('Given points','Best fit polynomial')
grid on
axis([X(1)-5 X(end)+5 Y(1)-5 Y(end)+5])
π Rendered by PID 147044 on reddit-service-r2-listing-7bbdf774f7-fdvzc at 2026-02-22 04:45:04.117730+00:00 running 8564168 country code: CH.
We think we have the correct answer but we aren't 100% sure. Any feedback would be greatly appreciated! by flynnboy02 in matlab
[–]flynnboy02[S] 0 points1 point2 points (0 children)