24小时热门版块排行榜    

查看: 2072  |  回复: 11
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

清晨清晨

银虫 (初入文坛)

[求助] 好心虫友,帮忙看看这个matlab程序那里出错了 已有1人参与

用matlab拟合数据,进行NRTL模型拟合:我编写了如下的程序,一直出错,麻烦有懂的虫友帮忙看看,怎么改错??
(一)定义.m文件。
function g4=f(beta0,x1,x2,T,R)
g1=beta0(1);
g2=beta0(2);
g3=beta0(3);
g4=beta0(4);
g4=x2.*x2.*((((g(1)./(R.*T)).*(exp(-g(3).*g(1)./(R.*T))).^2)./((x1+(exp(-g(3).*g(1)./(R.*T))).*x2).^2))+(((g(2)./(R.*T)).*(exp(-g(3).*g(2)./(R.*T))).^2)./((x2+(exp(-g(3).*g(2)./(R.*T))).*x1).^2)))
(二)编写程序。
x1=[0.01525        0.02059        0.02685        0.03417        0.04221        0.04958];
x2=[0.98475        0.97941        0.97315        0.96583        0.95779        0.95042];
T=[298.15        303.15        308.15        313.15        318.15        323.15];
R=[8.314 8.314 8.314 8.314 8.314 8.314];
beta0=[0,0,0,0];
[g,resnorm]=lsqcurvefit(@f,beta0,x1,x2,T,R)
运行后出错:
Warning: Length of lower bounds is > length(x); ignoring extra bounds.
> In checkbounds at 27
  In optim\private\lsqncommon at 39
  In lsqcurvefit at 149
  In Untitled2 at 6
Warning: Length of upper bounds is > length(x); ignoring extra bounds.
> In checkbounds at 37
  In optim\private\lsqncommon at 39
  In lsqcurvefit at 149
  In Untitled2 at 6
Exiting due to infeasibility:  4 lower bounds exceed the corresponding upper bounds.

g =

     0     0     0     0


resnorm =

     []
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

清晨清晨

银虫 (初入文坛)

引用回帖:
6楼: Originally posted by somomo91 at 2017-07-09 18:07:54
最后是 alpha12 和 alpha21 的值,根据文献应该在 0.20-0.47 之间。
程序里面全为零,

那我初始值就定义4个可以吗?我按照你说的改了程序,把初始值改为【1,1,0.3,1】不再为0,结果出来后就是Warning: Length of lower bounds is > length(x); ignoring extra bounds.
> In checkbounds at 27
  In optim\private\lsqncommon at 39
  In lsqcurvefit at 149
  In Untitled2 at 6
Warning: Length of upper bounds is > length(x); ignoring extra bounds.
> In checkbounds at 37
  In optim\private\lsqncommon at 39
  In lsqcurvefit at 149
  In Untitled2 at 6
Exiting due to infeasibility:  4 lower bounds exceed the corresponding upper bounds.

g =

    1.0000    1.0000    0.3000    1.0000


resnorm =

     []
就是我定义的值,我也把公式做了改变的g4=exp(x2.*x2.*((((g(1)./(R.*T)).........)
7楼2017-07-09 18:40:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 12 个回答

somomo91

专家顾问 (职业作家)

【答案】应助回帖


感谢参与,应助指数 +1
jjdg: 金币+1, 感谢参与 2017-09-28 23:50:04
这里的 beta0 有4个元素,但是 上下边界 有 6个元素,所以会出错
beta0 元素的个数应该和 R,T 一致。
CODE:
lsqcurvefit(fun,x0,xdata,ydata,lb,ub)

但即使beta0 有6个0,你会看到结果应该还不对。
没看方程,没法确定到底你的程序哪里出错
2楼2017-07-09 17:29:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

清晨清晨

银虫 (初入文坛)

引用回帖:
2楼: Originally posted by somomo91 at 2017-07-09 17:29:24
这里的 beta0 有4个元素,但是 上下边界 有 6个元素,所以会出错
beta0 元素的个数应该和 R,T 一致。
lsqcurvefit(fun,x0,xdata,ydata,lb,ub)

但即使beta0 有6个0,你会看到结果应该还不对。
没看方程,没法 ...

这个是需要拟合的公式,只需要求4个变量,所以我beta0只给了4个值
好心虫友,帮忙看看这个matlab程序那里出错了
IMG_20170709_174704.jpg

3楼2017-07-09 17:49:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

清晨清晨

银虫 (初入文坛)

引用回帖:
2楼: Originally posted by somomo91 at 2017-07-09 17:29:24
这里的 beta0 有4个元素,但是 上下边界 有 6个元素,所以会出错
beta0 元素的个数应该和 R,T 一致。
lsqcurvefit(fun,x0,xdata,ydata,lb,ub)

但即使beta0 有6个0,你会看到结果应该还不对。
没看方程,没法 ...

这个是需要拟合的公式,只需要求4个变量,所以我beta0只给了4个值
好心虫友,帮忙看看这个matlab程序那里出错了-1
IMG_20170709_174704.jpg

4楼2017-07-09 17:49:43
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见