找回密码
 注册
Simdroid-非首页
查看: 204|回复: 6

[数值计算] 求解一个方程组(个人认为有点挑战性,目前我们同学和老师们全都不会做)

[复制链接]
发表于 2011-4-16 23:50:21 | 显示全部楼层 |阅读模式 来自 美国
本帖最后由 zsmiup 于 2011-4-17 00:06 编辑

T = 1/8 (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l)
(\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l) = (1/
  3) (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) Log[(\[Rho]l (3 \
- \[Rho]g))/(\[Rho]g (3 - \[Rho]l))]
  
(* 第二方程可以简化为: (\[Rho]l-\[Rho]g)(6-\[Rho]g-\[Rho]l)=8/3*T*Log[(\[Rho]l \
(3-\[Rho]g))/(\[Rho]g (3-\[Rho]l))], 因为T=1/8 (3-\[Rho]g)(3-\[Rho]l)(\
\[Rho]g+\[Rho]l)*)

T -> temperature , from 0, to 1 从0变化到1
\[Rho]l -> density of liquid
\[Rho]g -> density of gas
p -> pressure
P[\[Rho]_] := (8 \[Rho]*(T))/(3 - \[Rho]) - 3 \[Rho]^2
(* \[Rho]l,\[Rho]g 都满足上式,密度和压力方程*)

T = 1/8 (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l)
(\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l) =
1/3 (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) Log[(\[Rho]l (3 \
- \[Rho]g))/(\[Rho]g (3 - \[Rho]l))]
另有关于\[Rho]l,pg和温度的表达式。
目的,是数值法 (T = T0 + 0.01, T0 = 0,
   Tmax = 1) ,解出,在相同的温度T下的\[Rho]l和\[Rho]g。 并作 P - \[Rho]l 和 P - \
\[Rho]g (压力和密度图) 证明 这两曲线相切,切点为 气液共同点

我的思路是用 For loop ,来求解。
但是问题是这个方程组,太难解,Mathematica 解起来就没完了,我取T =
0.5 , 就想算一个值,我等了20分钟都没有算完,所以想请教高手们怎么可以解下列方程组。
我试了, Solve, Reduce, FindRoot,Nsolve,我还分别解了这两个方程 【就是用\[Rho]g表示\[Rho]g】 \
,然后Plot 他们,想找到他们的交点。 但是第2个方程还是解不出来,想请教高手们出出主意
T = 1/8 (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l)
(\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l) = (1/
  3) (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) Log[(\[Rho]l (3 \
- \[Rho]g))/(\[Rho]g (3 - \[Rho]l))]
  
(* 第二方程可以简化为: (\[Rho]l-\[Rho]g)(6-\[Rho]g-\[Rho]l)=8/3*T*Log[(\[Rho]l \
(3-\[Rho]g))/(\[Rho]g (3-\[Rho]l))], 因为T=1/8 (3-\[Rho]g)(3-\[Rho]l)(\
\[Rho]g+\[Rho]l)*)


  下面是我试着的解,谢谢

Test body
\!\(\*
ButtonBox["For",
BaseStyle->"Link",
ButtonData->"paclet:ref/For"]\)[start, test, incr, body]
executes start, then repeatedly evaluates body and incr until test \
fails to give \!\(\*
ButtonBox["True",
BaseStyle->"Link",
ButtonData->"paclet:ref/True"]\).




T = 1
Reduce[1/8 (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) ==
  T, {\[Rho]g, \[Rho]l}]


1

-3 + \[Rho]g !=
  0 && (\[Rho]l == (-9 +
     6 \[Rho]g - \[Rho]g^2 - (-1 + \[Rho]g) Sqrt[-15 +
       2 \[Rho]g + \[Rho]g^2])/(
    2 (-3 + \[Rho]g)) || \[Rho]l == (-9 +
     6 \[Rho]g - \[Rho]g^2 + (-1 + \[Rho]g) Sqrt[-15 +
       2 \[Rho]g + \[Rho]g^2])/(2 (-3 + \[Rho]g)))


T = 1
Reduce[(\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l) ==
  1/3*T*Log[(\[Rho]l (3 - \[Rho]g))/(\[Rho]g (3 - \[Rho]l))], \
{\[Rho]g, \[Rho]l}]


1

$Aborted



Clear["Global"]
T = 0.01

Solve[{(3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) ==
   T, (\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l) ==
   1/3*T*Log[(\[Rho]l (3 - \[Rho]g))/(\[Rho]g (3 - \[Rho]l))]}, {\
\[Rho]l, \[Rho]g}]


Clear["\[Rho]l"] ,

NSolve[(\[Rho]l - 0.5) (6 - .5 - \[Rho]l) ==
  8/3*1/8 (3 - .5) (3 - \[Rho]l) (.5 + \[Rho]l)*
   Log[(\[Rho]l (3 - .5))/(0.5 (3 - \[Rho]l))], \[Rho]l] (* T=.5 *)

