Hey there,
I’m fairly new to Julia and this forum (in fact my first post here).
About my problem:
I’m currently trying to solve a system of 3 nonlinear equations that emerged as the solution of the hanging chain problem (following this video).
My studies didn’t involve solving NL systems very much, so I naively defined the system following the MTK documentation. But when I try to solve it I’m only getting a vector of 3 NaNs as solution.
If someone could help and point out my error I would really appreciate it
In case my versions are relevant:
- Julia: 1.6.0
- ModelingToolkit: 5.14.0
- NonlinearSolve: 0.3.8
Here is my code:
using ModelingToolkit, NonlinearSolve
@variables x y c_1 c_2 λ
@parameters x_1 x_2 y_1 y_2 m g L_0
f(x, y) = c_1/(m*g) * cosh( m*g/c_1*( x + c_2 ) ) - λ/c_1 - y
n = c_1/(m*g) * ( sinh(m*g/c_1*x_2 + c_2) - sinh(m*g/c_1 * x_1 + c_2) ) - L_0
f_1 = f(x_1, y_1)
f_2 = f(x_2, y_2)
eqs = [
0 ~ f_1
0 ~ f_2
0 ~ n
]
ns = NonlinearSystem(eqs, [c_1, c_2, λ], [x_1, x_2, y_1, y_2, m, g, L_0])
guess = [
c_1 => 1.0
c_2 => 1.0
λ => 1.0
]
ps = [
x_1 => 0.0
x_2 => 500.0e3
y_1 => 0.0
y_2 => 0.0
m => 257.0 * 2.7
g => 9.81e3
L_0 => 600.0e3
]
prob = NonlinearProblem(ns, guess, ps)
sol = solve(prob, NewtonRaphson())
(Edit before posting this:)
After writing this post it came to my mind, that maybe the System is ill-conditioned with the given parameters. So I set all my current non-zero parameters to 1.0 (L_0 to 1.1 as its the length of the chain) and indeed I got a non-NaN result. Could someone more proficient in the numerics of nonlinear systems point me in the right direction in setting this up please?
Thanks for your time!