multiplying scalar by matrix

102 visualizaciones (últimos 30 días)
Louisa Mezache
Louisa Mezache el 22 de Sept. de 2020
Editada: the cyclist el 22 de Sept. de 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

Respuesta aceptada

the cyclist
the cyclist el 22 de Sept. de 2020
Editada: the cyclist el 22 de Sept. de 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 comentarios
the cyclist
the cyclist el 22 de Sept. de 2020
Editada: the cyclist el 22 de Sept. de 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 el 22 de Sept. de 2020
Got it! That's very helpful. Thank you, again!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by