Reputation: 129
So I wish to create a log(y) vs log(x) of the following function in python. I am not sure how the range (w) should be composed to get a good graph. For now I have left it blank.
import numpy as np
import matplotlib.pyplot as plt
w =
y = 1/(1+2.56e-8*(w)^2)
plt.plot(log(w),log(y));
Okay so now I have to do one more plot but its a little bit more complicated.
w = np.arange(1e3, 1e7, 1e3)
z = 1/ (((5.89824e-15 (w ** 4))+(1-2.56e-8 (w ** 2))) ** 0.5)
b = plt.loglog(w, z);
This give me an error:
z = 1/ (((5.89824e-15 (w ** 4))+(1-2.56e-8 (w ** 2))) ** 0.5)
TypeError: 'float' object is not callable
Never mind I fixed it.
Upvotes: 1
Views: 653
Reputation: 78610
You can use the numpy.arange
function to get a numpy version of range. A reasonable range for this function is:
w = np.arange(1e3, 1e7, 1e3)
(That is, going from 1000 to 10000000 in steps of 1000). However, note that in order to make Python know you're trying to use exponentiation rather than the bitwise xor operator, you should change your line to:
y = 1/(1+2.56e-8*(w ** 2))
Then, if you make a log-log plot, you end up with:
plt.loglog(w, y)
Upvotes: 2