How to generate matrix filled with function values
1 view (last 30 days)
Show older comments
I'm trying to create a surface plot of the Plack radiation law over a range of temperatures and wavelengths, but when so far I've been unsuccessful. I've tried to use meshgrid to set my range of values as
EDU>> [l,T] = meshgrid(0:25:1000,0:300:12000);
where l is wavelength in nm and T is temperature in Kelvins. However, this means that when I plug it into my energy distribution function, I get a matrix filled with the same row.
distr = Planck(l,T);
where Planck is the function defined by
function [ distr ] = Planck( lam,temp )
%Applies the Planck radiation law to give the energy emitted by a black
%body for some given wavelength and temperature. Units are dimensionless,
%and given by u(lamda,T)/(8*pi*c*h/((550nm)^5).
% Input:
%lam = the actual wavelength
%temp = the actual temperature
%For our reference wavelength, we will use 550 nm, meaning that our
%reference temperature will be 26180 in accordance with the relationship
%T-knot = (h*c)/(lambda-knot*k)
L = lam/(550);
T = temp/(26180);
e = exp(1);
distr = (1./(L.^5))./(e.^(1./(L*T))-1);
end
Having used this to create a number of 2-D plots, the 3-D version should have lower z values for lower temperatures, but because all of the rows of distr are the same, the function is being displayed as constant with respect to T. So if I have a range of x values and a range of y values, and z is a function of x and y, how do I create a matrix filled with z-values for each combination of x and y in that range?
4 Comments
Cedric
on 18 Jan 2013
Was note your code per se I guess but your post. Just by adding a few spaces on lines starting with code and using || to make e.g. variable names standing out in chunks of text, you would have made it more readable:
I'm trying to create a surface plot of ...
EDU>> [l,T] = meshgrid(0:25:1000,0:300:12000);
where l is wavelength in nm and T is temperature in Kelvins. However, this means that when I plug it into my energy distribution function, I get a matrix filled with the same row.
distr = Planck(l,T);
where Planck is the function defined by
function [ distr ] = Planck( lam,temp )
% Applies the Planck radiation law to give the energy emitted by a
% black body for some given wavelength and temperature. Units are
% dimensionless, and given by u(lamda,T)/(8*pi*c*h/((550nm)^5).
% Input:
% lam = the actual wavelength
% temp = the actual temperature
% For our reference wavelength, we will use 550 nm, meaning that our
% reference temperature will be 26180 in accordance with the
% relationship T-knot = (h*c)/(lambda-knot*k)
L = lam/(550);
T = temp/(26180);
e = exp(1);
distr = (1./(L.^5))./(e.^(1./(L*T))-1);
end
Having used this to create a number of 2-D plots, the 3-D version should have lower z values for lower temperatures, but because all of the rows of distr are the same, the function is being displayed as constant with respect to T. So if I have a range of x values and a range of y values, and z is a function of x and y, how do I create a matrix filled with z-values for each combination of x and y in that range?
Accepted Answer
Thorsten
on 16 Jan 2013
You have to use element-wise multiplication L.*T:
distr = (1./(L.^5))./(e.^(1./(L.*T))-1);
0 Comments
More Answers (0)
See Also
Categories
Find more on Discrete Data 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!