MATLAB: What do the constants h,c and k do to the function?

chemistrycolorconstantsfiguregraphsetwavelength

figure('Name','Black Body','Menu','none','NumberTitle','on','Position',[500 100 350 450])
set(gcf,'Color',[0.6 1.0 1.0])
%h=6.6256e-34; c=2.9979e8; k=1.3805e-23;

u=@(lambda,T)(8*pi*h*c)./(lambda.^5.*(exp((h*c)./(k*lambda*T))-1));
%h=6.6256e-34; c=2.9979e8; k=1.3805e-23;
lambda=linspace(0.01e-6,10e-6,300);
plot(lambda*1e6,u(lambda, 800),'Color',[0.6 0.0 0.6],'LineWidth',2), hold on
plot(lambda*1e6,u(lambda, 850),'Color',[0.3 0.7 1.0],'LineWidth',2)
plot(lambda*1e6,u(lambda, 900),'Color',[0.0 0.8 0.0],'LineWidth',2)
plot(lambda*1e6,u(lambda, 950),'Color',[1.0 0.7 0.4],'LineWidth',2)
plot(lambda*1e6,u(lambda,1000),'Color',[0.9 0.0 0.0],'LineWidth',2), hold off
axis([0 10 0 200]), grid on
set(gca,'XTick',0:2:10,'YTick',0:50:200)
xlabel('Wavelength (\mum)','FontSize',11)
ylabel('Energy density (J m^{-4})','FontSize',11)
legend(' 800 K',' 850 K',' 900 K',' 950 K','1000 K')
If I have them before or after the anonymous function the graph works. If I take them away the graph still works.If I change say k to 1 no lines appear…which is odd since taking away all three values makes the graph work….I'm confused. Can anyone guide me in this?
The constants are c=speed of light, h=Pl*ncks const*nt and k=Boltzm*n const*nt.

Best Answer

The function picks up the constants from the workspace, so they have to appear in your code before the function. Defining the constants only after the function throws an error when I run it.