multiplying scalar by matrix

87 views (last 30 days)
Louisa Mezache
Louisa Mezache on 22 Sep 2020
Edited: the cyclist on 22 Sep 2020
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

Accepted Answer

the cyclist
the cyclist on 22 Sep 2020
Edited: the cyclist on 22 Sep 2020
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 Comments
the cyclist
the cyclist on 22 Sep 2020
Edited: the cyclist on 22 Sep 2020
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 on 22 Sep 2020
Got it! That's very helpful. Thank you, again!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!