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

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.

1 Comment

Is it important if you put them before the function or after?? For me it works either way.
Take away the % guys from the constants. Sorry for the typo....I was trying what would happen if i put the constants after the function.

Sign in to comment.

 Accepted 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.

4 Comments

Oh dang! That was the problem...
A quick question... if you don't mind.Changing u=@(lambda,T) to u=@(l,T) for all lambda in the equation has no effect on the graph. Why?
I searched for lambda in help in case matlab uses greek symbols but found nothing. I typed out l and it is not defined (obviously) but lambda is. Why does the function still work when you change lambda to l in the function definition?
The ‘u’ function is an anonymous function. The arguments and the variables they refer to in ‘u’ are ‘local’ to ‘u’ and are not shared by the rest of the workspace. It doesn’t matter what you call the various arguments to a function providing you change all references to those arguments in the function to match. (Note that while an anonymous function can pick up values of constants from the workspace, it does not share its internal variables with the workspace, returning as output to the workspace only the results of its calculations that you choose to have it return.)

Sign in to comment.

More Answers (0)

Categories

Asked:

on 16 Oct 2014

Commented:

on 16 Oct 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!