How to perform summation with double subscript notation?

3 visualizzazioni (ultimi 30 giorni)
Hello everyone, I have to perform some analysis based on the following equation, which contains summation operator with double subscript notation.
I have written a code. Can anyone please look at it and confim whether I am wrong or right?
alpha =0;
for i=1:2
for j=1:2
alpha=alpha +(C(i)*A(j)*((((E-Eg(j)+Ep(i))^2)/(exp(Ep(i)/(k*T))-1))+(((E-Eg(j)-Ep(i))^2)/(1-exp(-Ep(i)/(k*T))))));
end
end
Alpha=(alpha+(Ad*((E-Egd)^(1/2))));

Risposta accettata

Star Strider
Star Strider il 6 Mar 2022
First, provide the ‘C’ and the other missing vectors, then save ‘alpha’ as a matrix, then use the sum function to sum its elements.
alpha =0;
for i=1:2
for j=1:2
alpha(i,j) = C(i)*A(j)*((((E-Eg(j)+Ep(i))^2)/(exp(Ep(i)/(k*T))-1)));
end
end
Unrecognized function or variable 'C'.
Alpha=(sum(alpha(:))+(Ad*((E-Egd).^(1/2))))
Try that with the vectors to see if the result is as desired.
.
  4 Commenti
Md. Golam Zakaria
Md. Golam Zakaria il 6 Mar 2022
@Star Strider actually the square root is there, I mistyped the equation. You just tell me if there is any coding error regarding the summation.
Star Strider
Star Strider il 6 Mar 2022
I do not see anything wrong with it. The easiest way to troubleshoot it is to see what the individual terms evaluate to, and then see if those are correct —
h=4.136*10^-15; % Planck's Constant
k=8.617*10^-5; % Boltzmann's Constant
c=3*10^8; % speed of light
T=300; % Ambient Temparature
beta=7.021*10^-4;
gamma=1108;
Eg0_1=1.1557;
Eg0_2=2.5;
Egd0=3.2;
Eg1=Eg0_1-((beta*(T^2))/(T+gamma));
Eg2=Eg0_2-((beta*(T^2))/(T+gamma));
Egd=Egd0-((beta*(T^2))/(T+gamma));
Eg=[Eg1 Eg2];
Ep=[1.827*10^-2 5.773*10^-2];
C=[5.5 4.0];
A=[3.231*10^2 7.237*10^3];
Ad=1.052*10^6;
walenength=(.2*10^-6):(.0001*10^-6):(1.2*10^-6);
num=numel(walenength);
Alpha=nan(1,num);
for t=1:(num/1000)
lambda=walenength(t);
E=((h*c)/lambda);
alpha =0;
for i=1:2
for j=1:2
fprintf([repmat('—',1, 20) '\nt = %4d\ti = %d\tj = %d\n'],t,i,j)
Term_1(i,j) = (((E-Eg(j)+Ep(i))^2)./(exp(Ep(i)/(k.*T))-1))
Term_2(i,j) = (((E-Eg(j)-Ep(i))^2)/(1-exp(-Ep(i)/(k*T))))
alpha=alpha +(C(i)*A(j)*((((E-Eg(j)+Ep(i))^2)./(exp(Ep(i)/(k.*T))-1))+(((E-Eg(j)-Ep(i))^2)/(1-exp(-Ep(i)/(k*T))))));
end
end
Alpha(t)=(alpha+(Ad*((E-Egd)^(1/2))));
end
———————————————————— t = 1 i = 1 j = 1
Term_1 = 25.4307
Term_2 = 50.8231
———————————————————— t = 1 i = 1 j = 2
Term_1 = 1×2
25.4307 13.8133
Term_2 = 1×2
50.8231 27.4640
———————————————————— t = 1 i = 2 j = 1
Term_1 = 2×2
25.4307 13.8133 3.1853 0
Term_2 = 2×2
50.8231 27.4640 28.3998 0
———————————————————— t = 1 i = 2 j = 2
Term_1 = 2×2
25.4307 13.8133 3.1853 1.7396
Term_2 = 2×2
50.8231 27.4640 28.3998 15.2603
———————————————————— t = 2 i = 1 j = 1
Term_1 = 2×2
25.3999 13.8133 3.1853 1.7396
Term_2 = 2×2
50.7610 27.4640 28.3998 15.2603
———————————————————— t = 2 i = 1 j = 2
Term_1 = 2×2
25.3999 13.7905 3.1853 1.7396
Term_2 = 2×2
50.7610 27.4184 28.3998 15.2603
———————————————————— t = 2 i = 2 j = 1
Term_1 = 2×2
25.3999 13.7905 3.1815 1.7396
Term_2 = 2×2
50.7610 27.4184 28.3649 15.2603
———————————————————— t = 2 i = 2 j = 2
Term_1 = 2×2
25.3999 13.7905 3.1815 1.7368
Term_2 = 2×2
50.7610 27.4184 28.3649 15.2347
———————————————————— t = 3 i = 1 j = 1
Term_1 = 2×2
25.3691 13.7905 3.1815 1.7368
Term_2 = 2×2
50.6991 27.4184 28.3649 15.2347
———————————————————— t = 3 i = 1 j = 2
Term_1 = 2×2
25.3691 13.7678 3.1815 1.7368
Term_2 = 2×2
50.6991 27.3728 28.3649 15.2347
———————————————————— t = 3 i = 2 j = 1
Term_1 = 2×2
25.3691 13.7678 3.1776 1.7368
Term_2 = 2×2
50.6991 27.3728 28.3300 15.2347
———————————————————— t = 3 i = 2 j = 2
Term_1 = 2×2
25.3691 13.7678 3.1776 1.7340
Term_2 = 2×2
50.6991 27.3728 28.3300 15.2091
———————————————————— t = 4 i = 1 j = 1
Term_1 = 2×2
25.3383 13.7678 3.1776 1.7340
Term_2 = 2×2
50.6372 27.3728 28.3300 15.2091
———————————————————— t = 4 i = 1 j = 2
Term_1 = 2×2
25.3383 13.7452 3.1776 1.7340
Term_2 = 2×2
50.6372 27.3274 28.3300 15.2091
———————————————————— t = 4 i = 2 j = 1
Term_1 = 2×2
25.3383 13.7452 3.1738 1.7340
Term_2 = 2×2
50.6372 27.3274 28.2951 15.2091
———————————————————— t = 4 i = 2 j = 2
Term_1 = 2×2
25.3383 13.7452 3.1738 1.7311
Term_2 = 2×2
50.6372 27.3274 28.2951 15.1835
———————————————————— t = 5 i = 1 j = 1
Term_1 = 2×2
25.3076 13.7452 3.1738 1.7311
Term_2 = 2×2
50.5754 27.3274 28.2951 15.1835
———————————————————— t = 5 i = 1 j = 2
Term_1 = 2×2
25.3076 13.7226 3.1738 1.7311
Term_2 = 2×2
50.5754 27.2820 28.2951 15.1835
———————————————————— t = 5 i = 2 j = 1
Term_1 = 2×2
25.3076 13.7226 3.1700 1.7311
Term_2 = 2×2
50.5754 27.2820 28.2603 15.1835
———————————————————— t = 5 i = 2 j = 2
Term_1 = 2×2
25.3076 13.7226 3.1700 1.7283
Term_2 = 2×2
50.5754 27.2820 28.2603 15.1581
———————————————————— t = 6 i = 1 j = 1
Term_1 = 2×2
25.2770 13.7226 3.1700 1.7283
Term_2 = 2×2
50.5137 27.2820 28.2603 15.1581
———————————————————— t = 6 i = 1 j = 2
Term_1 = 2×2
25.2770 13.7000 3.1700 1.7283
Term_2 = 2×2
50.5137 27.2367 28.2603 15.1581
———————————————————— t = 6 i = 2 j = 1
Term_1 = 2×2
25.2770 13.7000 3.1662 1.7283
Term_2 = 2×2
50.5137 27.2367 28.2256 15.1581
———————————————————— t = 6 i = 2 j = 2
Term_1 = 2×2
25.2770 13.7000 3.1662 1.7255
Term_2 = 2×2
50.5137 27.2367 28.2256 15.1326
———————————————————— t = 7 i = 1 j = 1
Term_1 = 2×2
25.2464 13.7000 3.1662 1.7255
Term_2 = 2×2
50.4521 27.2367 28.2256 15.1326
———————————————————— t = 7 i = 1 j = 2
Term_1 = 2×2
25.2464 13.6775 3.1662 1.7255
Term_2 = 2×2
50.4521 27.1915 28.2256 15.1326
———————————————————— t = 7 i = 2 j = 1
Term_1 = 2×2
25.2464 13.6775 3.1624 1.7255
Term_2 = 2×2
50.4521 27.1915 28.1909 15.1326
———————————————————— t = 7 i = 2 j = 2
Term_1 = 2×2
25.2464 13.6775 3.1624 1.7227
Term_2 = 2×2
50.4521 27.1915 28.1909 15.1072
———————————————————— t = 8 i = 1 j = 1
Term_1 = 2×2
25.2159 13.6775 3.1624 1.7227
Term_2 = 2×2
50.3906 27.1915 28.1909 15.1072
———————————————————— t = 8 i = 1 j = 2
Term_1 = 2×2
25.2159 13.6550 3.1624 1.7227
Term_2 = 2×2
50.3906 27.1464 28.1909 15.1072
———————————————————— t = 8 i = 2 j = 1
Term_1 = 2×2
25.2159 13.6550 3.1586 1.7227
Term_2 = 2×2
50.3906 27.1464 28.1563 15.1072
———————————————————— t = 8 i = 2 j = 2
Term_1 = 2×2
25.2159 13.6550 3.1586 1.7199
Term_2 = 2×2
50.3906 27.1464 28.1563 15.0819
———————————————————— t = 9 i = 1 j = 1
Term_1 = 2×2
25.1854 13.6550 3.1586 1.7199
Term_2 = 2×2
50.3293 27.1464 28.1563 15.0819
———————————————————— t = 9 i = 1 j = 2
Term_1 = 2×2
25.1854 13.6326 3.1586 1.7199
Term_2 = 2×2
50.3293 27.1013 28.1563 15.0819
———————————————————— t = 9 i = 2 j = 1
Term_1 = 2×2
25.1854 13.6326 3.1548 1.7199
Term_2 = 2×2
50.3293 27.1013 28.1217 15.0819
———————————————————— t = 9 i = 2 j = 2
Term_1 = 2×2
25.1854 13.6326 3.1548 1.7171
Term_2 = 2×2
50.3293 27.1013 28.1217 15.0566
———————————————————— t = 10 i = 1 j = 1
Term_1 = 2×2
25.1549 13.6326 3.1548 1.7171
Term_2 = 2×2
50.2680 27.1013 28.1217 15.0566
———————————————————— t = 10 i = 1 j = 2
Term_1 = 2×2
25.1549 13.6102 3.1548 1.7171
Term_2 = 2×2
50.2680 27.0563 28.1217 15.0566
———————————————————— t = 10 i = 2 j = 1
Term_1 = 2×2
25.1549 13.6102 3.1510 1.7171
Term_2 = 2×2
50.2680 27.0563 28.0872 15.0566
———————————————————— t = 10 i = 2 j = 2
Term_1 = 2×2
25.1549 13.6102 3.1510 1.7143
Term_2 = 2×2
50.2680 27.0563 28.0872 15.0313
figure
plot((walenength./10^-6),real(Alpha))
hold on
plot((walenength./10^-6),imag(Alpha))
plot((walenength./10^-6),abs(Alpha),'--')
hold off
set(gca,'YScale','log')
ylim([(10^0) (10^9)])
xlabel('Wavelength \lambda ,(\mum)')
ylabel('Absorption Coefficient, \alpha(m^{-1})')
legend('Re(\alpha(T))','Im(\alpha(T))','|\alpha(T)|', 'Location','best')
See if the intermediate values appear to be correct.
.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by