Model a Hanging Chain
Find the position with minimal potential energy of a chain or cable of length suspended between two points.
![](assets.en/model-a-hanging-chain/O_41.png)
Set parameter values for the length of the chain , the left-end height
, and the right-end height
.
![Click for copyable input](assets.en/model-a-hanging-chain/In_73.png)
L = 4; a = 1; b = 3;
Let be the height of the chain as a function of horizontal position, with
.
![Click for copyable input](assets.en/model-a-hanging-chain/In_74.png)
xf = 1; nh = 201; h := xf/nh;
Set up variables for the height of the chain .
![Click for copyable input](assets.en/model-a-hanging-chain/In_75.png)
varsy = Array[y, nh + 1, {0, nh}];
Denote the slope at position by
and set up variables for it.
![Click for copyable input](assets.en/model-a-hanging-chain/In_76.png)
varsm = Array[m, nh + 1, {0, nh}];
Denote the partial potential energy from to
by
.
![Click for copyable input](assets.en/model-a-hanging-chain/In_77.png)
varsv = Array[v, nh + 1, {0, nh}];
Denote the length of the chain at position by
and set up variables for it.
![Click for copyable input](assets.en/model-a-hanging-chain/In_78.png)
varss = Array[s, nh + 1, {0, nh}];
Join all variables.
![Click for copyable input](assets.en/model-a-hanging-chain/In_79.png)
vars = Join[varsm, varsy, varsv, varss];
The objective is to minimize the total potential energy .
![Click for copyable input](assets.en/model-a-hanging-chain/In_80.png)
objfn = v[nh];
Here are the boundary value constraints from the geometry.
![Click for copyable input](assets.en/model-a-hanging-chain/In_81.png)
bndcons = {y[0] == a, y[nh] == b, v[0] == 0, s[0] == 0, s[nh] == L};
Discretize the ODEs: ,
,
.
![Click for copyable input](assets.en/model-a-hanging-chain/In_82.png)
odecons = {Table[
y[j + 1] == y[j] + 0.5*h*(m[j] + m[j + 1]), {j, 0, nh - 1}],
Table[v[j + 1] ==
v[j] + 0.5*
h*(y[j]*Sqrt[1 + m[j]^2] + y[j + 1]*Sqrt[1 + m[j + 1]^2]), {j,
0, nh - 1}],
Table[s[j + 1] ==
s[j] + 0.5*h*(Sqrt[1 + m[j]^2] + Sqrt[1 + m[j + 1]^2]), {j, 0,
nh - 1}]};
Choose initial points for the variables.
![Click for copyable input](assets.en/model-a-hanging-chain/In_83.png)
tmin = If[b > a, 0.25 , 0.75]; init =
Join[Table[4*Abs[b - a]*((k/nh) - tmin), {k, 0, nh}],
Table[4*Abs[b - a]*(k/nh)*(0.5*(k/nh) - tmin) + a, {k, 0, nh}],
Table[(4*Abs[b - a]*(k/nh)*(0.5*(k/nh) - tmin) + a)*4*
Abs[b - a]*((k/nh) - tmin), {k, 0, nh}],
Table[4*Abs[b - a]*((k/nh) - tmin), {k, 0, nh}]];
Minimize the total potential energy, subject to the constraints.
![Click for copyable input](assets.en/model-a-hanging-chain/In_84.png)
sol = FindMinimum[{objfn, Join[bndcons, odecons]},
Thread[{vars, init}]];
Extract the solution points.
![Click for copyable input](assets.en/model-a-hanging-chain/In_85.png)
solpts = Table[{i h, y[i] /. sol[[2]]}, {i, 0, nh}];
Plot the position of the chain with minimal potential energy.
![Click for copyable input](assets.en/model-a-hanging-chain/In_86.png)
ListPlot[solpts, ImageSize -> Medium, PlotTheme -> "Marketing"]
![](assets.en/model-a-hanging-chain/O_42.png)
Use FindFit to fit the result to the catenary curve.
![Click for copyable input](assets.en/model-a-hanging-chain/In_87.png)
catenary[t_] = c1 + (1/c2) Cosh[c2 (t - c3)];
![Click for copyable input](assets.en/model-a-hanging-chain/In_88.png)
fitsol = FindFit[solpts, catenary[t], {c1, c2, c3}, {t}]
![](assets.en/model-a-hanging-chain/O_43.png)
Plot the solution points together with the catenary curve.
![Click for copyable input](assets.en/model-a-hanging-chain/In_89.png)
Show[Plot[catenary[t] /. fitsol, {t, 0, 1},
PlotStyle -> Directive[Green, Thickness[0.01]],
ImageSize -> Medium],
ListPlot[Take[solpts, 1 ;; nh ;; 5], PlotStyle -> PointSize[.02]]]
![](assets.en/model-a-hanging-chain/O_44.png)