Jul-28-2021, 10:58 AM
Hey,
I'm trying to plot energy as a function of My. I want to plot the function for values of n between 1-10, but the code returns an AttributeError. I tried putting the My value straight into the equation (without defining 'bragg' first), but that doesn't work either, the graphs are all flat.
I'm trying to plot energy as a function of My. I want to plot the function for values of n between 1-10, but the code returns an AttributeError. I tried putting the My value straight into the equation (without defining 'bragg' first), but that doesn't work either, the graphs are all flat.
import numpy as np import matplotlib.pyplot as plt h = 2 k = 2 l = 0 a = 5.431020511 * 0.0001 R = 250 * 1000 d = a / np.sqrt(h**2+k**2+l**2) hc = 1.23984198 My = range(0,100) def bragg(My): bragg = 2*np.pi + np.arccos(np.sqrt(My)/np.sqrt(R)) return bragg def energy(bragg, n): E = (2 * d * np.sin(bragg) / (n*hc)) return E fig = plt.figure() fig.suptitle('Energy') plt.plot(My, energy(bragg,1), label='1st') plt.plot(My, energy(bragg,2), label='2nd') plt.plot(My, energy(bragg,3), label='3rd') plt.plot(My, energy(bragg,4), label='4th') plt.plot(My, energy(bragg,5), label='5th') plt.plot(My, energy(bragg,6), label='6th') plt.xlabel('My') plt.ylabel('Energy (eV)') plt.legend()The error given is this:
E = (2 * d * np.sin(bragg) / (n*hc)) AttributeError: 'function' object has no attribute 'sin' <matplotlib.figure.Figure at 0x218b44eb208>How can I proceed from this? I've never gotten an AttributeError before, so I don't know how to fix it. Any help is greatly appreciated!