how to make anonymous function and it's plot?

28 visualizzazioni (ultimi 30 giorni)
jessica mik
jessica mik il 21 Nov 2020
Risposto: Star Strider il 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...?

Risposte (1)

Star Strider
Star Strider il 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.

Community Treasure Hunt

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

Start Hunting!

Translated by