logarithm

ValueError: math domain error

Why does math.log result in ValueError: math domain error? Question: I was just testing an example from Numerical Methods in Engineering with Python. from numpy import zeros, array from math import sin, log from newtonRaphson2 import * def f(x): f = zeros(len(x)) f[0] = sin(x[0]) + x[1]**2 + log(x[2]) – 7.0 f[1] = 3.0*x[0] + …

Total answers: 5

how to check if a number is a power of base b?

how to check if a number is a power of base b? Question: In python, how can you check if a number n is an exact power of base b? Note: it needs to be generalized to any base which is given as a parameter. Here is what I got: Assume n and base are …

Total answers: 5

How do you do natural logs (e.g. "ln()") with numpy in Python?

How do you do natural logs (e.g. "ln()") with numpy in Python? Question: Using numpy, how can I do the following: ln(x) Is it equivalent to: np.log(x) I apologise for such a seemingly trivial question, but my understanding of the difference between log and ln is that ln is logspace e? Asked By: user1220022 || …

Total answers: 6

Log to the base 2 in python

Log to the base 2 in python Question: How should I compute log to the base two in python. Eg. I have this equation where I am using log base 2 import math e = -(t/T)* math.log((t/T)[, 2]) Asked By: Soumya || Source Answers: >>> def log2( x ): … return math.log( x ) / …

Total answers: 10

What is the difference between 'log' and 'symlog'?

What is the difference between 'log' and 'symlog'? Question: In matplotlib, I can set the axis scaling using either pyplot.xscale() or Axes.set_xscale(). Both functions accept three different scales: ‘linear’ | ‘log’ | ‘symlog’. What is the difference between ‘log’ and ‘symlog’? In a simple test I did, they both looked exactly the same. I know …

Total answers: 3