Query regarding for loop

5 Ansichten (letzte 30 Tage)
Amy Topaz
Amy Topaz am 14 Mär. 2022
Bearbeitet: Rena Berman am 8 Apr. 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 Kommentare
AndresVar
AndresVar am 14 Mär. 2022
Bearbeitet: AndresVar am 14 Mär. 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 am 8 Apr. 2022

(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 14 Mär. 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 Kommentar
Walter Roberson
Walter Roberson am 14 Mär. 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 !

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by