how to make anonymous function and it's plot?

8 次查看(过去 30 天)
i want to make black body radiation
clear
close all
clc
%Black body radiation graph
R=@(wl,T) 2*pi*c^2*h./(wl.^5)./(exp(h*c./wl/k/T)-1);
h=6.626e-34;
c=3e8;
k=1.38e-23;
wl=0.1:0.1:3;
this is my code but they said c doesn't recognize what's the problem...?

回答(1 个)

Star Strider
Star Strider 2020-11-21
Either include all of them as arguments:
R=@(wl,T,h,c,k) 2*pi*c^2*h./(wl.^5)./(exp(h*c./wl/k/T)-1);
h=6.626e-34;
c=3e8;
k=1.38e-23;
wl=1E-9:0.1:3;
T = 273;
figure
plot(wl,R(wl,T,h,c,k) )
grid
or define the ‘R’ function after assigning the constants:
%Black body radiation graph
h=6.626e-34;
c=3e8;
k=1.38e-23;
R=@(wl,T) 2*pi*c^2*h./(wl.^5)./(exp(h*c./wl/k/T)-1);
wl=1E-9:0.1:3;
T = 273;
figure
plot(wl,R(wl,T))
grid
Regardless, the constants must exist in your workspace before the ‘R’ function is called.
Both of these will work.

类别

Help CenterFile Exchange 中查找有关 Graphics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by