필터 지우기
필터 지우기

Help needed for below error

조회 수: 1 (최근 30일)
Amy Topaz
Amy Topaz 2022년 3월 16일
댓글: Rik 2022년 3월 29일
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
  댓글 수: 3
Amy Topaz
Amy Topaz 2022년 3월 16일
Sorry about that, I have modified it. I didn't mean in that sense.
Rik
Rik 2022년 3월 29일
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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2022년 3월 16일
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 .
  댓글 수: 6
Walter Roberson
Walter Roberson 2022년 3월 16일
fzero can only deal with a single variable, not a vector of variables, so it would be an error to use fzero with that x2.
Amy Topaz
Amy Topaz 2022년 3월 16일
okay, so how shall I proceed?

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2022년 3월 16일
Since it seems that you only solve for a single unknown, change
x2 = [0 1.73];
to
x2 = 1.73;
Then your code should be
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;

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by