用matlab做曲线拟合

来源:百度知道 编辑:UC知道 时间:2024/05/28 13:31:47
x=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
y=-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 6 6

画出曲线拟合后的图形
急用 谢谢各位!!!!!!!!

x=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];
y=[=-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 6 6];
m=length(x);
w=ones(m,1);
n=4;
c=zeros(n);
c1=zeros(n,1);
for i=1:n
for j=1:n
sum=0;
for k=1:m
sum=sum+w(k)*x(k)^(i+j-2);
end
c(i,j)=sum;
end
end
for i=1:n
sum=0;
for j=1:m
sum=sum+w(j)*x(j)^(i-1)*y(j);
end
c1(i)=sum;
end
c
c1
t=c\c1
h=0:0.1:55;
y1=t(1)+t(2)*h+t(3)*h.^2+t(4)*h.^3;
plot(x,y,'k*',h,y1,'b')
title('在三次曲线拟合下的曲线')