The graph produced uses the array named w as the x axis and the array named A1 as the y axis.I have to find and print the maximum point on the resulting graph. To do this I use the max() function to find the maximum value in the array named A1. To find the corresponding X value I am using the np.interp() function and swapping the x and y input axes so the value returned is effectively an x value for the graph produced (np.interp uses an x value to find a y, I am using a y value to find an x). However, no matter what value I give the np.interp function it always returns 4.99. I assume the issue must lie in the fact that in swapping the axes? But this is the only way to get the function to return an x value for a given y.
import numpy as np
import matplotlib.pyplot as plt
F = 10
m = 5
w0 = 1
w = np.array(np.arange(0.01, 5, 0.01))
b1 = 0.25*m*w0
G1 = np.array(np.sqrt((m**2)*(((w**2)-(w0**2))**2)+(b1**2)*(w**2)))
A1 = np.array(F/G1)
A1_Max = max(A1)
Here I am printing the value just to test if it is right. As you can see the x axis should be w and the y A1 in the np.interp function however as previously stated the axes are swapped:
w1_Max = np.interp(A1_Max, A1, w)
print(w1_Max)
plt.figure(figsize=(20, 20))
plt.plot(w, A1, '-', label='b=0.25*m*w0')
plt.xlabel('Frequency (rad/s)')
plt.ylabel('Amplitude (a.u.)')
plt.title('F = {0} m = {1}'.format(F,m))
plt.legend()