gpt4 book ai didi

wolfram-mathematica - 使用 Manipulate 的悬链线

转载 作者:行者123 更新时间:2023-12-04 18:20:00 24 4
gpt4 key购买 nike

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

最佳答案

我会这样做:

首先,定义悬链线:

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

现在我可以找到参数 a , cy这条曲线的数值,使用 FindRoot :
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

关于wolfram-mathematica - 使用 Manipulate 的悬链线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10872464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com