Runtimewarning error

Asked

Viewed 73 times

0

I am trying to run an array and the following error appears: Runtimewarning: invalid value encountered in double_scalars. What may cause it?

def geomBarras(nx, ny, nz, fx, fy, fz): #determina tamanho das barras e cossenos diretores
    _L = np.sqrt( (fx-nx) ** 2 + (fy-ny) ** 2 + (fz - nz) ** 2 )
    _lbx = (fx-nx)/_L
    _lby = (fy-ny)/_L
    _lbz = (fz-nz)/_L
    return [ _L, _lbx, _lby, _lbz] 

def matRot(Cx,Cy, Cz):  #cria uma matriz de rotação
    rot = np.matrix([
            [                                   Cx,                      Cy,                                   Cz,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.],
            [ (-Cx*Cy - Cz)/(Cx**2 + Cz**2) ** 0.5,  (Cx**2 + Cz**2) ** 0.5, (-Cy*Cz + Cx)/(Cx**2 + Cz**2) ** 0.5,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.],
            [  (Cx*Cy - Cz)/(Cx**2 + Cz**2) ** 0.5, -(Cx**2 + Cz**2) ** 0.5,  (Cy*Cz + Cx)/(Cx**2 + Cz**2) ** 0.5,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.],
            [                                   0.,                      0.,                                   0.,                                   Cx,                      Cy,                                   Cz,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.],
            [                                   0.,                      0.,                                   0., (-Cx*Cy - Cz)/np.sqrt(Cx**2 + Cz**2),  np.sqrt(Cx**2 + Cz**2), (-Cy*Cz + Cx)/np.sqrt(Cx**2 + Cz**2),                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.],
            [                                   0.,                      0.,                                   0.,  (Cx*Cy - Cz)/np.sqrt(Cx**2 + Cz**2), -np.sqrt(Cx**2 + Cz**2),  (Cy*Cz + Cx)/np.sqrt(Cx**2 + Cz**2),                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.],
            [                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   Cx,                      Cy,                                   Cz,                                   0.,                      0.,                                   0.],
            [                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0., (-Cx*Cy - Cz)/np.sqrt(Cx**2 + Cz**2),  np.sqrt(Cx**2 + Cz**2), (-Cy*Cz + Cx)/np.sqrt(Cx**2 + Cz**2),                                   0.,                      0.,                                   0.],
            [                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,  (Cx*Cy - Cz)/np.sqrt(Cx**2 + Cz**2), -np.sqrt(Cx**2 + Cz**2),  (Cy*Cz + Cx)/np.sqrt(Cx**2 + Cz**2),                                   0.,                      0.,                                   0.],
            [                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   Cx,                      Cy,                                   Cz],
            [                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0., (-Cx*Cy - Cz)/np.sqrt(Cx**2 + Cz**2),  np.sqrt(Cx**2 + Cz**2), (-Cy*Cz + Cx)/np.sqrt(Cx**2 + Cz**2)],
            [                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,                                   0.,                      0.,                                   0.,  (Cx*Cy - Cz)/np.sqrt(Cx**2 + Cz**2), -np.sqrt(Cx**2 + Cz**2),  (Cy*Cz + Cx)/np.sqrt(Cx**2 + Cz**2)]
            ])
    return rot

 nos    = [ [ 0., 0., 0.], [ 0., 4., 0.], [ 4., 4., 0.], [ 4., 0., 0.], [ 0., 0., 4.], [ 0., 4., 4.], [ 4., 4., 4.], [ 4., 0., 4.] ]

 barras = [ [  0, 1 ], [ 1 , 2 ], [  2, 3 ], [ 2, 6 ], [ 1, 5 ], [ 4, 5 ], [ 5, 6 ], [ 6, 7 ] ]

 for b in barras:

     [L, lbx, lby, lbz] = geomBarras( nos[b[0]][0], nos[b[0]][1], nos[b[0]][2], nos[b[1]][0], nos[b[1]][1], nos[b[1]][2] )

     T = matRot(lbx, lby, lbz)
  • 1

    Invalid values found in variable double_scalars. So I can say more, only with code.

  • I added the code

  • 2

    I found the mistake! There are combinations in which Cz and Cy will give zero, occasioning in a division by zero. Thank you so much for the help!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.