how to make anonymous function and it's plot?

16 Ansichten (letzte 30 Tage)
jessica mik
jessica mik am 21 Nov. 2020
Beantwortet: Star Strider am 21 Nov. 2020
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...?

Antworten (1)

Star Strider
Star Strider am 21 Nov. 2020
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.

Kategorien

Mehr zu Graphics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by