1 function deconvolution
2 data=load('0.10-645.dat');
3 xdata=data(:,1);
4 ydata=data(:,2);
5 x0=[0.1];
6 %x(1)为脉宽,x(2)为时间零点,x(3)为A1,x(4)为t1,x(5)为A2,x(6)为t2
7 %-----------------------------------------------------------
8 options=optimset('TolFun',1e-4,'TolX',1e-4,'MaxIter',1e9,'MaxFunEvals',1e9);
9 [x,resnorm,residual,exitflag,output]=lsqcurvefit(@fun,x0,xdata,ydata,options);
10 disp('the fitted parameter isdelta mu A1 tau1 A2 tau2)');disp(x);
11 disp('the resnorm is:');disp(resnorm);
12 disp('the exit flag is:');disp(exitflag);
13 disp(output);
14 %--------------------------------------------------------------------------fit
15 Fp=fun(x,xdata);
16 irf=-1*2*sqrt(log(2))/0.06/sqrt(pi)*exp(-log(2)*(2*(xdata-x(2))/x(1)).^2)/20;
17 subplot(2,1,1); plot(data(:,1),Fp,'b-',xdata,ydata,'ro',xdata,irf,'g');
18 subplot(2,1,2); plot(data(:,1),residual,'g*');
19 %-------------------------------------------------------------------------
20 result=[xdata ydata Fp residual irf];
21 save -ASCII -DOUBLE result.dat result;
22 y=[x resnorm];
23 save -ASCII -DOUBLE parameters.dat y;
24 function F=fun(x,xdata)
25 delta1=x(1)/(sqrt(log(4)));
26 F1=x(3).*exp(delta1^2/x(4)^2/2).*exp(-(xdata-x(2))/x(4)).*(1+erf(((xdata-x(2))/delta1-delta1/x(4))/sqrt(2)));
27 F2=x(5).*(1+erf((xdata-x(7))/sqrt(2)/delta1)-exp(delta1^2/x(6)^2/2).*exp(-(xdata-x(7))/x(6)).*(1+erf(((xdata-x(7))/delta1-delta1/x(6))/sqrt(2))));
28 F=F1+F2;
执行命令时出现:
错误使用 lsqcurvefit (line 181)
LSQCURVEFIT requires the following inputs to be of data type double: 'LB'.
出错 Untitled2 (line 9)
[x,resnorm,residual,exitflag,output]=lsqcurvefit(@fun,x0,xdata,ydata,options);
应该如何修改?