与操纵的接触网

时间:2012-06-03 17:32:44

标签: wolfram-mathematica curve

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

1 个答案:

答案 0 :(得分:3)

我会这样做:

首先,定义接触网:

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

现在,我可以使用a以数字方式找到此曲线的参数cyFindRoot

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版本更快更稳定。结果如下所示:

enter image description here

为了完整起见:也可以通过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}]

enter image description here