作业帮 > 综合 > 作业

matlab函数lsqnonlin用法,

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/19 15:25:21
matlab函数lsqnonlin用法,
已知函数Y=a(1) +a(2)*H+a(3)*H*H+a(4)*H*H*H+a(5)*sin((2*pi*t)/365)+a(6)*sin((4*pi*t)/365)+a(7)*cos((2*pi*t)/365)+a(8)*cos((4*pi*t)/365)+a(9)*t+a(10)*log(1+t)+a(11)/(t+1).现有N组(H,t,y)值,用最小二乘法子求出a(1)至a(11)的值.请写出M文件.
N = 45; % 每个变量的数据的个数
H = rand(N,1); % 将H整理为列向量,在此输入H的值
t = rand(N,1); % 将t整理为列向量,在此输入t的值
y = rand(N,1); % 将y整理为列向量,在此输入y的值
YY = @(a) a(1)+a(2).*H+a(3).*H.*H+a(4).*H.*H.*H+a(5)*sin((2*pi.*t)/365)+a(6)*sin((4*pi.*t)/365)+a(7)*cos((2*pi.*t)/365)+a(8)*cos((4*pi.*t)/365)+a(9).*t+a(10)*log(1+t)+a(11)./(t+1) - y
x0 = [0.3 0.4 0.3 0.4 0.3 0.4 0.3 0.4 0.3 0.4 0.3] % Starting guess
[x,resnorm] = lsqnonlin(YY,x0) % Invoke optimizer x即为用最小二乘法求出的a(1)至a(11)的值
如有问题,请继读联系
再问: 可否画出函数y的图像,残差图以及求解复相关系数?
再答: 建议你使用sftool做,方便多了。 sftool和cftool用法相同。 在2011b中,cftool也有sftool的功能。 ... ... [x,resnorm,residual] = lsqnonlin(YY,x0) ... [x,resnorm] = lsqnonlin(...) returns the value of the squared 2-norm of the residual at x: sum(fun(x).^2). [x,resnorm,residual] = lsqnonlin(...) returns the value of the residual fun(x) at the solution x. [x,resnorm,residual,exitflag] = lsqnonlin(...) returns a value exitflag that describes the exit condition. [x,resnorm,residual,exitflag,output] = lsqnonlin(...) returns a structure output that contains information about the optimization. [x,resnorm,residual,exitflag,output,lambda] = lsqnonlin(...) returns a structure lambda whose fields contain the Lagrange multipliers at the solution x. [x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(...) returns the Jacobian of fun at the solution x.