Home > Enterprise >  Using hyperbolic function in python
Using hyperbolic function in python

Time:10-06

I was trying to solve an equation for the catenary and wanted to use the Newton-Raphson method.

enter image description here

from math import sinh, cosh
y = 0.4                #Has taken to initiate the iteration.
k = 3/2
for _ in range(5):    #Iterations for Newton-Raphson Method
    y = y - (sinh(y)-y*k)/(cosh(y)-k)
    print(y)
print(y)
  • Output
-0.05174312094834577
9.262910138898434e-05
-5.298477449974456e-13
0.0
0.0
0.0

The unexpected output I was expecting 1/0.6164729394

CodePudding user response:

Your curve has 3 roots:

curve of sinh(y) - ky

Your solution (y = 0) is one solution. There is a positive solution at 1.622, and a symmetrical negative one at -1.622.

If you don't know your formula, best is to actually view it (when possible; here it is easy to do), to gain some insight.

Further, Newton-Raphson's result, the root, will depend on your starting point, and how it converges towards a root (with big jumps or small jumps, depending on function and derivative value). Be aware of that.


Related: https://math.stackexchange.com/questions/3472880/solving-sinh-x-kx

  • Related