2

我想在 Mathematica 中表示悬链线曲线,然后允许用户操作每个参数,例如悬挂点的位置 (A,B)、电缆的重量、重力等?

4

1 回答 1

4

我会这样做:

首先,定义悬链线:

catenary[x_] := a*Cosh[(x - c)/a] + y

现在我可以找到参数a和这条曲线的数值,c使用:yFindRoot

Manipulate[
 Module[{root},
  (
   root = FindRoot[
             {
                catenary[x1] == y1, 
                catenary[x2] == y2
             } /. {x1 -> pt[[1, 1]], y1 -> pt[[1, 2]], x2 -> pt[[2, 1]], y2 -> pt[[2, 2]], a -> \[Alpha]}, 
             {{y, 0}, {c, 0}}];
   Show[
    Plot[catenary[x] /. root /. a -> \[Alpha], {x, -2, 2}, 
     PlotRange -> {-3, 3}, AspectRatio -> 3/2],
    Graphics[{Red, Point[pt]}]]
   )], {{\[Alpha], 1}, 0.001, 10}, {{pt, {{-1, 1}, {1, 1}}}, Locator}]

或者,您可以准确求解参数:

solution = Simplify[Solve[{catenary[x1] == y1, catenary[x2] == y2}, {y, c}]]

然后在 Manipulate 中使用这个解决方案:

Manipulate[
 (
  s = (solution /. {x1 -> pt[[1, 1]], y1 -> pt[[1, 2]], 
      x2 -> pt[[2, 1]], y2 -> pt[[2, 2]], a -> \[Alpha]});
  s = Select[s, 
    Im[c /. #] == 0 && 
      Abs[pt[[1, 2]] - catenary[pt[[1, 1]]] /. # /. a -> \[Alpha]] < 
       10^-3 &];
  Show[
   Plot[catenary[x] /. s /. a -> \[Alpha], {x, -2, 2}, 
    PlotRange -> {-3, 3}, AspectRatio -> 3/2],
   Graphics[{Red, Point[pt]}]]
  ), {{\[Alpha], 1}, 0.001, 10}, {{pt, {{-1., 1.}, {1., 0.5}}}, 
  Locator}]

不过,该FindRoot版本更快、更稳定。结果如下所示:

在此处输入图像描述

为了完整起见:也可以通过 3 点找到悬链线:

m = Manipulate[
  Module[{root},
   (
    root = 
     FindRoot[
      catenary[#[[1]]] == #[[2]] & /@ pt, {{y, 0}, {c, 0}, {a, 1}}];
    Show[
     Plot[catenary[x] /. root, {x, -2, 2}, PlotRange -> {-3, 3}, 
      AspectRatio -> 3/2],
     Graphics[{Red, Point[pt]}]]
    )], {{pt, {{-1, 1}, {1, 1}, {0, 0}}}, Locator}]

在此处输入图像描述

于 2012-06-03T19:08:55.333 回答