how to make anonymous function and it's plot?

9 vues (au cours des 30 derniers jours)
jessica mik
jessica mik le 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...?

Réponses (1)

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

Catégories

En savoir plus sur Graphics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by