# Help needed for below error

1 view (last 30 days)
Amy Topaz on 16 Mar 2022
Commented: Rik on 29 Mar 2022
Kindly help with the below error for the below mentioned code. All other values are constant scale1 = 100;
T1 = linspace(10, 2000, scale1);
Ta = rdivide(1,T1);
ND1 = 1e17;
NA1 = 1e5;
%Computing n and p values to be plotted
hole1 = ones(scale1,1)*0;
Eflevel1 = ones(scale1,1)*0;
electron1 = ones(scale1,1)*0;
NC1 = 2*Mc*(((mde*kb*T1(1:100))/(2*pi*(hbar^2))).^(3/2));
NV1 = 2*(((mdh*kb*T1(1:100))/(2*pi*(hbar^2))).^(3/2));
kbT1 = (kb*T1(1:100))/e;
ev1 = 0;
ea1 = ev1 + Eai;
eg1 = 1.17 - (4.73e-4*((T1(1:100)).^2))./(T1(1:100) + 636);
ec1 = eg1;
ed1 = ec1 + Edi;
x2 = [0 1.73];
for range1 = 1:prod(size(T1))
eq2 = @(EF1) ((NC1(range1))*exp(-(ec1(range1)-EF1)/kbT1(range1))) + ((NA1)/(1+4*exp(-(EF1-ea1(range1))/kbT1(range1)))) - (((NV1(range1))*exp(-(EF1-ev1(range1))/kbT1(range1))) + ((ND1)/(1+2*exp(-(ed1(range1)-EF1)/kbT1(range1)))));
Eflevel1(range1) = fsolve(eq2, x2);
y1 = Eflevel1(range1);
x2 = y1.';
s11 = Eflevel1(:,1,:);
electron1(range1) = (NC1(range1))*exp(-(ec1(range1)-Eflevel1(range1))/(kbT1(range1)));
s12 = electron1(:,1,:);
hole1(range1) = (NV1(range1))*exp(-(Eflevel1(range1)-ev1(range1))/(kbT1(range1)));
s13 = hole1(:,1,:);
end
Rik on 29 Mar 2022
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
The page has now been archived.

Walter Roberson on 16 Mar 2022
x2 = [0 1.73];
row vector
Eflevel1(range1) = fsolve(eq2, x2);
vector is used as the example parameters for fsolve, so eq2 is going to be passed something the same length as x2.
eq2 = @(EF1) ((NC1(range1))*exp(-(ec1(range1)-EF1)/kbT1(range1))) + ((NA1)/(1+4*exp(-(EF1-ea1(range1))/kbT1(range1)))) - (((NV1(range1))*exp(-(EF1-ev1(range1))/kbT1(range1))) + ((ND1)/(1+2*exp(-(ed1(range1)-EF1)/kbT1(range1)))));
That vector becomes EF1 on input. You use that vector EF1 in several places, including in
/(1+4*exp(-(EF1-ea1(range1))/kbT1(range1)))
so the right hand side of the / is a row vector.
But remember that the / operator is matrix-right-divide, mrdivide, with A/B being similar to A*pinv(B) except with some size constraints. And the size constraints are such that row vector / row vector is not permitted .
Amy Topaz on 16 Mar 2022
okay, so how shall I proceed?

Torsten on 16 Mar 2022
Since it seems that you only solve for a single unknown, change
x2 = [0 1.73];
to
x2 = 1.73;
for range1 = 1:prod(size(T1))
eq2 = @(EF1) NC1(range1)*exp(-(ec1(range1)-EF1)/kbT1(range1)) + NA1/(1+4*exp(-(EF1-ea1(range1))/kbT1(range1))) - (NV1(range1)*exp(-(EF1-ev1(range1))/kbT1(range1)) + (ND1/(1+2*exp(-(ed1(range1)-EF1)/kbT1(range1)))));
Eflevel1(range1) = fsolve(eq2, x2);
x2 = Eflevel1(range1);
end
y1 = Eflevel1;
x2 = y1.';
s11 = Eflevel1;
electron1 = NC1.*exp(-(ec1-Eflevel1)./kbT1);
s12 = electron1;
hole1= NV1.*exp(-(Eflevel1-ev1)./kbT1);
s13 = hole1;