登录论坛

查看完整版本 : [MATLAB数学相关] 有关于nlinfit非线性拟合的问题 谢谢各位大侠指导呀


溺水的鱼88
2011-11-15, 10:41
有关于nlinfit非线性拟合的问题 谢谢各位大侠指导呀

x1=[-292.2,-137.3,1120.9,-33877.0,-35100.1,33812.2,-48791.0,-74.3,48609.9];
x2=[-35588.1,-36343.4,35635.9,-808.6,-24.9,-330.5,-298.3,-50834.3,-466.1];
x3=[35238.0,-34957.3,-35201.9,35506.2,-34776.5,-35558.4,-971.7,-1357.6,-219.5];
x=[x1,x2,x3];
y=[51688.7^2,51688.3^2,51690.0^2,51689.7^2,51689.5^2,51688.9^2,51689.9^2,51690.1^2,51691.9^2];
beta0=[-0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -100.0 -100.0 -100.0];
myfun=@(a,x)a(1).*(x(:,1)-a(7))^2+a(2).*(x(:,2)-a(8))^2+a(3)*(x(:,3)-a(9))^2+a(4).*(x(:,1)-a(7))*(x(:,2)-a(8))+a(5).*(x(:,2)-a(8))*(x(:,3)-a(9))+a(6).*(x(:,3)-a(9))*(x(:,1)-a(7));
[a,b,c,d,res]=nlinfit(x,y,myfun,beta0);
a;
plot3(x1,x2,x3,y,'o',x1,x2,x3,myfun(a,x));
程序是这个
报错
??? Error using ==> nlinfit at 127
MODELFUN should return a vector of fitted values the same length as Y.

Error in ==> nlinfit0 at 8
[a,b,c,d,res]=nlinfit(x,y,myfun,beta0);

请问大侠是什么问题呢?

还有如果使用optimization tool 能解决这个拟合问题么 谢谢指导了

mathjiang
2011-11-19, 20:09
x是1*27的向量,y是1*9的向量。

x1=[-292.2,-137.3,1120.9,-33877.0,-35100.1,33812.2,-48791.0,-74.3,48609.9];
x2=[-35588.1,-36343.4,35635.9,-808.6,-24.9,-330.5,-298.3,-50834.3,-466.1];
x3=[35238.0,-34957.3,-35201.9,35506.2,-34776.5,-35558.4,-971.7,-1357.6,-219.5];
x=[x1;x2;x3]; %其中逗号改为分号.