Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
how corrige an error in the program using vpasolve
조회 수: 1 (최근 30일)
이전 댓글 표시
i write this code to resolve two non linear equation ,but there are an error which i can't corrige it to obtain the last graph who can help me thank you in advance .
%% defining constants
sigma = 30*10^-3;%eV
deltaE = -73e-3;%eV
E0 = 1.26;%eV Ea = E0+16e-3; tautr=0.022 ; taur=800; ; Kb = 8.617*10^-5;%eV/K theta = 270; %K alfa = 0.00048;%eV/K T = 0:10:300;
X=zeros(size(T)); E1=zeros(size(T)); E2 = zeros(size(T));
%% resoudre l'equation et trouver x syms x
for i=1:numel(T)
E1(i) = E0 -( alfa*T(i)^2)/(theta+T(i));
X(i) = vpasolve(((sigma/(Kb*T(i)))^2-x)*(taur/tautr)*exp(deltaE/(Kb*T(i)))-x*exp(x)==0,x);
E2(i) = E0 -(alfa*T(i)^2)/(theta + T(i))-X(i)*Kb*T(i);
a(i)=X(i)*Kb*T(i);
end
%% resoudre l'equation et trouver X1
x1 = zeros(size(T)); a = zeros(size(T)); b = zeros(size(T)); c = zeros(size(T)); d = zeros(size(T));
h=2*(sigma)^2;
for i=1:numel(T) a(i)=X(i)*Kb*T(i); b(i)=exp((-a(i)^2)/(2*(sigma)^2)); c(i)=exp((E0-a(i)-Ea)/(Kb*T(i)))+(tautr/taur); d(i)=0.5*(b(i)/c(i)); end syms x1
for i=1:numel(T)
X1(i)= vpasolve((exp((x1-E0)^2/h))/(exp((x1-Ea)/(Kb*T(i))) + (tautr/taur))- d(i)==0,x1);
end %%
figure(1) plot(T,E1,'r.') title('E1')
figure(2) plot(T,E2,'b') title('E2') hold on plot(T,E1,'r') hold on;
figure(3) plot(T,X,'k.','Markersize',15) title('X');
figure (4) plot(T,a,'k');
figure(5) plot(T,X1,'g'); the error is
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193790/image.png)
댓글 수: 2
Walter Roberson
2018년 8월 14일
You could get that error if the vpasolve was not able to find a solution. It would return empty in that case. You should assign the output to a temporary variable and then check the results and store something like nan if there was no result.
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!