Professional Documents
Culture Documents
% exp_phi_n[num_cells+1];
% exp_phi_p[num_cells+1];
% diff_v[num_cells];
% E[num_cells];
% up[num_cells+layers -1];
% un[num_cells+layers -1];
% um[num_cells+layers -1];
% v_middle[num_cells];
% Jn[num_cells+2];
% Jp[num_cells+2];
% J[num_cells+2];
% p[num_cells+1];
% n[num_cells+1];
% phi_p_interface[layers - 1];
% phi_n_interface[layers - 1];
function f0=main()
%// check whether the length of the device is equal to the sum of the
individual layers
layers = 4;
len_full=120e-9;
len_prec=1e-11;
length = 0.0;
for i=1:(layers)
len = [10e-9, 40e-9, 30e-9, 40e-9];
length =length + len(i);
end
for i=1:(layers-1)
ea=[3.6, 2.4, 3.19, 2.4];
eg=[2, 3.1, 2.38, 3.1];
phi_p_interface(i) = (ea(i+1)+eg(i+1)) - (ea(i)+eg(i)); %// interface
barrier for holes at O-O interface
phi_n_interface(i) = ea(i+1) - ea(i); %//interface
barrier for electrons at O-O interface
end
len_norm=len_full;
v_n = (kb*temp)/q;
E_n = v_n/len_norm;
cd_n = epsi_r*epsi_0*E_n/(q*len_norm);
for i=1:(layers)
uN = [1e-4, 6.9e-6,1.51e-7,1.51e-7]; %mobility of
electrons in layers
uP = [1e-3, 2.6e-4, 9.16e-10,9.16e-10]; %mobility of
holes in layers
u_n=uP(1);
ni(i) = (n_0/cd_n)*exp(-eg(i)/(2*kb_ev*temp));
uP_n(i) = uP(i)/u_n;
uN_n(i) = uN(i)/u_n;
end
del_v(layers-1) = 0.0;
for i=(layers-2):-1:1
del_v(i) = del_v(i+1) + ((ea(i+1) - ea(i)) + ((eg(i+1) -
eg(i))/2))/(kb_ev*temp);
end
for i=1:(layers-1)
JpintA(i) = exp (-phi_p_interface(i)/(kb_ev*temp));
JpintB(i) = (1200e3*300*300/n_0)*exp
(+phi_p_interface(i)/(kb_ev*temp)) / (q*E_n);
JnintA(i) = exp (-phi_n_interface(i)/(kb_ev*temp));
JnintB(i) = (1200e3*300*300/n_0)*exp
(+phi_n_interface(i)/(kb_ev*temp)) / (q*E_n);
end
%//file handling
% FILE *fp1, *fp2, *fp3, *fp4, *fp5, *fp6, *fp7, *fp8, *fp9, *fp10, *fp11,
*fp12 ,*fp13, *fpfile(3);
name = 'problem8HTL';
savedir = 'temp';
initdir = 'temp';
mkdir('D:/Simulation');
char(path);
fprintf(path, '%s%s%s', 'D:/Simulation/', name, '/');
char temppath;
fprintf('temppath', '%s%s', path, 'temp/');
mkdir('path');
mkdir('temppath');
% fp1 = fopen('V_dir.txt','w');
% fp2 = fopen('Edir.txt','w');
% fp3 = fopen('ndir.txt','w');
% fp4 = fopen('pdir.txt','w');
% fp5 = fopen('Xdir.txt','w');
% fp6 = fopen('exp_fn_dir.txt','w');
% fp7 = fopen('exp_fp_dir.txt','w');
% fp8 = fopen('Jdir.txt','w');
% fp9 = fopen('Jndir.txt','w');
% fp10 = fopen('Jpdir.txt','w');
% fp11 = fopen('updir.txt','w');
% fp12 = fopen('undir.txt','w');
% fp13 = fopen('plotdir.txt','w');
% fpfile(1) = fopen('file2.txt','w');
% fpfile(0) = fopen('file1.txt','w');
sprintf('%s%s%s', path,savedir,'/E.txt');
sprintf('%s%s%s', path,savedir,'/n.txt');
sprintf('%s%s%s', path,savedir,'/p.txt');
sprintf('%s%s%s', path,savedir,'/X.txt');
sprintf('%s%s%s', path,initdir,'/exp_fn.txt');
sprintf('%s%s%s', path,initdir,'/exp_fp.txt');
sprintf('%s%s%s', path,initdir,'/V.txt');
sprintf('%s%s%s', path,initdir,'/X.txt');
sprintf('exp_fn_dir_in','%s%s%s', path,savedir,'/exp_fn.txt');
sprintf('exp_fp_dir_in','%s%s%s', path,savedir,'/exp_fp.txt');
sprintf('V_dir_in','%s%s%s', path,savedir,'/V.txt');
sprintf('%s%s%s', path,savedir,'/J.txt');
sprintf('%s%s%s', path,savedir,'/Jn.txt');
sprintf('%s%s%s', path,savedir,'/Jp.txt');
sprintf('%s%s%s', path,savedir,'/up.txt');
sprintf('%s%s%s', path,savedir,'/un.txt');
sprintf('%s%s%s', path,savedir,'/plot.txt');
sprintf('%s%s%s', path,savedir,'/effi.txt');
sprintf('%s%s', path,'/IV_char.txt');
sprintf('%s%s', path,'/device_par.txt');
v_app = 0;
reading = 1;
incr_step = 0.1;
v_start=2.5;
v_final=15;
max_vol = v_final;
vapp = v_start;
for r=1:(v_app<max_vol)
j_temp = 0.0;
v_app = vapp + incr_step*r;
% // initial guess
initialize()
v_cell(1) = v_a;
v_cell(num_cells) = v_c;
count_iterations = 0;
iteration_max = 1500;
exp_phi_p=[num_cells+1];
exp_phi_n=[num_cells+1];
for j=0:iteration_max
count_iterations=count_iterations+1;
end
tol_v=1e-6;
field ()
if (fp>0)
psip = (1/fp) + sqrt(1/fp) - (1/fp)*sqrt(1+2*sqrt(fp));
spp = (S0pp/4) * (pow(psip,-2) - fp);
else
psip = (-1/fp) + sqrt(-1/fp) - (-1/fp)*sqrt(1+2*sqrt(-fp));
snp = (S0np/4) * (pow(psip,-2) + fp);
end
if (fn>0)
psin = (1/fn) + sqrt(1/fn) - (1/fn)*sqrt(1+2*sqrt(fn));
snn = (S0nn/4) * (pow(psin,-2) - fn);
else
psin = (-1/fn) + sqrt(-1/fn) - (-1/fn)*sqrt(1+2*sqrt(-fn));
spn = (S0pn/4) * (pow(psin,-2) + fn);
end
for l=0:(layers-2)
inter(l) = exp(E(cells_int(l)-1) *(del_x/2));
apoo(l) = inter(l) * JpintA(l) * ni(l) * exp(del_v(l));
bpoo(l) = (1/inter(l)) * ni(l+1) * (exp(del_v(l+1)));
kpoo(l) = ( (up(cells_int(l)-1+l) * u_n * E(cells_int(l)-
1)/JpintB(l)) + (up(cells_int(l)-1+l)/up(cells_int(l)+l)) * (1 - (bpoo(l) /
ni(l+1)) * (1/exp(del_v(l+1)))) - ((1 - inter(l)) * JpintA(l)) );
solve_continuity_n ()
solve_continuity_p ()
difference = 0.0;
calculate_current ()
calculate_carrier ()
end
if (j < iteration2)
rel_factor_j = 0.7;
end
if (j < iteration3)
rel_factor_j = 0.5;
end
else
return;
end
fp1 = fopen('V_dir.txt','w');
fp2 = fopen('Edir.txt','w');
fp3 = fopen('ndir.txt','w');
fp4 = fopen('pdir.txt','w');
fp5 = fopen('Xdir.txt','w');
fp6 = fopen('exp_fn_dir.txt','w');
fp7 = fopen('exp_fp_dir.txt','w');
fp8 = fopen('Jdir.txt','w');
fp9 = fopen('Jndir.txt','w');
fp10 = fopen('Jpdir.txt','w');
fp11 = fopen('updir.txt','w');
fp12 = fopen('undir.txt','w');
fp13 = fopen('plotdir.txt','w');
fpfile(1) = fopen('file2.txt','w');
fpfile(0) = fopen('file1.txt','w');
for i=1:num_cells
fprintf (fp1, '%i\t%e\n', i, v_cell(i)*v_n);
fprintf (fp3, '%i\t%e\n', i, n(i)*cd_n);
fprintf (fp4, '%i\t%e\t%e\n', i, p(i)*cd_n, (up(i)
+un(i))*p(i)*n(i));
fprintf (fp6, '%i\t%e\n', i, ((exp_phi_n(i))));
fprintf (fp7, '%i\t%e\n', i, ((exp_phi_p(i))));
fprintf (fp11, '%i\t%e\n', i, up(i));
fprintf (fp12, '%i\t%e\n', i, un(i));
fprintf (fp9, '%i\t%e\n', i, Jn(i)*J_n);
fprintf (fp10, '%i\t%e\n', i, Jp(i)*J_n);
fprintf (fp8, '%i\t%e\n', i, (J(i))*J_n);
if (i ~= num_cells)
%//length of device
for j=1:(layers-1)
fprintf (fpfile(2), '\t%e', len(j));
end
%//work function
if (vapp == v_app)
fprintf (fpfile(0), '%e\t%e', v_app, J(50)*J_n); % //instead of
J(50) we could have used any value, as J is constant throughout the device
else
fprintf (fpfile(0), '\n%e\t%e', v_app, J(50)*J_n);
end
% //applied voltage
% // fprintf (fpfile(1), '\n\n\nApplied voltage\t\t\t%e', v_app);
% // printing the rest of the values
org_int = 0;
for i=0:(num_cells+layers-1)
if (i==0)
fprintf (fpfile(1), '%e\t%e\t%e\t%e\t%s\t%s\t%s\t%s\t%s\t%e\t
%e\t%e\t%e\t%e', i*delx, Jn(i)*J_n, Jp(i)*J_n, J(i)*J_n, ' ',' ',' ', ' ',' ',
i*delx, v_cell(i)*v_n, n(i)*cd_n, p(i)*cd_n, (q/(epsi_r*epsi_0))*(un(i) +
up(i))*u_n*n(i)*cd_n*p(i)*cd_n);
continue;
end
if (i<num_cells+1)
fprintf (fpfile(1), '\n%e\t%e\t%e\t%e\t%e\t%e\t%e\t%e\t%e\t%e\t
%e\t%e\t%e\t%e', delx/2+(i-1)*delx, Jn(i)*J_n, Jp(i)*J_n, J(i)*J_n, delx/2+(i-
1)*delx, un(i-1+org_int)*u_n, up(i-1+org_int)*u_n, delx/2+(i-1)*delx, E(i-
1)*E_n, i*delx, v_cell(i)*v_n, n(i)*cd_n, p(i)*cd_n,
(q/(epsi_r*epsi_0))*(un(i+org_int) + up(i+org_int))*u_n*n(i)*cd_n*p(i)*cd_n);
end
if ((org_int < layers-1) && (i == cells_int(org_int)))
org_int=org_int+1;
fprintf (fpfile(1), '\n%s\t%s\t%s\t%s\t%e\t%e\t%e\t%s\t%s\t
%s\t%s\t%s\t%s\t%s', ' ',' ',' ',' ', delx/2+(i-1)*delx, un(i-1+org_int)*u_n,
up(i-1+org_int)*u_n, ' ',' ', ' ',' ',' ',' ',' ');
end
if (i==num_cells+1)
fprintf (fpfile(1), '\n%e\t%e\t%e\t%e\t%s\t%s\t%s\t%s\t%s\t
%s\t%s\t%s\t%s\t%s', (i-1)*delx, Jn(i)*J_n, Jp(i)*J_n, J(i)*J_n, ' ',' ',' ',
' ',' ', ' ',' ',' ',' ',' ');
end
end
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
fclose(fp5);
fclose(fp6);
fclose(fp7);
fclose(fp8);
fclose(fp9);
fclose(fp10);
fclose(fp11);
fclose(fp12);
fclose(fp13);
fclose(fpfile(1));
fclose(fpfile(0));
printf('\nPress any key to exit...');
return ;
end
function f1 = initialize()
layers=4;
num_cells=(1000+layers-1);
v_start=2.5;
vapp=v_start;
if v_app == vapp
for i=1:(num_cells+1)
exp_phi_n(i) = 1.0;
exp_phi_p(i) = 1.0;
v_cell(i) = 0.0;
end
end
% else
% fp1 = fopen ('exp_fn_dir_in', 'r');
% fp2 = fopen ('exp_fp_dir_in', 'r');
% fp3 = fopen ('V_dir_in', 'r');
% end
% for i=1:(num_cells+1)
% fscanf (fp1,'%e %e', c, d);
% exp_phi_n(i) = d;
% fscanf(fp2,'%e %e', c, d);
% exp_phi_p(i) = d;
% fscanf(fp3,'%e %e', c, d);
% v_cell(i) = (d/v_n);
% end
% fclose(fp1);
% fclose(fp2);
% fclose(fp3);
end
exp_phi_n(i) = 1.0;
exp_phi_p(i) = 1.0;
v_cell(i) = 0.0;
a(i-2) = 1;
b(i-1) = -v_cell(i+1) - v_cell(i-1) + 2*v_cell(i) -
(del_x*del_x)*ni(layers -1)*((exp_phi_p(i)/exp(v_cell(i))) -
(exp_phi_n(i)*exp(v_cell(i))));
d(i-1) = -(2.0 + (del_x*del_x)*ni(layers-
1)*((exp_phi_p(i)/exp(v_cell(i))) + (exp_phi_n(i)*exp(v_cell(i)))));
end
if (i==1)
c(i) = 1;
d(i) = -(2.0+
(del_x*del_x)*ni(1)*(((exp_phi_p(i)*exp(del_v(x1+1)))/exp(v_cell(i))) +
(exp_phi_n(i)*exp(v_cell(i))/exp(del_v(x1+1)))));
b(i) = -v_cell(i+1) - v_cell(i) + 2*v_cell(i) -
(del_x*del_x)*ni(1)*((exp_phi_p(i)*exp(del_v(x1+1))/exp(v_cell(i))) -
(exp_phi_n(i)*exp(v_cell(i))/exp(del_v(x1+1))));
end
for q1=1:(layers-1)
if i==cells_int(q1)
x1=q1+1;
end
end
if ((i~=1) & (i~=num_cells))
a(i-1) = 1;
c(i-1) = 1;
b(i-1) = -v_cell(i+1) - v_cell(i-1) + 2*v_cell(i-1) -
(del_x*del_x)*ni(x1)*((exp_phi_p(i-1)*exp(del_v(x1))/exp(v_cell(i-1))) -
(exp_phi_n(i-1)*exp(v_cell(i-1))/exp(del_v(x1))));
d(i-1) = -(2.0 + (del_x*del_x)*ni(x1)*(((exp_phi_p(i-
1)*exp(del_v(x1)))/exp(v_cell(i-1))) + (exp_phi_n(i-1)*exp(v_cell(i-
1))/exp(del_v(x1)))));
end
end
for i=1:(num_cells-1)
d(i) = d(i) - (a(i-1)/d(i-1))*c(i-1);
b(i) = b(i) - (a(i-1)/d(i-1))*b(i-1);
end
diff_v(num_cells-1) = (b(num_cells-2)/d(num_cells-2));
v_cell(num_cells-1) = v_cell(num_cells-1) +
rel_factor_v*diff_v(num_cells-1);
error = fabs(diff_v(num_cells-1));
for i=(num_cells-2):-1:0
diff_v(i) = (b(i-1) - c(i-1)*diff_v(i+1))/d(i-1);
v_cell(i) = v_cell(i) + rel_factor_v*diff_v(i);
if (fabs(diff_v(i)) > error)
error = fabs(diff_v(i));
end
end
end
end
for i=0:num_cells
E(i) = -(v_cell(i+1)-v_cell(i))/(del_x);
end
for i=0:num_cells
v_middle(i) = (v_cell(i)+v_cell(i+1))/2;
end
% temp1;
%temp2;
for i=0:num_cells
r1 =0;
if (i==0)
cp(0) = up(0)*ni(0)*exp(del_v(0))*(1/exp(v_middle(0)));
if (E(0)>0)
dp(0) = - ni(0)*exp(del_v(0))*spp*exp(-v_cell(0))*del_x - cp(0) -
del_x*gamma_rec*um(0)*ni(0)*ni(0)*exp_phi_n(0)/2;
bp(0) = - del_x*Jp0_cons*up(0)*exp(sqrt(fp));
end
else
dp(0) = - ni(0)*exp(del_v(0))*S0pp*exp(-v_cell(0))*del_x - cp(0) -
del_x*gamma_rec*um(0)*ni(0)*ni(0)*exp_phi_n(0)/2;
bp(0) = - del_x*Jp0_cons*up(0);
end
end
for y1=0:(layers-1)
if (i==(cells_int(y1)-1))
ap(i-1) = up(i+(y1-1))*ni(y1)*exp(del_v(y1))*(1/exp(v_middle(i-
1)));
bp(i) = 0;
cp(i) = del_x*(up(i+y1)*E(i)/kpoo(y1))*(bpoo(y1))*exp(-
v_cell(i+1));
dp(i) = - (up(i+y1)*E(i)/kpoo(y1))*apoo(y1)*exp(-v_cell(i))*del_x
- ap(i-1) - del_x*gamma*um(i+(y1-1))*ni(y1)*ni(y1)*exp_phi_n(i);
x=x+1;
r1=1;
end
if (i == cells_int(y1))
x=x-1;
ap(i-1) = (up(i+(y1-1))*E(i-1)/kpoo(y1))*apoo(y1)*exp(-v_cell(i-
1))*del_x;
bp(i) = 0;
cp(i) = up(i+y1+1)*ni(y1+1)*exp(del_v(y1+1))*(1/exp(v_middle(i)));
dp(i) = - del_x*(up(i+(y1-1))*E(i-1)/kpoo(y1))*bpoo(y1)*exp(-
v_cell(i)) - cp(i) - del_x*gamma*um(i+y1+1)*ni(y1+1)*ni(y1+1)*exp_phi_n(i);
r1 =1;
x=x+1;
end
end
if (i==num_cells)
ap(i-1) = up(num_cells+layers -2)*ni(layers -1)*(1/exp(v_middle(i-
1)));
if (E(i-1)<0)
bp(i) = - del_x*JpN_cons*up(num_cells+layers -2)*exp(sqrt(-fn));
dp(i) = - del_x*spn*ni(layers -1)*exp(-v_cell(i)) - ap(i-1) -
del_x*gamma_rec*um(num_cells+layers -2)*ni(layers -1)*ni(layers
-1)*exp_phi_n(i)/2;
end
else
bp(i) = - del_x*JpN_cons*up(num_cells+layers -2);
dp(i) = - del_x*S0pn*ni(layers -1)*exp(-v_cell(i)) - ap(i-1) -
del_x*gamma_rec*um(num_cells+layers -2)*ni(layers -1)*ni(layers
-1)*exp_phi_n(i)/2;
end
for i=1:num_cells
dp(i) = dp(i) - (ap(i-1)/dp(i-1))*cp(i-1);
bp(i) = bp(i) - (ap(i-1)/dp(i-1))*bp(i-1);
end
temp1 = bp(num_cells)/dp(num_cells);
temp2 = exp_phi_p(num_cells) + rel_factor_j*(temp1 - exp_phi_p(num_cells));
exp_phi_p(num_cells) = temp2;
for i=(num_cells-1):-1:0
temp1 = (bp(i) - cp(i)*exp_phi_p(i+1))/dp(i);
temp2 = exp_phi_p(i) + rel_factor_j*(temp1 - exp_phi_p(i));
exp_phi_p(i) = temp2;
end
end
function f5=solve_continuity_n( exp_phi_n, exp_phi_p, v_cell, E, un,
um )
x1=0;
r2=0;
% temp1;
% temp2;
for i=0:num_cells
v_middle(i) = (v_cell(i)+v_cell(i+1))/2;
end
for i=0:num_cells
r2 =0;
if (i==0)
cn(0) = un(0)*ni(0)*(1/exp(del_v(0)))*exp(v_middle(0));
if (E(0)>0)
dn(0) = - ni(0)*(1/exp(del_v(0))*S0np*exp(v_cell(0))*del_x) -
cn(0) - del_x*gamma_rec*um(0)*ni(0)*ni(0)*exp_phi_p(0)/2;
bn(0) = -del_x*Jn0_cons*un(0);
end
else
dn(0) = - ni(0)*(1/exp(del_v(0)))*snp*exp(v_cell(0))*del_x - cn(0)
- del_x*gamma_rec*um(0)*ni(0)*ni(0)*exp_phi_p(0)/2;
bn(0) = -del_x*Jn0_cons*un(0)*exp(sqrt(-fp));
end
end
for y2=0:(layers-1)
if (i==cells_int(y2)-1)
an(i-1) = un(i+(x1-1))*ni(y2)*(1/exp(del_v(y2)))*exp(v_middle(i-
1));
bn(i) = 0;
cn(i) =
del_x*(un(i+x1+1)*E(i)/knoo(y2))*anoo(y2)*exp(v_cell(i+1));
dn(i) = - (un(i+x1+1)*E(i)/knoo(y2))*bnoo(y2)*exp(v_cell(i))*del_x
- an(i-1) - del_x*gamma*um(i+(x1-1))*ni(y2)*ni(y2)*exp_phi_p(i);
r2 =1;
x1=x1+1;
end
if (i==cells_int(y2))
x1=x1-1;
an(i-1) = un(i+x1)*(E(i-1)/knoo(y2))*bnoo(y2)*exp(v_cell(i-
1))*del_x;
bn(i) = 0;
cn(i) = un(i+x1+1)*ni(y2+1)*exp(v_middle(i))*(1/exp(del_v(y2+1)));
dn(i) = - del_x*(un(i+x1)*E(i-1)/knoo(y2))*anoo(y2)*exp(v_cell(i))
- cn(i) - del_x*gamma*um(i+x1+1)*ni(y2+1)*ni(y2+1)*exp_phi_p(i);
r2=1;
x1=x1+1;
end
end
if (i==num_cells)
an(i-1) = un(num_cells+layers-2)*ni(layers -1)*exp(v_middle(i-1));
if (E(i-1)<0)
bn(i) = - del_x*JnN_cons*un(num_cells+layers -2);
dn(i) = - del_x*S0nn*ni(layers -1)*exp(v_cell(i)) - an(i-1) -
del_x*gamma_rec*um(num_cells+layers -2)*ni(layers -1)*ni(layers
-1)*exp_phi_p(i)/2;
end
else
bn(i) = - del_x*JnN_cons*un(num_cells+layers -2)*exp(sqrt(fn));
dn(i) = - del_x*snn*ni(layers -1)*exp(v_cell(i)) - an(i-1) -
del_x*gamma_rec*um(num_cells+layers -2)*ni(layers -1)*ni(layers
-1)*exp_phi_p(i)/2;
end
ii = 0;
for i=1:num_cells
ii = num_cells - i;
dn(ii) = dn(ii) - (cn(ii)/dn(ii+1))*an(ii);
bn(ii) = bn(ii) - (cn(ii)/dn(ii+1))*bn(ii+1);
end
temp1 = bn(0)/dn(0);
temp2 = exp_phi_n(0) + rel_factor_j*(temp1 - exp_phi_n(0));
exp_phi_n(0) = temp2;
for i=(num_cells-1):-1:0
ii = num_cells - i;
temp1 = (bn(ii) - an(ii-1)*exp_phi_n(ii-1))/dn(ii);
temp2 = exp_phi_n(ii) + rel_factor_j*(temp1 - exp_phi_n(ii));
exp_phi_n(ii) = temp2;
end
end
for h=0:(layers-1)
if (i==cells_int(h))
Jn(i) = (un(i+g)*E(i-
1)/knoo(h))*(anoo(h)*exp(v_cell(i))*exp_phi_n(i) - bnoo(h)*exp(v_cell(i-
1))*exp_phi_n(i-1));
Jp(i) = (up(i+g-1)*E(i-1)/kpoo(h))*(apoo(h)*exp(-v_cell(i-
1))*exp_phi_p(i-1)- bpoo(h)*exp(-v_cell(i))*exp_phi_p(i));
g=g+1;
r3=1;
end
end
if ((i~=0) & (i~=num_cells+1) & (r3==0))
Jn(i) = un(i+(g-1))*ni(g)*exp(v_middle(i-
1))*(1/exp(del_v(g)))*(exp_phi_n(i)-exp_phi_n(i-1))/del_x;
Jp(i) = -up(i+(g-1))*ni(g)*(1/exp(v_middle(i-
1)))*exp(del_v(g))*(exp_phi_p(i)-exp_phi_p(i-1))/del_x;
end
if (i~=0)
difference =difference + fabs(J(i)-temp7);
end
temp7 = J(i);
end
for i=0:num_cells
for p1=0:(layers-1)
if (i==cells_int(p1))
b=b+1;
end
end
n(i) = ni(b)*exp(v_cell(i))*(1/exp(del_v(b)))*exp_phi_n(i);
p(i) = ni(b)*exp(-v_cell(i))*exp(del_v(b))*exp_phi_p(i);
end
end
end