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

[编程进阶] 请教Mathematica问题!

[复制链接]
发表于 2008-11-9 18:41:33 | 显示全部楼层 |阅读模式 来自 德国
下面两段程序,感觉应该是同样的结果,但是却不同。请高手指点!
第一段程序:
\!\(\*
  RowBox[{\(c\_11 = \((2.1`30)\)*10^11; c\_13 = \((1.05`30)\)*10^11;
          c\_33 = \((2.11`30)\)*10^11; c\_44 = \((0.423`30)\)*10^11;\),
        "\[IndentingNewLine]", \(e\_15 = \(-0.48`30\); e\_31 = \(-0.573`30\); \
e\_33 = 1.321`30;\), "\[IndentingNewLine]", \(pϵ\_11 = 8.55`30;
    pϵ\_33 = 10.2`30;\), "\[IndentingNewLine]", \(pρ =
    5670`30;\), "\[IndentingNewLine]",
    RowBox[{\(FPiezo[GC_]\), ":=",
      RowBox[{"Module", "[",
        RowBox[{\({Tp, K, DK, a1, a2, a3, a4, b, de, V}\), ",",
          RowBox[{\(V = GC\), ";", "\[IndentingNewLine]",
            RowBox[{"K", "=",
              RowBox[{"(", GridBox[{
                    {\(c\_11 + c\_44*b\^2 - pρ*
    V\^2\), \(\((c\_13 + c\_44)\)*b\), \(\((e\_15 + e\_31)\)*b\)},
                    {\(\((c\_13 + c\_44)\)*b\), \(c\_44 + c\_33*b\^2 - pρ*
      V\^2\), \(e\_15 + e\_33*b\^2\)},
                    {\(\((e\_15 + e\_31)\)*
        b\), \(e\_15 + e\_33*b\^2\), \(-\((pϵ\_11 + pϵ\_33*b\^2)\)\)}
                    }], ")"}]}],
      ";", "\[IndentingNewLine]", \(DK = Det[K]\), ";",
             "\[IndentingNewLine]", \(a1 = Coefficient[DK, b,
6]\), ";", \(a2 = Coefficient[DK, b, 4]\), ";", \(a3 = Coefficient[DK,
             b, 2]\),
            ";", \(a4 = Coefficient[DK, b, 0]\),
                ";", "\[IndentingNewLine]", \(Tp =
            Solve[a1\ x^6 +
              a2\ x^4 + a3\ x^2 + a4 == 0, x]\), ";
                ", "\[IndentingNewLine]", \(pdecay =
              Array[de, {1, 6}]\), ";
                ", "\[IndentingNewLine]", \(Do[pdecay[\([1, m]\)] = Tp[\([m, \
1, 2]\)], {m, 6}]\),
            ";", "\[IndentingNewLine]",
                 "pdecay"}]}], "]"}]}], "\[IndentingNewLine]", \(F1[GC_] :=
                    Module[{}, temp = FPiezo[GC];
            Im[temp[\([1, 1]\)]]]\), "\[IndentingNewLine]", \(Plot[
            F1[x], {x, 0, 2000}]\)}]\)
第二段程序:
\!\(\*
  RowBox[{\(c\_11 = \((2.1`30)\)*10^11; c\_13 = \((1.05`30)\)*10^11;
          c\_33 = \((2.11`30)\)*10^11; c\_44 = \((0.423`30)\)*10^11;\),
        "\[IndentingNewLine]", \(e\_15 = \(-0.48`30\); e\_31 = \(-0.573`30\); \
e\_33 = 1.321`30;\), "\[IndentingNewLine]", \(pϵ\_11 = 8.55`30;
    pϵ\_33 = 10.2`30;\), "\[IndentingNewLine]", \(pρ =
    5670`30;\), "\[IndentingNewLine]",
    RowBox[{\(FPiezo[GC_]\), ":=",
      RowBox[{"Module", "[",
        RowBox[{\({Tp, K, DK, a1, a2, a3, a4, b, de, V}\), ",",
         
    RowBox[{\(V = GC\), ";", "\[IndentingNewLine]", \(Teq =
       Solve[a1\ x^6 + a2\ x^4 +
    a3\ x^2 + a4 == 0, x]\), ";", "\[IndentingNewLine]",
            RowBox[{"K", "=",
              RowBox[{"(", GridBox[{
                    {\(c\_11 +
    c\_44*b\^2 - pρ*V\^2\), \(\((c\_13 + c\_44)\)*b\), \(\((e\_15 + e\_31)\)*
      b\)},
                    {\(\((c\_13 + c\_44)\)*b\), \(c\_44 + c\_33*
        b\^2 - pρ*V\^2\), \(e\_15 + e\_33*b\^2\)},
                    {\(\((e\_15 +
       e\_31)\)*b\), \(e\_15 + e\_33*b\^2\), \(-\((pϵ\_11 + pϵ\_33*b\^2)\)\)}
                    }], ")"}]}], ";", "\[IndentingNewLine]", \(DK = Det[K]\),
            ";", "\[IndentingNewLine]", \(Tp = Teq //. {a1 -> Coefficient[DK,
              b, 6], a2 -> Coefficient[DK, b, 4],
             a3 -> Coefficient[DK, b, 2], a4 -> Coefficient[DK, b,
              0]}\), ";",
                "\[IndentingNewLine]", \(pdecay = Array[de, {1, 6}]\), ";",
                      "\[IndentingNewLine]", \(Do[pdecay[\([1, m]\)] = \
Tp[\([m, 1, 2]\)], {m, 6}]\),
                    ";", "\[IndentingNewLine]", "pdecay"}]}], "]"}]}],
                    "\[IndentingNewLine]", \(F1[GC_] := Module[{}, temp =
              FPiezo[GC]; Im[
            temp[\([1, 1]\)]]]\), "\[IndentingNewLine]", \(Plot[F1[x], {x,
              0, 2000}]\)}]\)
