声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1715|回复: 2

[求助]matlab解非线性方程组出错

[复制链接]
发表于 2006-2-27 22:48 | 显示全部楼层 |阅读模式

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

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

x
<P>用matlab解非线性方程组出错了,出错信息如下:<BR>??  In an assignment  A(I) = B, the number of elements in B and<BR> I must be the same.<BR><BR>Error in ==&gt; thermal&gt;NonlinEqs at 24<BR>f(4)=x(3).^2.*x(4).^2-K1.*x(1).*x(2)./(P./xtotal).^2;<BR><BR>Error in ==&gt; fsolve at 180<BR>        fuser = feval(funfcn{3},x,varargin{:});<BR><BR>Error in ==&gt; thermal at 14<BR>x1 =fsolve(@NonlinEqs,x0,[],K1,K2,K3,n10,n20)<BR><BR><BR>程序如下<BR>function xFsolve<BR>% xFsolve.m<BR>% 求解热力学平衡计算</P>
<P>clear all<BR>clc</P>
<P>n10=0.2;n20=1-n10;<BR>T=500:100:1500;             %体系温度,K<BR>K1=exp(7.9305.*log(T)-5.6347e-03.*T+5.8622e-07.*T.^2-2.7848e+04./T-19.03390284);<BR>K2=exp(0.248617.*log(T)-1.4693e-03.*T+2.28e-07.*T.^2-4.1539e+04./T+4.213066);<BR>K3=exp(6.833053.*log(T)-3.7606e-03.*T+3.48e-07.*T.^2-7.276675e+03./T-33.8969);<BR>x0 = [n10 n20 0 0 0 0]';<BR>x1 =fsolve(@NonlinEqs,x0,[],K1,K2,K3,n10,n20)</P>
<P><BR>% ------------------------------------------------------------------<BR>function f = NonlinEqs(x,K1,K2,K3,n10,n20)<BR>P=101325;<BR>xtotal=x(1)+x(2)+x(3)+x(4)+x(5)+x(6);<BR>f(1) = x(1)+x(2)+x(3)+x(6)-1;<BR>f(2) = 2*x(1)+x(4)+x(5)-2*n10;<BR>f(3)=2.*x(2)+x(3)+x(5)-2*n20;<BR>f(4)=x(3).^2.*x(4).^2-K1.*x(1).*x(2)./(P./xtotal).^2;<BR>f(5)=x(3).*x(5)-K2.*x(2).*x(4);<BR>f(6)=x(6).*x(4).^2-K3.*x(1);<BR><BR><BR></P>
回复
分享到:

使用道具 举报

发表于 2006-2-28 08:44 | 显示全部楼层

回复:(mathtype)[求助]matlab解非线性方程组出错

<DIV class=quote><B>以下是引用<I>mathtype</I>在2006-2-27 22:48:38的发言:</B><BR>
<P>用matlab解非线性方程组出错了,出错信息如下:<BR>??  In an assignment  A(I) = B, the number of elements in B and<BR>I must be the same.<BR><BR>Error in ==&gt; thermal&gt;NonlinEqs at 24<BR>f(4)=x(3).^2.*x(4).^2-K1.*x(1).*x(2)./(P./xtotal).^2;<BR><BR>Error in ==&gt; fsolve at 180<BR>        fuser = feval(funfcn{3},x,varargin{:});<BR><BR>Error in ==&gt; thermal at 14<BR>x1 =fsolve(@NonlinEqs,x0,[],K1,K2,K3,n10,n20)<BR><BR><BR>程序如下<BR>function xFsolve<BR>% xFsolve.m<BR>% 求解热力学平衡计算</P>
<P>clear all<BR>clc</P>
<P>n10=0.2;n20=1-n10;<BR>T=500:100:1500;             %体系温度,K<BR>K1=exp(7.9305.*log(T)-5.6347e-03.*T+5.8622e-07.*T.^2-2.7848e+04./T-19.03390284);<BR>K2=exp(0.248617.*log(T)-1.4693e-03.*T+2.28e-07.*T.^2-4.1539e+04./T+4.213066);<BR>K3=exp(6.833053.*log(T)-3.7606e-03.*T+3.48e-07.*T.^2-7.276675e+03./T-33.8969);<BR>x0 = [n10 n20 0 0 0 0]';<BR>x1 =fsolve(@NonlinEqs,x0,[],K1,K2,K3,n10,n20)</P>
<P><BR>% ------------------------------------------------------------------<BR>function f = NonlinEqs(x,K1,K2,K3,n10,n20)<BR>P=101325;<BR>xtotal=x(1)+x(2)+x(3)+x(4)+x(5)+x(6);<BR>f(1) = x(1)+x(2)+x(3)+x(6)-1;<BR>f(2) = 2*x(1)+x(4)+x(5)-2*n10;<BR>f(3)=2.*x(2)+x(3)+x(5)-2*n20;<BR>f(4)=x(3).^2.*x(4).^2-K1.*x(1).*x(2)./(P./xtotal).^2;<BR>f(5)=x(3).*x(5)-K2.*x(2).*x(4);<BR>f(6)=x(6).*x(4).^2-K3.*x(1);<BR><BR><BR></P></DIV>
<P><BR>x(3).^2.*x(4).^2  <FONT color=#ff00ff>是一个数</FONT><BR>K1.*x(1).*x(2)./(P./xtotal).^2;  <FONT color=#ff00ff>是向量,两者无法相加</FONT></P>
发表于 2006-5-15 14:44 | 显示全部楼层
高!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-5-11 03:31 , Processed in 0.116532 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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