NSolve[(5.5` - \[Rho]l) (-0.5` + \[Rho]l) ==
  0.8333333333333333` (3 - \[Rho]l) (0.5` + \[Rho]l) (Log[
      5.` \[Rho]l] - Log[3 - \[Rho]l]), \[Rho]l]



NSolve[(5.5 - \[Rho]l) (-0.5 + \[Rho]l) ==
  0.833333 (3 - \[Rho]l) (0.5 + \[Rho]l) (-Log[3 - \[Rho]l] +
     Log[5. \[Rho]l]), \[Rho]l]


抱歉 帖子有点乱, 这个问题确实复杂,请有有兴趣的高手贴到mathematica上看看
发表于 2011-4-17 00:28:24 | 显示全部楼层 来自 黑龙江哈尔滨
Simdroid开发平台
1# zsmiup

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2011-4-17 12:41:07 | 显示全部楼层 来自 美国
本帖最后由 zsmiup 于 2011-4-17 23:36 编辑

wow 谢谢 高手

不过,我将您的代码 打进去了 却得到不同的结果

如下
  1. ff[T_] := Module[{sol},
复制代码
sol = FindRoot[{(3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) == T,
       (\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l) ==
      1/3*T*Log[(\[Rho]l (3 - \[Rho]g))/(\[Rho]g (3 - \[Rho]l))]}, {{\
\[Rho]l, Random[]}, {\[Rho]g, Random[]}}, MaxIterations -> 100]]
Table[ff[x], {x, 0, 1, 0.1}][/code][/code]


During evaluation of In[35]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances. >>

During evaluation of In[35]:= FindRoot::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >>

During evaluation of In[35]:= FindRoot::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >>

During evaluation of In[35]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances. >>

During evaluation of In[35]:= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances. >>

During evaluation of In[35]:= General::stop: Further output of FindRoot::lstol will be suppressed during this calculation. >>

During evaluation of In[35]:= FindRoot::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >>

During evaluation of In[35]:= General::stop: Further output of FindRoot::cvmit will be suppressed during this calculation. >>

Out[36]= {{\[Rho]l -> 0.285354, \[Rho]g -> -0.285354}, {\[Rho]l ->
   0.00681528 + 2.04605*10^-15 I, \[Rho]g -> -0.00715281 -
    1.79037*10^-15 I}, {\[Rho]l -> -2.5948*10^-8 +
    1.20629*10^-8 I, \[Rho]g -> -2.59477*10^-8 +
    1.20634*10^-8 I}, {\[Rho]l -> -9.05927*10^-9, \[Rho]g -> \
-9.05932*10^-9}, {\[Rho]l ->
   0.0187468 - 0.0257193 I, \[Rho]g -> -0.0109141 +
    0.0154141 I}, {\[Rho]l ->
   0.0317468 - 0.000638149 I, \[Rho]g -> -0.0165133 +
    0.000337336 I}, {\[Rho]l -> -7.67425*10^-8 +
    1.23146*10^-10 I, \[Rho]g -> -7.67422*10^-8 +
    1.24441*10^-10 I}, {\[Rho]l -> -1.18052*10^-8, \[Rho]g -> \
-1.18052*10^-8}, {\[Rho]l -> -4.96428*10^-7, \[Rho]g -> \
-4.96425*10^-7}, {\[Rho]l -> -3.93091*10^-8, \[Rho]g -> \
-3.93093*10^-8}, {\[Rho]l ->
   0.11282 + 2.14641*10^-15 I, \[Rho]g -> -0.0525342 -
    4.15596*10^-16 I}}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复 不支持

使用道具 举报

发表于 2011-4-17 21:53:48 | 显示全部楼层 来自 台湾

  1. ff[T_] :=
  2.   Module[{sol},
  3.    sol = FindRoot[{(3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) ==
  4.        T (\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l), (3 - \[Rho]g) \
  5. (3 - \[Rho]l) (\[Rho]g + \[Rho]l) ==
  6.        1/3*T*Log[(\[Rho]l (3 - \[Rho]g))/(\[Rho]g (3 - \[Rho]l))]}, \
  7. {{\[Rho]l, 1/10, 9/10}, {\[Rho]g, 1/10, 9/10}}, MaxIterations -> 100]];

  8. ff[#] & /@ Range[0, 1, 1/10]

  9. TableForm[{N@#, \[Rho]l, \[Rho]g} /. ff[#] & /@ Range[0, 1, 1/10],
  10. TableHeadings -> {T, \[Rho]l, \[Rho]g}]
复制代码

评分

1

查看全部评分

回复 不支持

使用道具 举报

 楼主| 发表于 2011-4-17 23:53:25 | 显示全部楼层 来自 美国
TBE 您好:

运行您的code 得到了 和您的结果相似的解(有可以忽略的tiny difference), 但是当我给 这个方程组,加上系数,(1/8 和 8/3) 的时候
mathematica 说,100 次得iterations ,也找不到 一个比较好的解,这是说, mathematica不适合解这个方程,还是说这个方程组,本身有点问题。
谢谢
FindRoot::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >>

加上系数的代码
  1. Clear["Globe'*"]
  2. ff[T_] :=
  3. Module[{sol},
  4.   sol = FindRoot[{1/
  5.        8 (3 - \[Rho]g) (3 - \[Rho]l) (\[Rho]g + \[Rho]l) == T,
  6.      (\[Rho]l - \[Rho]g) (6 - \[Rho]g - \[Rho]l) ==
  7.       8/3 T*Log[(\[Rho]l (3 - \[Rho]g))/(\[Rho]g (3 - \[Rho]l))]}, {{\
  8. \[Rho]l, Random[]}, {\[Rho]g, Random[]}}]]
  9. Table[ff[x], {x, 0.01, 1.1, 0.1}]
复制代码
回复 不支持

使用道具 举报

 楼主| 发表于 2011-4-18 06:25:50 | 显示全部楼层 来自 美国
谢谢 chungyuandye 的解答

不知道可不可帮我解释下 & 在这儿 是什么意思? and吗 ?
ff[#] & /@ Range[0, 1, 1/10]

我还问您下 有没有 mathmatica符号的小手册
比如 /. ; := ; /@ ,这样的mathematica火星文 注解
回复 不支持

使用道具 举报

发表于 2011-4-18 12:28:32 | 显示全部楼层 来自 北京
&是引用的意思,代表第几个变量

入门的话看一下《introduction to programming in mathematica》
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-28 00:37 , Processed in 0.049518 second(s), 19 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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