马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
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.
请问问题出在哪里?
老是跳出些错误,所以都用最保险的写,方程式才会那么长
各位高手帮忙看下! |