已知函数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文件。
可否画出函数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.