这两段程序的区别是,第一段程序直接求解了一个系数已经确定了的一员六次方程,儿第二段程序是先求解了一个系数待定的一员六次方程再将系数值代入。
发表于 2008-11-10 15:21:38 | 显示全部楼层 来自 江苏无锡
Simdroid开发平台
Your question is unclear.
Your code is uncomplete.
回复 不支持

使用道具 举报

 楼主| 发表于 2008-11-10 16:07:43 | 显示全部楼层 来自 德国
你可以直接将代码copy到Mathematica编辑器里,是可以执行的。我刚试过!
回复 不支持

使用道具 举报

发表于 2008-11-11 01:52:22 | 显示全部楼层 来自 美国
The comments are correct.  

Your question is not clear because you did not explain what you had planned to do and how you did it and what you obtained.  Your code is not complete because you do not have any comments (注释) at all.  It will be hard for others to guess what you plan to do.

You just cannot boldly state that it does not work and tell me how to get it work.  

你的问题其实很简单就是把一些参数放到一个矩阵当中,然后求出是矩阵的行列式(Det)等于0时的最小的根的虚部。 然后把根对你的参数V画图。
竟然最小的根,就要把根求出来,然后排序。你第一个程序只是用了Mathematica的default (sort),所以没太大的问题。 第二个你是先用解一些含有参数的方程,得到有参数的解,这个时候Mathematica是不会排序,因为排序会根据你的参数变化而变化,所以第二个程序得到的结果和第二个不一样,这个比较正常。

我把简化后的程序放在这儿:
  1. Subscript[c, 11] = 2.1*10^11; Subscript[c, 13] =
  2. 1.05*10^11; Subscript[c, 33] = 2.11*10^11; Subscript[c, 44] =
  3. 0.423*10^11;
  4. Subscript[e, 15] = -0.48; Subscript[e, 31] = -0.573; Subscript[e, 33] \
  5. = 1.321;
  6. Subscript[p\[Epsilon], 11] = 8.55; Subscript[p\[Epsilon], 33] = 10.2;
  7. p\[Rho] = 5670;
  8. K = {{-p\[Rho] V^2 + Subscript[c, 11] + b^2 Subscript[c, 44],
  9.     b (Subscript[c, 13] + Subscript[c, 44]),
  10.     b (Subscript[e, 15] + Subscript[e, 31])}, {b (Subscript[c, 13] +
  11.        Subscript[c, 44]), -p\[Rho] V^2 + b^2 Subscript[c, 33] +
  12.      Subscript[c, 44],
  13.     Subscript[e, 15] +
  14.      b^2 Subscript[e, 33]}, {b (Subscript[e, 15] + Subscript[e, 31]),
  15.     Subscript[e, 15] +
  16.      b^2 Subscript[e, 33], -Subscript[p\[Epsilon], 11] -
  17.      b^2 Subscript[p\[Epsilon], 33]}};
  18. F1[x_] := Sort[Solve[Det[K] == 0 //. V -> x, b]][[1, 1, 2]] // Im
  19. Plot[F1[x], {x, 0, 2000}]
复制代码
回复 不支持

使用道具 举报

发表于 2008-11-16 11:06:15 | 显示全部楼层 来自 北京邮电大学
赞smarten,Mathematica的确用的很牛,而且版主做得尽职尽责
佩服兼感谢一个
回复 不支持

使用道具 举报

 楼主| 发表于 2008-11-18 16:45:50 | 显示全部楼层 来自 德国
Thanks for Smarten's explain.
非常感谢smaten耐心的讲解,受益匪浅!
回复 不支持

使用道具 举报

发表于 2008-11-18 16:51:54 | 显示全部楼层 来自 湖南长沙
请问:我的mathematic现在怎么不能用了?总是出现:“The requested evaluator is not currently defined”.这个提示。重装后也不能解决。
回复 不支持

使用道具 举报

发表于 2008-11-19 00:10:33 | 显示全部楼层 来自 美国
回复 不支持

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-5 10:24 , Processed in 0.050216 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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