function f=example1(c,tdata) f=c(1)*(exp(-c(2)*tdata)-exp(-c(3)*tdata));
x=1:1:12; y=[0 0 0 1 0 3 10 12 8 2 1 2 ]'; c0=[2 8]; for i=1:1000 c=lsqcurvefit(@zhengtai,c0,x,y); c0=c; end y1=(1./(sqrt(2.*3.14).*c(1))).*exp(-(x-c(1)).^2./(2.*c(2)^2)); plot(x,y,'r-',x,y1); legend('实验数据','拟合曲线')
x=[0.25 0.5 0.75 1 1.5 2 2.5 3 3.5 4 4.5 5 6 7 8 9 10 11 12 13 14 15 16]'; y=[30 68 75 82 82 77 68 68 58 51 50 41 38 35 28 25 18 15 12 10 7 7 4]'; f=@(c,x)c(1)*(exp(-c(2)*x)-exp(-c(3)*x)); c0=[114 0.1 2]'; for i=1:50 opt=optimset('TolFun',1e-3); [c R]=nlinfit(x,y,f,c0,opt) c0=c; hold on plot(x,c(1)*(exp(-c(2)*x)-exp(-c(3)*x)),'g') end
t=[0.25 0.5 0.75 1 1.5 2 2.5 3 3.5 4 4.5 5 6 7 8 9 10 11 12 13 14 15 16];y=[30 68 75 82 82 77 68 68 58 51 50 41 38 35 28 25 18 15 12 10 7 7 4];c0=[1 1 1];for i=1:50 c=lsqcurvefit(@example1,c0,t,y); c0=c;endy1=c(1)*(exp(-c(2)*t)-exp(-c(3)*t));plot(t,y,'+',t,y1);legend('实验数据','拟合曲线')
function f=zhengtai(c,x)
f=(1./(sqrt(2.*3.14).*c(1))).*exp(-(x-c(1)).^2./(2.*c(2)^2));
x=1:1:12; y=[0 0 0 1 0 3 10 12 8 2 1 2 ]'; c0=[2 8]; for i=1:1000 c=lsqcurvefit(@zhengtai,c0,x,y); c0=c; end y1=(1./(sqrt(2.*3.14).*c(1))).*exp(-(x-c(1)).^2./(2.*c(2)^2)); plot(x,y,'r-',x,y1); legend('实验数据','拟合曲线')
x=[0.25 0.5 0.75 1 1.5 2 2.5 3 3.5 4 4.5 5 6 7 8 9 10 11 12 13 14 15 16]'; y=[30 68 75 82 82 77 68 68 58 51 50 41 38 35 28 25 18 15 12 10 7 7 4]'; f=@(c,x)c(1)*(exp(-c(2)*x)-exp(-c(3)*x)); c0=[114 0.1 2]'; for i=1:50 opt=optimset('TolFun',1e-3); [c R]=nlinfit(x,y,f,c0,opt) c0=c; hold on plot(x,c(1)*(exp(-c(2)*x)-exp(-c(3)*x)),'g') end
t=[0.25 0.5 0.75 1 1.5 2 2.5 3 3.5 4 4.5 5 6 7 8 9 10 11 12 13 14 15 16];y=[30 68 75 82 82 77 68 68 58 51 50 41 38 35 28 25 18 15 12 10 7 7 4];c0=[1 1 1];for i=1:50 c=lsqcurvefit(@example1,c0,t,y); c0=c;endy1=c(1)*(exp(-c(2)*t)-exp(-c(3)*t));plot(t,y,'+',t,y1);legend('实验数据','拟合曲线')