0

So I have tried to plot a log log curve of intensity vs frequency using planck equation with the help of python.But I didn't get the output.i don't know were are the errors exactly.

import matplotlib.pyplot as plt 
import numpy as np

h = 6.626e-34 
c = 3.0e+8 
k = 1.38e-23

def planck(freq, T):
    a = 2.0*h*freq**3
    b = h*freq/(k*T)
    intensity = a/ ( (c**2) * (np.exp(b) - 1.0) )
    return intensity 

frequency = np.logspace(10e+9, 10e+19, 1e10,endpoint=False) 
# intensity at 3000K, 5000K, 10000K, 20000K,30000K 
intensity3000 = planck(frequency, 3000.) 
intensity5000 = planck(frequency, 5000.) 
intensity10000 = planck(frequency, 10000.)
intensity20000 = planck(frequency, 20000.)
intensity30000=planck(frequency,30000.)

plt.loglog(frequency, intensity3000, 'k-')
# plot intensity3000 versus frequency in Hz as a black line
plt.loglog(frequency, intensity5000, 'y-') 
# 5000K yellow line 
plt.loglog(frequency, intensity10000, 'r-') 
# 10000K red line 
plt.loglog(frequency, intensity20000, 'g-') 
# 20000K green line 

plt.xlim([10e+9,10e+19])
plt.ylim([1,1e10])
# show the plot 
plt.show()

I tried to run the program .but this is what I got:

> Traceback (most recent call last):   File
> "/data/user/0/ru.iiec.pydroid3/app_HOME/planckplot.py", line 11, in
> <module>    File "<__array_function__ internals>", line 5, in logspace
> File
> "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/numpy/core/function_base.py",
> line 275, in logspace
>     y = linspace(start, stop, num=num, endpoint=endpoint, axis=axis)   File "<__array_function__ internals>", line 5, in linspace   File
> "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/numpy/core/function_base.py",
> line 120, in linspace
>     num = operator.index(num) TypeError: 'float' object cannot be interpreted as an integer

I am really stuck here. What I am looking for is a log-log graph with B_nu in units of Joule/sec/meter^2/steradian/Hertz along the Y-axis and frequency in Hertz along the X-axis. The frequency range is taken from 10^9 Hz to 10^19 Hz. Ps:I have only beginner level python knowledge.

JohanC
  • 71,591
  • 8
  • 33
  • 66
  • [See `np.logspace(start, stop, num, end_point=False)`](https://numpy.org/doc/stable/reference/generated/numpy.logspace.html). `start` and `stop` need to be the exponents, not the full numbers, `num=1e10` is valid because `1e10` is interpreted as a float, not an integer, and also because it is much too high as number of elements of an array. Try `np.logspace(9, 19, 200, endpoint=False)` instead. – JohanC Feb 20 '23 at 06:53
  • You need something like `frequency = np.logspace( +9, +19, 25, endpoint=False)`. Check the [docs](https://numpy.org/doc/stable/reference/generated/numpy.logspace.html) on `logspace` – mikuszefski Feb 20 '23 at 06:54
  • ...y limits are probably wrong as well. – mikuszefski Feb 20 '23 at 06:55
  • Thanks for all the advice . I corrected it but didn't get the graph. More like I got a plain x -y axis without curves. How can I correct it to get the answer – VISMAYA P V Feb 21 '23 at 14:34
  • I tried to paste the output here , but didn't work. – VISMAYA P V Feb 21 '23 at 14:35

0 Answers0