Query regarding for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
I have the below logic
T1 = linspace(10, 800, 10);
for range1 = 1:numel(T1)
a = 2*Mc*(((mde*kb*T1(range1))/(2*pi*(hbar^2)))^(3/2));
b = 2*(((mdh*kb*T1(range1))/(2*pi*(hbar^2)))^(3/2));
c = (kb*T1(range1))/e;
d = 1.17 - (8.096e-8*((T1(range1))^2))/(T1(range1) + 800);
ec1 = d;
ed1 = ec1 + Edi;
eq = @(EF1) ((a)*exp(-(ec1-EF1)/c)) + ((NA1)/(1+4*exp(-(EF1-ea1)/c))) - (((b)*exp(-(EF1-ev1)/c)) + ((ND1)/(1+2*exp(-(ed1-EF1)/c))));
x = [0 2];
Eflevel1(range1) = fzero(eq, x);
end
%How can I write the above lines without using for loop? Is that possible?
%Assume all other values as constants.
댓글 수: 2
답변 (1개)
Walter Roberson
2022년 3월 14일
Q = @(v) sym(v);
syms Edi EF1 e ea1 ev1 hbar kb Mc mde mdh NA1 ND1 T1
assume([Edi, EF1, e, ea1, ev1, hbar, kb, Mc, mde, mdh, NA1, ND1, T1] ~= 0)
Pi = Q(pi);
range1 = 1;
T1vals = linspace(10, 800, 10);
a = 2*Mc*(((mde*kb*T1(range1))/(2*Pi*(hbar^2)))^(3/2));
b = 2*(((mdh*kb*T1(range1))/(2*Pi*(hbar^2)))^(3/2));
c = (kb*T1(range1))/e;
d = Q(1.17) - (Q(8.096e-8)*((T1(range1))^2))/(T1(range1) + Q(800));
ec1 = d;
ed1 = ec1 + Edi;
eq = ((a)*exp(-(ec1-EF1)/c)) + ((NA1)/(1+4*exp(-(EF1-ea1)/c))) - (((b)*exp(-(EF1-ev1)/c)) + ((ND1)/(1+2*exp(-(ed1-EF1)/c))));
sol = solve(eq, EF1, 'returnconditions', true)
sc = subs(sol.conditions, sol.parameters(1), 0)
sz = solve(sc, sol.parameters(2))
sol_EF1 = subs(sol.EF1, {sol.parameters(1), sol.parameters(2)}, {0, sz})
댓글 수: 1
Walter Roberson
2022년 3월 14일
The solutions involve roots of an equation of degree 4. I believe it is a polynomial, so I believe that explicit solutions are possible -- though they would be very long !
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!