I'm trying to plot log-log graph for the black body spectrum with frequency range 10^9 to 10^19 with temperatures 3000k, 5000k, 10000k, 20000k, 30000k I can't plot the graph
2 views (last 30 days)
Show older comments
h =6.626e-34;
c = 3e8;
k= 1.38e-23;
T1 =3000;
T2=5000;
T3=10000;
T4=20000;
T5=30000;
nu=linspace(1e9,1e19,100);
B=(2*h*nu.^3/c.^2)/(exp(h*nu /(k*T))-1);
plot(nu,B);
xlim(1e9, 1e19);
loglog(nu,B);
xlabel ('frequency ,Hz');
ylabel ('Bv,(w/(m^2steradian)')
1 Comment
dpb
on 25 May 2022
You wrote
B=(2*h*nu.^3/c.^2)/(exp(h*nu /(k*T))-1);
but used multiple different variables T1, T2, ... instead to set the temperatures you wanted. MATLAB doesn't do anything magic to associate those variables with one just called "T", you have to do that yourself.
Make and array of T and pass each to the equation in turn -- or, you could use <meshgrid> and do them all at once. To do that you'll need to use the "dot" operators throughout the expression, not just for the exponents (that actually don't need it here as they're operating on constants, not arrays).
Answers (1)
Walter Roberson
on 25 May 2022
B = (2*h*nu.^3/c.^2) ./ (exp(h*nu./(k*T))-1);
1 Comment
Walter Roberson
on 26 May 2022
You have values down to 1e-69500. You will have a difficult time getting a meaningful plot out.
format long g
Q = @(v) sym(v);
h = Q(6.626e-34);
c = Q(3e8);
k = Q(1.38e-23);
T1 = 3000;
T2 = 5000;
T3 = 10000;
T4 = 20000;
T5 = 30000;
nu = linspace(Q(1e9),Q(1e19),100); %row !
%T = Q([T1; T2; T3; T4; T5]); %column !
T = Q(logspace(log10(T1), log10(T5), 25).');
B = (2 .* h .* nu.^3 ./ c.^2) ./ (exp(h .* nu ./ (k .* T))-1);
[min(B(:)), max(B(:))]
vpa(ans)
surf(double(nu), double(T), double(log10(B)))
xlabel ('frequency ,Hz');
ylabel('Temperature')
ylabel ('log10(Bv), (w/(m^2steradian)')
Notice that -6e4 here means 10^(-60000) -- an incredibly small value.
I suggest that you review your formulas and constants.
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!