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 Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by