Lozansky
Lozansky

Reputation: 374

Black-body intensity curves for different temperatures [simple]

I have written a function that will calculate the intensity depending on temperature on wavelength. This is what the code looks like for the temperature 600 K:

function f=radiation(l,t)

l = linspace(0,10^-5,100); % The interval for the wavelength
a = 3.7415*10^(-16) ;      % constant
b = 0.014388;              % constant
t=600;                     % Setting the temperature to 600 K
f = a./(l.^5.*(exp(b./(l*t))-1)); 
plot(l,f)

Now I want to plot curves for different temperatures in the same window without having to repeat the code. How can I do this in a neat way?

Upvotes: 0

Views: 566

Answers (1)

RPM
RPM

Reputation: 1769

Here's a way without having to loop over multiple temperatures:

l = linspace(0,10^-5,100); % The interval for the wavelength
a = 3.7415*10^(-16) ;      % constant
b = 0.014388;              % constant
t=[600,800,1000,1200];
figure;             
[t,l] = meshgrid(t,l);
f = a./(l.^5.*(exp(b./(l.*t))-1)); 
plot(l,f)
legend(num2str(t(1,:)'))

This gives me the following:

enter image description here

Upvotes: 4

Related Questions