The shape of a hanging wire is a classial problem in Euler-Lagrange equations, but here the shape is found from minimizing the potential starting from an initial estimate. To solve for the shape we can look at the problem in view of a constrained optimization problem. The Lagrangian is given below in continous form.
The continous form is discretized. The average height from two neighboring points is used to give a symmetric Lagrangian, which leads to a better solution. It also leads to more complicated terms in the Jacobian and Hessian.
The Jacobian of the Lagrangian is given by
The Hessian of the Lagrangian is given by
The constraints are the boundary fixed position of the wire, and the total wire length l.
The optimization algorithm can converge faster if given the analytical expressions for Jacobian and Hessian of the nonlinear constraint. The Jacobian is given by
The Hessian of the constraint is given by
The solution is given below
The initial guessed path is a based on a sine curve, which doesn't optimize the potential function. The iterated solution is closer to the true shape of a hanging wire. A parabola is a better approximation to the solution, which is a catenary. We can try with a parabola initial condition. The solution is seen below