I have the code below. when I try to run it, I get an error messages says: "C:\Users\hanab\OneDrive\Desktop\Numerical simulation\HW#5\numer.py:33: RuntimeWarning: overflow encountered in long_scalars X[i,j] = (k0/(mu0157.9778831)) * (220*kxdy[i,j]*kxdy[i+1,j])/(kxdy[i,j]*dx_2[i+1,j]+kxdy[i+1,j]*dx_2[i,j]):
it is clear that the error in ligne 33. but how can I fix it.
import numpy as np
import matplotlib.pyplot as plt
kx = np.array([50, 100, 200, 100, 150, 250, 150, 200, 300])
ky = 0.5 * np.copy(kx)
kz = 0.1 * np.copy(kx)
phi = np.array([0.15, 0.18, 0.20, 0.17, 0.20, 0.22, 0.22, 0.25, 0.26])
n=9
m=9
dt = 5
dx = np.array([750, 1000, 1250])
dy = np.array([750, 1000, 1250])
dz = np.ones(dx.shape)
xx, yy, zz = np.meshgrid(dx, dy, dz)
k0 = 1.0
mu0 = 5
kx = np.reshape(kx, (dx.shape[0], dx.shape[0])).T
ky = np.reshape(ky, (dy.shape[0], dy.shape[0]))
kydx = (ky*dx).T
kxdy = (kx*dy)
dy_2 = np.array([[750, 1000, 1250],[750, 1000, 1250],[750, 1000, 1250]])
dx_2 = np.array([[750, 750, 750],[1000, 1000, 1000],[1250, 1250, 1250]])
X = np.zeros((dx.shape[0], dx.shape[0]))
Y = np.zeros((dy.shape[0], dy.shape[0]))
for i in range(len(dx_2)-1):
for j in range(len(dx_2)):
X[i,j] = (k0/(mu0*157.9778831)) * (2*20*kxdy[i,j]*kxdy[i+1,j])/(kxdy[i,j]*dx_2[i+1,j]+kxdy[i+1,j]*dx_2[i,j])
for i in range(len(dx_2)):
for j in range(len(dx_2)-1):
Y[i,j] = (k0/(mu0*157.9778831)) * (2*20*kydx[i,j]*kydx[i,j+1])/(kydx[i,j]*dy_2[i,j+1]+kydx[i,j+1]*dy_2[i,j])
X = X.T.flatten()
Y = Y.T.flatten()
T = np.zeros((X.shape[0], Y.shape[0]))
J = np.zeros(T.shape)
for i in range(3,9):
T[i, i-3] = -Y[i-3]
for i in range(1,9):
T[i, i-1] = -X[i-1]
T = T + T.T
diags = -T.sum(axis=0)
for i in range(T.shape[0]):
T[i,i] = diags[i]