声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1483|回复: 2

[工具箱] 求:关于nlinfit函数的问题

[复制链接]
发表于 2010-3-9 21:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
M 文件:
function yhat = mymodel1(beta, x)

yhat=(beta(1)+beta(2)*x(:,1)+beta(3)*x(:,2)+beta(4)*x(:,3)+beta(5)*x(:,4)+beta(6)*x(:,5)+beta(7)*x(:,1).*x(:,1)+beta(8)*x(:,2).*x(:,2)+beta(9)*x(:,3).*x(:,3)+beta(10)*x(:,4).*x(:,4)+beta(11)*x(:,5).*x(:,5)+beta(12)*x(:,1).*x(:,2)+beta(13)*x(:,1).*x(:,3)+beta(14)*x(:,1).*x(:,4)+beta(15)*x(:,1).*x(:,5)+beta(16)*x(:,2).*x(:,3)+beta(17)*x(:,2).*x(:,4)+beta(18)*x(:,2).*x(:,5)+beta(19)*x(:,3).*x(:,4)+beta(20)*x(:,3).*x(:,5)+beta(21)*x(:,4).*x(:,5));

命令:
x=[1,1,2,1,2;
1,2,1,4,4;
1,3,3,2,1;
1,4,4,3,3;
2,1,4,2,4;
2,2,3,3,2;
2,3,1,1,3;
2,4,2,4,1;
3,1,1,3,1;
3,2,2,2,3;
3,3,4,4,2;
3,4,3,1,4;
4,1,3,4,3;
4,2,4,1,1;
4,3,2,3,4;
4,4,1,2,2];

y=[0.1726,0.1604,0.0997,0.1132,0.1753,0.1130,0.1476,0.0772,0.1071,0.1528,0.1065,0.1567,0.1473,0.1135,0.1323,0.1301];

beta0=[0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01];

beta = nlinfit(x,y,'mymodel1',beta0)

结果:报错
??? Error using ==> nlinfit
MODELFUN should return a vector of fitted values the same length as Y.

请问问题出在哪里?


老是跳出些错误,所以都用最保险的写,方程式才会那么长
各位高手帮忙看下!
回复
分享到:

使用道具 举报

发表于 2010-3-10 08:01 | 显示全部楼层
把y改成列向量即可,即在y=……后加一行y=y';
仔细看一下nlinfit的参数输入格式要求

评分

1

查看全部评分

 楼主| 发表于 2010-3-10 08:36 | 显示全部楼层

回复 沙发 friendchj 的帖子

好的,我试下,谢谢
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-13 19:05 , Processed in 0.067769 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表