mathtype 发表于 2006-2-27 22:48

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

<P>用matlab解非线性方程组出错了,出错信息如下:<BR>??In an assignmentA(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 = ';<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>

happy 发表于 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 assignmentA(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 = ';<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>

realyyy 发表于 2006-5-15 14:44

高!
页: [1]
查看完整版本: [求助]matlab解非线性方程组出错