multiplying scalar by matrix

조회 수: 99 (최근 30일)
Louisa Mezache
Louisa Mezache 2020년 9월 22일
편집: the cyclist 2020년 9월 22일
Hello,
I'm trying to plot the equations for I1 and I2 on the same graph, but nothing is showing up when I run the code. To avoid any matrix/scalar multiplication and division mistakes, I just added a period everywhere. The x-axis should be lambda, from 400 to 700 but the blank graph that shows up is from 0 to 1. I appreciate any help. I'm fairly new to Matlab, but I'm working on getting more practice. Below is my code. Please let me know if you need any more information.
lambda = 400:700;
h = 6.626e-34; %Planck's constant
c = 3e8; %speed of light
k = 1.380e-23; %Boltzmann's constant
T1 = 505.372; %preheat temperature in Kelvin
T2 = 449.817; %cooking temperature in Kelvin
I1 = (2*h*c^2 ./ lambda.^5) .* 1./(exp(h*c./lambda .* k .* T1) - 1); %spectral radiance at T1
I2 = (2*h*c^2 ./ lambda.^5) .* 1./(exp(h*c./lambda .* k .* T2) - 1); %spectral radiance at T2
plot(lambda,I1,lambda,I2)
Thank you,
Louisa

채택된 답변

the cyclist
the cyclist 2020년 9월 22일
편집: the cyclist 2020년 9월 22일
In the exponentials, you missed an important set of parentheses, ensuring that you divide by the whole expression
(lambda .* k .* T)
Instead, you are dividing by lambda, and then multiplying by k and T.
You need
I1 = (2*h*c^2 ./ lambda.^5) .* 1./(exp(h*c./(lambda .* k .* T1)) - 1); %spectral radiance at T1
I2 = (2*h*c^2 ./ lambda.^5) .* 1./(exp(h*c./(lambda .* k .* T2)) - 1); %spectral radiance at T2
  댓글 수: 3
the cyclist
the cyclist 2020년 9월 22일
편집: the cyclist 2020년 9월 22일
You're welcome. FYI, this was fairly easy to debug by inspecting the variable values when you plotted them. The issue was that I1 and I2 were actually "Infinite". Then it was a matter of tracing back how that happened.
If you are not familiar with the debugging tools in MATLAB, take a look at this documentation.
Louisa Mezache
Louisa Mezache 2020년 9월 22일
Got it! That's very helpful. Thank you, again!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by