How to perform summation with double subscript notation?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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))));
採用された回答
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 件のコメント
@Star Strider actually I only uploaded part of the code. Just wanted to know if my summation formating is right or wrong. I am giving the full code. Can you please comment on this on? I am getting slight different result than expected.
clc
clear all
close all
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
lambda=walenength(t);
E=((h*c)/lambda);
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(t)=(alpha+(Ad*((E-Egd)^(1/2))));
end
plot((walenength./10^-6),Alpha)
set(gca,'YScale','log')
ylim([(10^0) (10^9)])
xlabel('Wavelength \lambda ,(\mum)'),ylabel('Absorption Coefficient, \alpha(m^{-1})')
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
lambda=walenength(t);
E=((h*c)/lambda);
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(t)=(alpha+(Ad*((E-Egd)^(1/2))));
end
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')

This is difficult to follow. I do not understand taking the square root in the second term of the ‘Alpha(t)’ assignment, since the square root is not in the posted symbolic code.
It would likely be best for you to go through this to be certain there are no coding errors, since this is not an area of my expertise. I have no idea what the ‘expected’ result is, so I have nothing to compare it to.
.
@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.

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.
.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
