How to assign new variables to an equation with set parameters?

15 vues (au cours des 30 derniers jours)
Kyle Lazaroff
Kyle Lazaroff le 13 Déc 2019
So far this is the code i have for it, i need to split L_sun into 3 variables based off of values set by lambda.
close
clear
clc
r_d = 1.50e11; % distance from Earth to Sun
r_s = (1.39e9)/2; % radius of the sun
fw =(r_s/r_d)^2;
t_s = 5800; % temp in kelvin
h = 6.626e-34; % in J*s
k_b = 1.381e-23; % in J/K
c = 2.998e8; % in m/s
syms lambda L_sun
lambda = (0.001:0.01:3)*1e-6;
L_sun = fw .* (2*pi*h*c.^2) ./ lambda.^5 .*...
1./(exp((h*c)./(lambda*k_b*t_s)) -1);
every time i end up just assigning all of L_sun to the new variables instead of just the portions
uv = L_sun when lambda < 0.38e-6
vis = L_sun when 0.38e-6 < lambda < 0.78e_6
ir = L_sun when lambda > 0.78e-6

Réponses (1)

Nishant Gupta
Nishant Gupta le 16 Déc 2019
You can modify the code as following:
syms lambda L_sun
lambda = (0.001:0.01:3)*1e-6;
j=1;
k=1;
l=1;
for i=1:300
L_sun = fw .* (2*pi*h*c.^2) ./ lambda(i).^5 .* 1./(exp((h*c)./(lambda(i)*k_b*t_s)) -1);
if (lambda(i) < 0.38e-6)
uv(j) = L_sun;
j = j + 1;
elseif (lambda(i) > 0.38e-6) && (lambda(i) < 0.78e-6)
vis(k) = L_sun;
k = k+1;
else
ir(l) = L_sun;
l = l+1;
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by