Query regarding for loop

1 vue (au cours des 30 derniers jours)
Amy Topaz
Amy Topaz le 14 Mar 2022
Modifié(e) : Rena Berman le 8 Avr 2022
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 commentaires
AndresVar
AndresVar le 14 Mar 2022
Modifié(e) : AndresVar le 14 Mar 2022
Could you write the equation in vector form like Ax=b?
as it is now, you can put most stuff outside loop except fzero.
Rena Berman
Rena Berman le 8 Avr 2022

(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 14 Mar 2022
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)
sol = struct with fields:
EF1: (T1*kb*(log(z1) + pi*k*2i))/e parameters: [k z1] conditions: ~in((e*((T1*kb*(log(z1) + pi*k*2i))/e - (T1*kb*log(-4*exp((e*ea1)/(T1*kb))))/e)*1i)/(2*T1*kb*pi), 'integer') & in(k, 'integer') & log(z1) + pi*k*2i ~= 0 & ~in((e*((T1*kb*(log(z1) + pi*k*2i))/e - (T1*kb*log(-(exp(-(764645580906253*T1*e)…
sc = subs(sol.conditions, sol.parameters(1), 0)
sc = 
sz = solve(sc, sol.parameters(2))
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
sz = 
sol_EF1 = subs(sol.EF1, {sol.parameters(1), sol.parameters(2)}, {0, sz})
sol_EF1 = 
  1 commentaire
Walter Roberson
Walter Roberson le 14 Mar 2022
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 !

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by