用最小二乘法求积分的时候 设置函数格式的时候要将数据变成double形式 但是因为有积分就没法实现 应该怎么改正呢
clear;clc;syms t w p;%定义参数%生成数据w=[0.01,0.03,0.05,0.1,0.5,0.8,1,10,50,100]';func1=@(a)double(int((25*exp(-0.5/t^2+1/t-0.5)+10*exp(-0.5/t^2+1/t-0.5))*(1-1/(1+a^2*t^2))*(1/t),t,0.01,100));G1=arrayfun(func1,w);func2=@(a)double(int((25*exp(-0.5/t^2+1/t-0.5)+10*exp(-0.5/t^2+1/t-0.5))*(a*t/(1+a^2*t^2))*(1/t),t,0.01,100));G2=arrayfun(func2,w);G=G1+G2;%添加噪声G1_noise=[1,7,10,40,100,300,500,800,888,900]';G2_noise=[30,80,100,200,250,300,250,80,30,20]';G_noise=G1_noise+G2_noise;%调用Lspcurvefit函数func=@(p,w)double(arrayfun(@(a)int((p(1)*exp(p(2)/t^2+p(3)/t+p(4))+p(5)*exp(p(6)/t^2+p(7)/t+p(8)))*(1-1/(1+a^2*t^2))*(1/t),t,0.01,100) ... +int((p(1)*exp(p(2)/t^2+p(3)/t+p(4))+p(5)*exp(p(6)/t^2+p(7)/t+p(8)))*(a*t/(1+a^2*t^2))*(1/t),t,0.01,100),w));%选择合适的初始值p0=[450,-1,0,0,180,-10,0,-0]';p=lsqcurvefit(func,p0,w,G_noise);%拟合结果y_fit_lsq=func(p,w);%调用nlinfitpp=nlinfit(w,G_noise,func,p0);y_dit_nlin=func(pp,w); |