3 (a) calculate thy potential at point P located a distance z above the center of a charged disk of
radius a and surface charge density p, Coulombs per square meter. Please show all work An
integral that you may need is The elemental area in cylindrical coordinates is dA = (b) Calculate
the electric field at P. Use back of page if necessary
Solution
function [Ef] = Loop_Ef() %(Main M-File function)
clc, clear all, close all
u.N1 = 1e21; %This is the number of states
u.NA = 1e15; %This is the number of acceptors
u.ND = 0; %This is the number of donors
u.Z1 = 281.73e19; %This term in front of the square root of the energy (this contains mass of
electron)
u.Z2 = 757.989e19; %This is the mass of hole
u.Eg = 1.12/2; %This is the energy gap
u.a = 0.0259;
%u.rat_a = 2 %scaling factor that modifies the steepness of the oxide exponential density of
states
u.es = 11.9 * 8.854187817e-14; %permittivity measured C / cm * V
u.qe = 1.602e-19; %This is the value of charge
u.psi_0_range = linspace(-0.4, 1, 160)\'; %This defines the range of Psi_0
u.display = true; %psi is in Volts Not ev?
%%
%ratN_range = 1e-2; ratS_range = [ 0.5: 0.2: 2];
ratN_range = 1; ratS_range = 1; %This doesn’t matter for Parabolic DOS
for iN = 1 : length(ratN_range)
for iS = 1 : length(ratS_range)
u.ratN = ratN_range(iN);
u.ratS = ratS_range(iS);
u.N2 = u.ratN * u.N1;
try
% Ef_(iN,iS) = Calculate_Ef(u); %Here its calculating the f_function
Ef_(iN,iS) = -0.356324 %REMOVE-TESTING
u.Ef_ = Ef_(iN,iS); %Here Ef equals
u.Q = Calculate_El(u);%Here is calculating the charge
DiffQ(u);
catch
Ef_(iN,iS) = NaN; %If there is nothing then NaN
end
end
end
clf,
plot(u.psi_0_range, u.Q) %Its plotting the graph
u.Ef_all = Ef_;
save \'u.mat\' %It saves all the data in u.file
save \'Ef_.dat\' Ef_ -ascii %Exports the data of Ef as ascii
keyboard %This command gives the control to the user
end
%================================================
function [Ef_] = Calculate_Ef(u)
clc
time = cputime;
%rescale volumes for numerical stability
u.Nscale = u.N1 ^ 2;
Nscale = u.Nscale;
u.N1 = u.N1 / Nscale;
u.N2 = u.N2 / Nscale;
u.Z1 = u.Z1 / Nscale;
u.Z2 = u.Z2 / Nscale;
%get rid of the u.\'\'
N1 = u.N1; N2 = u.N2;
Z1 = u.Z1; Z2 = u.Z2;
Eg = u.Eg;
a = u.a;
NA = u.NA/Nscale; ND = u.ND/Nscale;
P_1 = @(E) Z1.*sqrt(-Eg-E); %This is the parabolic function(Valance band)
P_2 = @(E) Z2.*sqrt(E-Eg); %This is the parabolic function (Conduction band)
Fn = @(E,Ef) 1 ./ ( exp((E-Ef)/a) ); %This is the Fermi-dirac for electrons
Fp = @(E,Ef) 1 ./ ( exp((Ef-E)/a) ); %This is the Fermi-dirac for holes
dp = @(E,Ef) P_1(E) .* Fp(E,Ef); %the integrands
dn = @(E,Ef) P_2(E) .* Fn(E,Ef);
p = @(Ef) Nscale * (IntegrateInf_p( @(E) dp(E,Ef), u ) + ND); %define our functions p & n
(Ef)
n = @(Ef) Nscale * (IntegrateInf_n( @(E) dn(E,Ef), u ) + NA);
%%we need to make sure that multiplication/division with Nscale is consistent all the way
through to DiffQ
Ef_ = Solve_Ef(-0.5, p, n); %Ef* is obtained here
fprintf(\'The value Ef*= %f, gives equal val.
3 (a) calculate thy potential at point P located a distance z above .pdf
1. 3 (a) calculate thy potential at point P located a distance z above the center of a charged disk of
radius a and surface charge density p, Coulombs per square meter. Please show all work An
integral that you may need is The elemental area in cylindrical coordinates is dA = (b) Calculate
the electric field at P. Use back of page if necessary
Solution
function [Ef] = Loop_Ef() %(Main M-File function)
clc, clear all, close all
u.N1 = 1e21; %This is the number of states
u.NA = 1e15; %This is the number of acceptors
u.ND = 0; %This is the number of donors
u.Z1 = 281.73e19; %This term in front of the square root of the energy (this contains mass of
electron)
u.Z2 = 757.989e19; %This is the mass of hole
u.Eg = 1.12/2; %This is the energy gap
u.a = 0.0259;
%u.rat_a = 2 %scaling factor that modifies the steepness of the oxide exponential density of
states
u.es = 11.9 * 8.854187817e-14; %permittivity measured C / cm * V
u.qe = 1.602e-19; %This is the value of charge
u.psi_0_range = linspace(-0.4, 1, 160)'; %This defines the range of Psi_0
u.display = true; %psi is in Volts Not ev?
%%
%ratN_range = 1e-2; ratS_range = [ 0.5: 0.2: 2];
ratN_range = 1; ratS_range = 1; %This doesn’t matter for Parabolic DOS
for iN = 1 : length(ratN_range)
for iS = 1 : length(ratS_range)
u.ratN = ratN_range(iN);
u.ratS = ratS_range(iS);
u.N2 = u.ratN * u.N1;
try
% Ef_(iN,iS) = Calculate_Ef(u); %Here its calculating the f_function
2. Ef_(iN,iS) = -0.356324 %REMOVE-TESTING
u.Ef_ = Ef_(iN,iS); %Here Ef equals
u.Q = Calculate_El(u);%Here is calculating the charge
DiffQ(u);
catch
Ef_(iN,iS) = NaN; %If there is nothing then NaN
end
end
end
clf,
plot(u.psi_0_range, u.Q) %Its plotting the graph
u.Ef_all = Ef_;
save 'u.mat' %It saves all the data in u.file
save 'Ef_.dat' Ef_ -ascii %Exports the data of Ef as ascii
keyboard %This command gives the control to the user
end
%================================================
function [Ef_] = Calculate_Ef(u)
clc
time = cputime;
%rescale volumes for numerical stability
u.Nscale = u.N1 ^ 2;
Nscale = u.Nscale;
u.N1 = u.N1 / Nscale;
u.N2 = u.N2 / Nscale;
u.Z1 = u.Z1 / Nscale;
u.Z2 = u.Z2 / Nscale;
%get rid of the u.''
N1 = u.N1; N2 = u.N2;
Z1 = u.Z1; Z2 = u.Z2;
Eg = u.Eg;
a = u.a;
3. NA = u.NA/Nscale; ND = u.ND/Nscale;
P_1 = @(E) Z1.*sqrt(-Eg-E); %This is the parabolic function(Valance band)
P_2 = @(E) Z2.*sqrt(E-Eg); %This is the parabolic function (Conduction band)
Fn = @(E,Ef) 1 ./ ( exp((E-Ef)/a) ); %This is the Fermi-dirac for electrons
Fp = @(E,Ef) 1 ./ ( exp((Ef-E)/a) ); %This is the Fermi-dirac for holes
dp = @(E,Ef) P_1(E) .* Fp(E,Ef); %the integrands
dn = @(E,Ef) P_2(E) .* Fn(E,Ef);
p = @(Ef) Nscale * (IntegrateInf_p( @(E) dp(E,Ef), u ) + ND); %define our functions p & n
(Ef)
n = @(Ef) Nscale * (IntegrateInf_n( @(E) dn(E,Ef), u ) + NA);
%%we need to make sure that multiplication/division with Nscale is consistent all the way
through to DiffQ
Ef_ = Solve_Ef(-0.5, p, n); %Ef* is obtained here
fprintf('The value Ef*= %f, gives equal values for: p(Ef*)= %f & n(Ef*)= %f ', Ef_, p(Ef_),
n(Ef_) )
fprintf('Time: %2.2fsecs ', cputime-time ) %displays the time
if u.display
clf
b = 1; %range of the graphs AND of Ef search
PlotParabolics (Eg, b, P_1, P_2); %This is plotting the parabolics
PlotFermis (b, Fn, Fp, Ef_); %This is plotting the fermis
PlotIntegrands(Eg, b, dp, dn, Ef_);%This is plotting the integrands
PlotIntegrals(Ef_, p, n, 0.05); %This is plotting the integrals
pause
end
end
%================================================
The algorithm presented below is used to generate the Current
function [Q_values] = Calculate_Q(u)
clc
time = cputime;
4. %rescale volumes for numerical stability
u.Nscale = u.N1^2;
Nscale = u.Nscale;
u.N1 = u.N1 / Nscale;
u.N2 = u.N2 / Nscale;
u.NA = u.NA / Nscale;
u.ND = u.ND / Nscale;
u.Z1 = u.Z1 / Nscale;
u.Z2 = u.Z2 / Nscale;
%get rid of the u.x
N1 = u.N1;
N2 = u.N2;
Z1 = u.Z1; Z2 = u.Z2;%so, now all terms in rho are scaled
NA = u.NA;
ND = u.ND;
Eg = u.Eg;
a = u.a;
Ef_ = u.Ef_;
es = u.es;
qe = u.qe;
%%
%anonynous functions for Q
P_1_ = @(E,psi) Z1.*sqrt(-(Eg+psi)-E); %This defines parabolic but includes psi
P_2_ = @(E,psi) Z2.*sqrt(E-(Eg-psi)); % + 1e14*exp(E/rat_a * a);
Fn_ = @(E) 1 ./ exp((E - Ef_)/a) ; %This is the Fermi-Dirac
Fp_ = @(E) 1 ./ exp((Ef_- E)/a) ;
dp_ = @(E,psi) P_1_(E,psi) .* Fp_(E); %The integrands
dn_ = @(E,psi) P_2_(E,psi) .* Fn_(E);
p_ = @(psi) IntegrateInf_p_( @(E) dp_(E,psi), u, psi); %These are the new integrals with psi
n_ = @(psi) IntegrateInf_n_( @(E) dn_(E,psi), u, psi);
5. rho = @(psi) qe * ( p_(psi) + ND - NA - n_(psi) ); %charge density, NA & ND here =
NA&ND / Nscale
%we multiply with charge of electron to convert carrier density to charge density
ElI = @(psi_0) Nscale * quadv( rho, 0, psi_0, 1e-15 ); %use quadv here as inputs cannot be
vectored in our case
%we multiply by Nscale here to bring data to their un-
scaled values
Q = @(psi_0) sqrt( abs( 2 * es * ElI(psi_0) ) ); % C/cm^2
Q_values = [];
% warning('off', 'MATLAB:quadl:MaxFcnCount') %shoot the pigs!
for i = 1 : length(u.psi_0_range) %This determines Q for every psi
psi_0 = u.psi_0_range(i);
try
Q_values(i) = Q(psi_0);
catch
Q_values(i) = NaN;
end
fprintf( ' Q(%3.5f)= %3.10f', psi_0, Q_values(end) )
end
fprintf(' Time: %2.2fsecs ', cputime-time )
end
%================================================
The following algorithm will be used to integrate the information
function [val] = IntegrateInf_p(func, u) %For Holes
Eg = u.Eg; %This defines Eg
Nsc = u.Nscale;
b = 66; %bound for approximation of integral: intuitive!!!
type = 'smart';
switch lower(type)
case 'fixed'
b1 = -b;
6. b2 = +b;
case 'smart' %find integral significance interval
E_range = linspace(-b, -Eg, 10000)';%This defines the range of E
y = func(E_range); This calculates the max value
[mx, idx] = max(y);
tol = mx / Nsc; %Nsc>>1
left = find( abs(y(1:idx-1)) < tol );
left = max(left);
if false
figure
plot(E_range, y, '-'), hold on
plot( E_range(left ), y(left ), 'rs', 'markersize', 2)
pause(1), close
end
b1 = E_range(left); %This is the limites of the integral
b2 = -Eg;
end
val = quadl(func, b1, b2, 1e-33);%This calculates the integral
end
%================================================
function [val] = IntegrateInf_p_(func, u, pote)%For holes
Eg= u.Eg;
Nsc = u.Nscale;
b = 66; %bound for approximation of integral: intuitive!!!
type = 'smart';
switch lower(type)
case 'fixed'
b1 = -b;
b2 = +b;
case 'smart' %find integral significance interval
E_range = linspace(-b, -(Eg+pote), 10000)';
y = func(E_range);
[mx, idx] = max(y);
tol = mx / Nsc; %Nsc>>1
7. left = find( abs(y(1:idx-1)) < tol );
left = max(left);
if false
figure
plot(E_range, y, '-'), hold on
plot( E_range(left ), y(left ), 'rs', 'markersize', 2)
pause(1), close
end
b1 = E_range(left); %This limits the integral including psi
b2 = -(Eg+pote);
end
val = quadl(func, b1, b2, 1e-33);%This calculates the integral using quadl
end
%================================================
function [val] = IntegrateInf_n(func, u) %For electrons
Eg = u.Eg;
Nsc = u.Nscale;
b = 66; %bound for approximation of integral: intuitive!!!
type = 'smart';
switch lower(type)
case 'fixed'
b1 = -b;
b2 = +b;
case 'smart' %find integral significance interval
E_range = linspace(Eg, +b, 10000)';
y = func(E_range);
[mx, idx] = max(y);
tol = mx / Nsc; %Nsc>>1
right = find( abs(y(idx+1:end)) < tol );
right = idx+min(right);
if false
figure
plot(E_range, y, '-'), hold on
plot( E_range(right), y(right), 'rs', 'markersize', 2)
8. pause(1), close
end
b1 = Eg;
b2 = E_range(right);
end
val = quadl(func, b1, b2, 1e-33);
end
%================================================
function [val] = IntegrateInf_n_(func, u, pote)%For electrons
Eg= u.Eg;
Nsc = u.Nscale;
b = 66; %bound for approximation of integral: intuitive!!!
type = 'smart';
switch lower(type)
case 'fixed'
b1 = -b;
b2 = +b;
case 'smart' %find integral significance interval
E_range = linspace((Eg-pote), +b, 10000)';
y = func(E_range);
[mx, idx] = max(y);
tol = mx / Nsc; %Nsc>>1
right = find( abs(y(idx+1:end)) < tol );
right = idx+min(right);
if false
figure
plot(E_range, y, '-'), hold on
plot( E_range(right), y(right), 'rs', 'markersize', 2)
pause(1), close
end
b1 = Eg-pote;
b2 = E_range(right);
end
9. val = quadl(func, b1, b2, 1e-33);
end
%================================================
function [] = PlotIntegrals(Ef_, p, n, b) %These are the plotting commands
Ef_range = linspace( Ef_-b, Ef_+b, 30);
p_vals = [];
n_vals = [];
for Ef = Ef_range
p_vals = [ p_vals; p(Ef) ];
n_vals = [ n_vals; n(Ef) ];
end
subplot(2,2,4)
plot_prop = { 'linewidth', 1 };
plot( Ef_range, p_vals, 'k', plot_prop{:} );
hold on
plot( Ef_range, n_vals, 'r', plot_prop{:} );
plot( Ef_, p(Ef_), 'og', 'markersize', 10, plot_prop{:} )
xlabel('E_f'); ylabel('p(E_f), n(E_f)')
title( ['plot2: Ef*=', num2str(Ef_) ] )
axis tight
end
%================================================
Following algorithms are used for the plotting purpose of the results
function [] = PlotIntegrands(Eg, b, dp, dn, Ef) %These are the plotting commands
subplot(2,2,2)
E_range_pos = linspace(Eg, +b, 500)';
E_range_neg = linspace(-b, -Eg, 500)';
plot_prop = { 'linewidth', 1 };
plot( E_range_neg, dp(E_range_neg, Ef), 'k', plot_prop{:} );
hold on
plot( E_range_pos, dn(E_range_pos, Ef), 'r', plot_prop{:} );
xlabel('E'); ylabel('dn(E) & dp(E)')
title('bf dp(black), dn(red)')
10. axis tight
end
%================================================
function [] = PlotParabolics(Eg, b, N_1, N_2) %These are the plotting commands
subplot(2,2,1)
E_range_neg = linspace(-b, -Eg, 500)';
E_range_pos = linspace(Eg, b, 500)';
plot_prop = { 'linewidth', 1 };
plot( E_range_neg, N_1(E_range_neg), 'k', plot_prop{:} );
hold on
plot( E_range_pos, N_2(E_range_pos), 'r', plot_prop{:} );
xlabel('E'); ylabel('N(E)')
title('bf N1(black): Valence, N2(red): Conduction')
axis tight
end
%================================================
function [] = PlotFermis(b, Fn, Fp, Ef) %These are the plotting commands
hold off
subplot(2,2,3)
E_range = linspace(-b, +b, 500)';
plot_prop = { 'linewidth', 1 };
plot( E_range, Fn(E_range, Ef), 'r', plot_prop{:} );
hold on
plot( E_range, Fp(E_range, Ef), 'k', plot_prop{:} );
xlabel('E'); ylabel('Fn(E), Fp(E)')
title('bfFp(black), Fn(red)')
axis tight
end
%================================================
function [Eq] = Solve_Ef(x0, p, n)%This calculates Ef for every value
type = 'optim';
switch lower(type)
case 'manual'
11. b = 6;
Ef_range = -b+2.3 : 0.001 : +b-2.3;
p_vals = [];
n_vals = [];
for Ef = Ef_range
p_vals = [ p_vals; p(Ef) ];
n_vals = [ n_vals; n(Ef) ];
end
[val, idx] = min( abs(p_vals-n_vals) ); %find intersection
Eq = Ef_range(idx);
case 'optim'
options = optimset('TolFun', 1e-12,...
'TolX', 1e-7,...
'MaxIter', 500, ...
'FunValCheck', 'on',...
'Display', 'iter');
[Eq, fval, exitflag, output] = fminsearch(@error, x0, options); %Nelder-Mead
end
%---nested error function---
function y = error(x);
y = abs( p(x) - n(x) );
end
%---nested error function---
end
%================================================
function [] =xxx() %This symbolic.Ef defines our parameters to be real
clear all
clc
syms E N1 N2 Eg real
pi_ = sym(pi);
N_1 = @(E) Z1.*sqrt(-Eg-E);
N_2 = @(E) Z2.*sqrt(E-Eg);
12. %G1 = subs(G1,N1,1);
%int(G1, E, -inf, +inf)
syms Ef real
syms a positive
Fn = 1 / ( 1 + exp((E-Ef)/a) );
Fp = 1 / ( 1 + exp((Ef-E)/a) );
%int(Fp, E, -inf,+inf)
%p = int( G1*Fp, E, -inf, +inf );
%n = int( G2*Fn, E, -inf, +inf );
pd = subs( G1 * Fp, {N1, s1, a}, {12, 0.12, 1} );
end
%================================================
%side = +ve or - ve side
function [] = DiffQ(u, side) %Calculation of the capacitance
clc
time = cputime;
x = u.psi_0_range; %This defines the x
y = u.Q'; %This defines the y
%y(x>0) = -y(x>0); %THIS HAS TO BE HANDLED WITHIN El
%y(x<0) = -y(x<0);
if exist( 'side', 'var')
region = sign(side)*x >= 0.0;
x = x(region);
y = y(region);
end
if false
gnum = min( floor(length(x)/3), 8 );
model = [ 'gauss' num2str(gnum) ];
13. obj = fittype(model);
opts = fitoptions( 'method', 'nonlinear', 'display', 'iter' );
fres = fit(x, y, obj, opts );
else %splines
fres = fit(x, y, 'cubicspline');
% fres = fit(x, y, 'smoothingspline', 'SmoothingParam', 1-1e-6);
end
x2 = linspace( min(x), max(x), 200); %Fitting for 200 points
diff = differentiate(fres, x2); %This is the differentiation of Q
diff = abs(diff);%This gives the absolute values of diff
clf
subplot(3,1,1), plot(fres, 'k-', x, y, 'bo');%The plotting commands
ylabel('Q')
axis tight
%legend('data', 'fitted curve')
legend off
subplot(3,1,2), plot(x2, diff,'r-', 'linewidth', 1)
ylabel('dQ/dpsi')
axis tight
cox = 17.2659e-9 %Farads, dox=200nm, eox=3.9
%cox = 23.020868e-9 %Farads, dox=150nm, eox=3.9
cap = diff*cox ./ (diff+cox); %This calculates the capacitance
subplot(3,1,3), plot(x2, cap,'r-', 'linewidth', 1)
ylabel('cap')
axis tight
fprintf(' Time: %2.2fsecs ', cputime-time )
end
%================================================
14. -Matlab code Gaussian (polymer) DOS distribution
The below mentioned algorithm is used to iterate the values and generate the data for results.
function [Ef] = Loop_Ef() %(This is the Main M-file function)
clc, clear all, close all
%For Gaussian (polymer)
u.N1 = 1e21; %This is the number of states
u.NA = 1e15; %This is the number of acceptors
u.ND = 0; %This is the number of donors
u.Z1 = 89.6167e19; %This term in front of the square root of the energy (this contains mass of
electron)
u.Z2 = 241.2757e19; %This is the mass of hole
u.Eg = 1.12./2; %This is the energy gap
u.a = 0.0259; %This is the term that represents KT
%u.rat_a = 2 %scaling factor that modifies the steepness of the oxide exponential density of
states
u.es = 3 * 8.854187817e-14;%The permittivity measured C / cm * V
u.qe = 1.602e-19; %This is the value of charge
u.psi_0_range = linspace(-0.4, 1, 160)'; %This defines the range of Psi_0
u.display = true; %psi is in eV
%%
%ratN_range = 1e-2; ratS_range = [ 0.5: 0.2: 2];
ratN_range = 1; ratS_range = 1; %This doesn’t matter for Parabolic DOS
for iN = 1 : length(ratN_range)
for iS = 1 : length(ratS_range)
u.ratN = ratN_range(iN);
u.ratS = ratS_range(iS);
u.N2 = u.ratN * u.N1;
try
15. %Ef_(iN,iS) = Calculate_Ef(u); %Here its calculating the f_function
Ef_(iN,iS) = -0.386001 %REMOVE-TESTING
u.Ef_ = Ef_(iN,iS); %The ef equals
u.Q = Calculate_El(u); %Here is calculating the charge
DiffQ(u);
catch
Ef_(iN,iS) = NaN; %If there is nothing then NaN
end
end
end
clf,
plot(u.psi_0_range, u.Q) %Here its plotting
u.Ef_all = Ef_;
save 'u.mat' %It saves all data in a u.file
save 'Ef_.dat' Ef_ -ascii %This exports the data of Ef AS ascii
keyboard %Here the command gives control to the user
end
%================================================
function [Ef_] = Calculate_Ef(u) %This is the same as parabolic
clc
time = cputime;
%rescale volumes for numerical stability
Nscale = u.N1 ^ 2;
u.N1 = u.N1 / Nscale;
u.N2 = u.N2 / Nscale;
%get rid of the u.''
N1 = u.N1; N2 = u.N2;
s1 = u.s1; s2 = u.s2;
Eg = u.Eg;
a = u.a;
NA = u.NA/Nscale; ND = u.ND/Nscale;
G1 = @(E) N1/(s1*sqrt(2*pi)) .* exp( -(E+Eg).^2 / (2*s1^2) ); %This is the Gausssian
16. (Valance band)
G2 = @(E) N2/(s2*sqrt(2*pi)) .* exp( -(E-Eg).^2 / (2*s2^2) ); %This is the Gaussian
(Conduction band)
Fn = @(E,Ef) 1 ./ ( 1 + exp((E-Ef)/a) );
Fp = @(E,Ef) 1 ./ ( 1 + exp((Ef-E)/a) );
dp = @(E,Ef) G1(E) .* Fp(E,Ef); %the integrands
dn = @(E,Ef) G2(E) .* Fn(E,Ef);
p = @(Ef) Nscale * (IntegrateInf( @(E) dp(E,Ef), Nscale ) + ND); %define our functions p & n
(Ef)
n = @(Ef) Nscale * (IntegrateInf( @(E) dn(E,Ef), Nscale ) + NA);
%%we need to make sure that multiplication/devision with Nscale is consistent all the eay
through to DiffQ
Ef_ = Solve_Ef(0, p, n); %Ef* is obtained here
fprintf('The value Ef*= %f, gives equal values for: p(Ef*)= %f & n(Ef*)= %f ', Ef_, p(Ef_),
n(Ef_) )
fprintf('Time: %2.2fsecs ', cputime-time )
if u.display
clf
b = 3; %range of the graphs AND of Ef search
PlotGaussians (b, G1, G2);
PlotFermis (b, Fn, Fp, Ef_);
PlotIntegrands(b, dp, dn, Ef_);
PlotIntegrals(Ef_, p, n, 0.05);
pause
end
end
%================================================
The algorithm presented below is used to generate the Current
function [Q_values] = Calculate_Q(u) %This calculates the total charge
clc
time = cputime;
18. rho = @(psi) qe * ( p_(psi) + ND - NA - n_(psi) ); %NA & ND here = NA&ND / Nscale
%we multiply with charge of electron to convert carrier density to charge density
ElI = @(psi_0) Nscale * quadv( rho, 0, psi_0, 1e-15 ); %use quadv here as inputs cannot be
vectored in our case
%we multiply by Nscale here to bring data to their un-
scaled values
Q = @(psi_0) sqrt( abs( 2 * es * ElI(psi_0) ) ); % C/cm^2
Q_values = [];
% warning('off', 'MATLAB:quadl:MaxFcnCount') %shoot the pigs!
for i = 1 : length(u.psi_0_range)
psi_0 = u.psi_0_range(i);
try
Q_values(i) = Q(psi_0);
catch
Q_values(i) = NaN;
end
fprintf( ' Q(%3.5f)= %3.10f', psi_0, Q_values(end) )
end
fprintf(' Time: %2.2fsecs ', cputime-time )
end
%================================================
The following algorithm will be used to integrate the information
function [val] = IntegrateInf_n(func, u) %Again same as parabolic but it’s not necessary to
change the limits of our integration
Eg = u.Eg;
Nsc = u.Nscale;
b = 66; %bound for approximation of integral: intuitive!!!
type = 'smart';
switch lower(type)
case 'fixed'
b1 = -b;
19. b2 = +b;
case 'smart' %find integral significance interval
E_range = linspace(Eg, +b, 10000)';
y = func(E_range);
[mx, idx] = max(y);
tol = mx / Nsc; %Nsc>>1
right = find( abs(y(idx+1:end)) < tol );
right = idx+min(right);
if false
figure
plot(E_range, y, '-'), hold on
plot( E_range(right), y(right), 'rs', 'markersize', 2)
pause(1), close
end
b1 = Eg;
b2 = E_range(right);
end
val = quadl(func, b1, b2, 1e-33);
end
%================================================
function [] =xxx() %This is symbolic Ef (Its exactly the same as Parabolic but here is for
Gaussian)
clear all
clc
syms E N1 N2 Eg real
syms s1 s2 positive
pi_ = sym(pi);
G1 = N1/(s1*sqrt(2*pi_)) * exp( -E^2 / (2*s1^2) );
G2 = N2/(s2*sqrt(2*pi_)) * exp( -(E-Eg)^2 / (2*s2^2) );
%G1 = subs(G1,N1,1);
%int(G1, E, -inf, +inf)
syms Ef real
20. syms a positive
Fn = 1 / ( 1 + exp((E-Ef)/a) );
Fp = 1 / ( 1 + exp((Ef-E)/a) );
%int(Fp, E, -inf,+inf)
%p = int( G1*Fp, E, -inf, +inf );
%n = int( G2*Fn, E, -inf, +inf );
pd = subs( G1 * Fp, {N1, s1, a}, {12, 0.12, 1} );
end
%================================================
function [Eq] = Solve_Ef(x0, p, n) %The same as parabolic but here is for Gaussian
type = 'optim';
switch lower(type)
case 'manual'
b = 6;
Ef_range = -b+2.3 : 0.001 : +b-2.3;
p_vals = [];
n_vals = [];
for Ef = Ef_range
p_vals = [ p_vals; p(Ef) ];
n_vals = [ n_vals; n(Ef) ];
end
[val, idx] = min( abs(p_vals-n_vals) ); %find intersection
Eq = Ef_range(idx);
case 'optim'
options = optimset('TolFun', 1e-12,...
'TolX', 1e-7,...
'MaxIter', 500, ...
'FunValCheck', 'on',...
'Display', 'iter');
[Eq, fval, exitflag, output] = fminsearch(@error, x0, options); %Nelder-Mead
end
21. %---nested error function---
function y = error(x);
y = abs( p(x) - n(x) );
end
%---nested error function---
end
%================================================
function [] = PlotGaussians(b, G1, G2) %Here is plotting the Gaussian
subplot(2,2,1)
E_range = linspace(-b, +b, 500)';
plot_prop = { 'linewidth', 1 };
plot( E_range, G1(E_range), 'k', plot_prop{:} );
hold on
plot( E_range, G2(E_range), 'r', plot_prop{:} );
xlabel('E'); ylabel('G1(E), G2(E)')
title('bfG1(black): HOMO, G2(red): LUMO')
axis tight
end
%================================================
Following algorithms are used for the plotting purpose of the results
function [] = PlotIntegrals(Ef_, p, n, b)%Here is plotting the Integrals
Ef_range = linspace( Ef_-b, Ef_+b, 30);
p_vals = [];
n_vals = [];
for Ef = Ef_range
p_vals = [ p_vals; p(Ef) ];
n_vals = [ n_vals; n(Ef) ];
end
subplot(2,2,4)
plot_prop = { 'linewidth', 1 };
plot( Ef_range, p_vals, 'k', plot_prop{:} );
hold on
plot( Ef_range, n_vals, 'r', plot_prop{:} );
22. plot( Ef_, p(Ef_), 'og', 'markersize', 10, plot_prop{:} )
xlabel('E_f'); ylabel('p(E_f), n(E_f)')
title( ['plot2: Ef*=', num2str(Ef_) ] )
axis tight
end
%================================================
function [] = PlotIntegrands(b, dp, dn, Ef) )%Here is plotting the Integrands
subplot(2,2,2)
E_range = linspace(-b, +b, 500)';
plot_prop = { 'linewidth', 1 };
[ax,h1,h2] = plotyy( E_range, dp(E_range, Ef), E_range, dn(E_range, Ef) );
set( get(ax(1),'Ylabel'), 'String', 'dp')
set(get(ax(2),'Ylabel'),'String','dn')
set( h1, 'Color','k' )
set( h2, 'Color','r')
%plot( E_range, dp(E_range, Ef), 'k', plot_prop{:} ); hold on
%plot( E_range, dn(E_range, Ef), 'r', plot_prop{:} );
%ylabel('dp(E) & dn(E)')
xlabel('E');
title('bfdp=G_1*F_p(black) and dn=G_2*F_n(red)')
axis tight
end
%================================================
function [] = PlotFermis(b, Fn, Fp, Ef) %Here is plotting the Fermis
hold off
subplot(2,2,3)
E_range = linspace(-b, +b, 500)';
plot_prop = { 'linewidth', 1 };
plot( E_range, Fn(E_range, Ef), 'r', plot_prop{:} );
hold on
plot( E_range, Fp(E_range, Ef), 'k', plot_prop{:} );
xlabel('E'); ylabel('Fn(E), Fp(E)')
title('bfFp(black), Fn(red)')
axis tight
23. end
%================================================
%side = +ve or - ve side
function [] = DiffQ(u, side)
clc
time = cputime;
x = u.psi_0_range; %This defines x
y = u.Q'; %This defines y
%y(x>0) = -y(x>0); %THIS HAS TO BE HANDLED WITHIN El
%y(x<0) = -y(x<0);
if exist( 'side', 'var')
region = sign(side)*x >= 0.0;
x = x(region);
y = y(region);
end
if false
gnum = min( floor(length(x)/3), 8 );
model = [ 'gauss' num2str(gnum) ];
obj = fittype(model);
opts = fitoptions( 'method', 'nonlinear', 'display', 'iter' );
fres = fit(x, y, obj, opts );
else %splines
%fres = fit(x, y, 'cubicspline');
fres = fit(x, y, 'smoothingspline', 'SmoothingParam', 1-1e-6);
end
x2 = linspace( min(x), max(x), 200); %Here is fitting with 200 points
diff = differentiate(fres, x2); %This is the differentiation of Q
diff = abs(diff); %This gives the absolute value of diff
clf
subplot(3,1,1), plot(fres, 'k-', x, y, 'bo'); %Here is the plotting commands