1
I am making a program that makes numerical calculations, but constantly appear to me operations where there is division by 0 (zero)
. I ended up finding a solution using if
, but still wanted to know why the try
can’t handle that exception
def substituicoesRetroativas(A,b):
n = len(b)
x = zeros(n)
for i in range(n-1,-1,-1):
soma = 0
for j in range(i+1,n):
soma += A[i,j] * x[j]
try:
x[i] = float(b[i] - soma)/A[i,i]
except:
print "Matriz Impossivel"
break
return np.matrix(x).transpose()
When executing I get the following error message
Eliminacao de Gauss :
/home/ubuntu/workspace/PASSINI/Trab 2/sS.py:23: RuntimeWarning: divide by zero encountered in double_scalars
x[i] = float(b[i] - soma)/A[i,i]
/home/ubuntu/workspace/PASSINI/Trab 2/sS.py:20: RuntimeWarning: invalid value encountered in double_scalars
soma += A[i,j] * x[j]
[[ nan]
[-inf]
[ inf]]
you would have an example of parameters for the function?
– Jeanderson Candido
you are using some library in this code?
– Jeanderson Candido
@Jeandersonbarroscândido I am using the numpy.
– Victor Henrique