MATLAB: Problem in simulating if condition

if condition

When I am trying to simulate , it is only taking one codition. The other condition it is not taking.
gd=2;
Ecd=0.045;
k=8.617e-5;
ni=1e10;
T=linspace(0,600,100);
mee=0.553*9.11e-31;
meh=0.357*9.11e-31;
Nc=((2.510e19)*((0.553)^1.5).*((T/300).^1.5));
Nv=((2.510e19)*((0.357)^1.5).*((T/300).^1.5));
display(Nc)
display(Nv)
Nj=(Nc/gd).*(exp(-Ecd./(k.*T)));
display(Nj)
Nd=1e15;
Eg0=0.7437;
a=4.77e-4;
b=235;
Eg=Eg0-((a*(T.^2))./(T+b));
display(Eg)
ni=((sqrt(Nc.*Nv)).*(exp((-Eg)./(2*k.*T))));
if (T>300)
n=(Nd/2)+(sqrt(((Nd/2)^2)+(ni.^2)));
else
n=((Nj/2).*((sqrt(1+((4*Nd)./(Nj))))-1));
end
plot(T,n/Nd,'g','linewidth',2)
plot(T, ni/Nd,'–r','linewidth',2)
grid on
xlabel('Temperature in K')
ylabel('n/Nd')
title('Temp. dependence of Majority Carrier Concentration')
set(gca,'ylim',[0 3],'xlim', [0 610])

Best Answer

You can replace your if statement with
% Assuming there are 100 steps in T
nhi=(Nd/2)+(sqrt(((Nd/2)^2)+(ni(51:100).^2)));
nlo=((Nj(1:50)/2).*((sqrt(1+((4*Nd)./(Nj(1:50)))))-1));
n = [nlo, nhi];
Also replace
plot(T,n/Nd,'g','linewidth',2)
plot(T, ni/Nd,'--r','linewidth',2)
with
plot(T,n/Nd,'g','linewidth',2)
hold on
plot(T, ni/Nd,'--r','linewidth',2)
if you want both curves on the same plot.
The following is the result