ValueError: math domain error

前端 未结 4 1860
萌比男神i
萌比男神i 2020-12-01 02:35

I was just testing an example from Numerical Methods in Engineering with Python.

from numpy import zeros, array
from math import sin, log
from newto         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-01 02:49

    You are trying to do a logarithm of something that is not positive.

    Logarithms figure out the base after being given a number and the power it was raised to. log(0) means that something raised to the power of 2 is 0. An exponent can never result in 0*, which means that log(0) has no answer, thus throwing the math domain error

    *Note: 0^0 can result in 0, but can also result in 1 at the same time. This problem is heavily argued over.

提交回复
热议问题