필터 지우기
필터 지우기

How to generate matrix filled with function values

조회 수: 2 (최근 30일)
Jack Dempsey
Jack Dempsey 2013년 1월 16일
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
Cedric
Cedric 2013년 1월 18일
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?
Jack Dempsey
Jack Dempsey 2013년 1월 19일
Alright, I'll keep that in mind. Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Thorsten
Thorsten 2013년 1월 16일
You have to use element-wise multiplication L.*T:
distr = (1./(L.^5))./(e.^(1./(L.*T))-1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by