Mathematica嵌套操纵滞后

时间:2014-11-13 22:18:01

标签: wolfram-mathematica

确定!我正在努力构建一个嵌套的操纵命令,该命令将解决n个串联的阻尼振荡质量(具有固定端点)。我有一切工作,但我有一个问题 - 当我增加振荡器的数量时,我的初始条件落后了一点。例如,如果我将n设置为4,Mathematica说我仍然只有2个初始条件(起始数 - 一个振荡器的位置和速度)。当我移动到3时,我现在有8个(来自我的4个振荡器) - 这对于状态空间方程来说太多了,而且都失败了。发生了什么事?

(是的,我知道我的初始条件不会被正确放入,我只是想让它们先匹配)。

coupledSMD[n_, m_, k_, b_, f_, x0_, v0_, tmax_] :=
    Module[{aM, bM, cM, dM},
    aM = Join[Table[Boole[i == j - n], {i, n}, {j, 2 n}], 
      Join[
        If[n != 1,DiagonalMatrix[-2 k/m Table[1, {n}]] + 
          k/m DiagonalMatrix[Table[1, {n - 1}], 1] + 
          k/m DiagonalMatrix[Table[1, {n - 1}], -1],
          {{-2 k/m}}], 
        If[n != 1,DiagonalMatrix[-2 b/m Table[1, {n}]] + 
          b/m DiagonalMatrix[Table[1, {n - 1}], 1] + 
          b/m DiagonalMatrix[Table[1, {n - 1}], -1],
          {{-2 b/m}}], 2]];
    bM = Join[Table[0, {n}, {1}], Table[1/m, {n}, {1}]];
    cM = Table[Boole[i == j], {i, n}, {j, 2 n}];
    dM = Table[0, {n}, {1}];
    OutputResponse[ 
       {StateSpaceModel[{aM, bM, cM, dM}], Flatten[Join[x0, v0]]},
       f, {t, 0, tmax}]
]
Manipulate[
  With[{
    x0s = Table[Subscript[x, i, 0], {i, 1, n}],
    v0s = Table[Subscript[v, i, 0], {i, 1, n}],
    initialx = Sequence @@ Table[{{Subscript[x, i, 0], 0}, -10, 10}, {i, 1, n}],
    initialv = Sequence @@ Table[{{Subscript[v, i, 0], 0}, -10, 10}, {i, 1, n}]},
    Manipulate[
      myplot = coupledSMD[n, m, k, b, f, x0s, v0s, tmax];
      Plot[myplot, {t, 0, tmax}, PlotRange -> yheight {-1, 1}, 
        PlotLegends -> Table[Subscript[x, i, 0], {i, 1, n}]],
      Style["Initial Positions", Bold],
      initialx,
      Delimiter,
      Style["Initial Velocities", Bold],
      initialv,
      Delimiter,
      Style["System conditions", Bold],
      {{m, 1, "Mass(kg)"}, 0.1, 10, Appearance -> "Labeled"},
      {{k, 1, "Spring Constant(N/m)"}, 0.1, 10, Appearance -> "Labeled"},
      {{b, 0, "Damping Coefficient(N.s/m)"}, 0, 1, Appearance -> "Labeled"},
      {{f, 0, "Applied Force"}, 0, 10, Appearance -> "Labeled"},
      Delimiter,
      Style["Plot Ranges", Bold],
      {tmax, 10, 100},
      {{yheight, 10}, 1, 100},
      Delimiter,
      ControlPlacement -> Flatten[{Table[Right, {2 n + 2}], Table[Left, {8}]}]
    ]],
  {n, 1, 4, 1}
]

修改:更新了代码。它现在有效,但我仍然得到错误。我猜它与更新过程中的时滞有关? - 某些部分在其他部分之前得到更新。同样,它似乎工作得很好,除了它抛出这些错误(错误对我来说似乎是多余的,好像它们是代码中的残余,但实际上并没有引起问题)

但我真的不知道我在说什么:)

0 个答案:

没有答案