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.

温馨提示:内容为网友见解,仅供参考
第1个回答  2011-11-30
在每个函数中都io.output一个文件,然后往里面写数据。其他4个都有写,就这个两个没有。我换其他代码,通通没用,我要崩溃了
相似回答