I am trying to plot an integrated function of E with the range of values of E. I cannot figure out how to make the output of the integrate.quad function compatible with the range of E.
This is the code that I have been using
import numpy as np
import scipy.constants as phys
import scipy.integrate as integrate
import math
import matplotlib.pyplot as plt
E = np.linspace(0, 12, 10000)
fermi = 4.5
kT = 0.04
dfdE = np.exp((E-fermi)/(kT))/((np.exp((E-fermi)/(kT)) 1)**2) * 1/(kT)
t = 1/(1 np.exp(-2*np.pi * (E-(0-0.5)*3))) 1/(1 np.exp(-2*np.pi * (E-(1-0.5)*3))) 1/(1 np.exp(-2*np.pi * (E-(2-0.5)*3))) 1/(1 np.exp(-2*np.pi * (E-(3-0.5)*3))) 1/(1 np.exp(-2*np.pi * (E-(4-0.5)*3))) 1/(1 np.exp(-2*np.pi * (E-(5-0.5)*3))) 1/(1 np.exp(-2*np.pi * (E-(6-0.5)*3))) -2
f = dfdE*t-2
def f_integral(E):
return f
result_f = integrate.quad_vec(f_integral, fermi-1.5, fermi 1.5 )
print(result_f)
plt.plot(E,result_f)
This is the error that is occurring:
Traceback (most recent call last):
File ~\OneDrive\Documents\BSc_Project\Plot.py:29 in <module>
plt.plot(E,result_f)
File ~\anaconda3\lib\site-packages\matplotlib\pyplot.py:2757 in plot
return gca().plot(
File ~\anaconda3\lib\site-packages\matplotlib\axes\_axes.py:1632 in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File ~\anaconda3\lib\site-packages\matplotlib\axes\_base.py:312 in __call__
yield from self._plot_args(this, kwargs)
File ~\anaconda3\lib\site-packages\matplotlib\axes\_base.py:498 in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (10000,) and (2,)
Any help would be appreciated.
CodePudding user response:
Since your result_f
is a tuple, you need to slice it with [0]
before calling