2019-07-17 14:56发布
mopeipei 发表于 2011-10-20 16:10 我想要拟合一曲线,原始数据是: yt=[ 521.486755 161.973785 130.258820 120.327599 90.597206 51.03395 ...
最多设置5个标签!
clear,clc
x=0.2:0.2:4.8;
y=[ 521.486755 161.973785 130.258820 120.327599 90.597206 51.033958 29.523090 19.248325 11.156927 10.221434 4.437991 3.455873 2.075573 1.551129 1.744870 0.761403 0.754921 0.532298 0.324880 0.587357 0.236039 0.227544 0.132627 2.709515];
x=x(;y=y(;
SSy=var(y)*(length(y)-1)
fx1=@(b,x)b(1)*exp(-b(2)*x);
fx2=@(b,x)b(1)*x.^b(2).*exp(-b(3)*x);
b=rand(1,2)
for l=1:5
b=lsqcurvefit(fx1,b,x,y)
b=nlinfit(x,y,fx1,b)
end
figure(1)
y1=fx1(b,x);
RSS=(y-y1)'*(y-y1)
R12=(SSy-RSS)/SSy
hold off
plot(x,y,'o')
x1=0:.1:5;
y1=fx1(b,x1);
hold on
plot(x1,y1)
b=rand(1,3)
for l=1:5
b=lsqcurvefit(fx2,b,x,y)
b=nlinfit(x,y,fx2,b)
end
y2=fx2(b,x);
RSS=(y-y2)'*(y-y2)
R22=(SSy-RSS)/SSy
figure(2)
hold off
plot(x,y,'o')
y1=fx2(b,x1);
hold on
plot(x1,y1)
一周热门 更多>