I'm running the following calculation:
N = 2**15
dx = 0.1
x = np.arange(-N/2,N/2)
u0 = np.zeros([N, 1])
L = N * dx
x0 = x[1] + 2 * delta
delta = 15
while x0 < L - delta:
l1 = 1.267;
x0 = x0 + delta
r = 1/(l1*np.cosh(x)**2)
u0 = r + u0
Essentially, while x0< L - delta this loop will run for 2^15 points.
This works fine translated into MATLAB but python gives me this error:
RuntimeWarning: overflow encountered in cosh
r = 1/(l1*np.cosh(x)**2)
coshgrows very large:Why is your
xso wide? For most of the range, the inverse of thiscoshwill be 0.Look at a +-20 range for
xsuppressing the warnings
The warning does not prevent you from getting useful values. It is a warning, not an error.
But can suppress the warning. On way is with
errstate:np.seterrcan also be used, but it will change handling for the whole script, not just this context. So thewith np.errstateis preferred.Do take time to read the docs.
There is also a
warningsmoduleWhy can't I suppress numpy warnings