Code keeps running and running and not stopping
Mostrar comentarios más antiguos
I have code I am trying to run and when I try to get the value for V_max, the code won't stop running. I don't get an error and it will run for hours if I let it. I have asked my TA for my class as well as several classmates and none of them can figure out what is wrong either.
h=4.136e-15;%eVs
k=8.617e-5;%eV/k
c=3e8;
theta_s=0.00467;%radians
T_c=300;
q=1.6e-19;
syms E;
%PROBLEM 1
%a
T_s=5760;
a=q*(pi/2)*(1-cos(2*theta_s))*(2/((h^3)*(c^2)));
fun1= ((E.^3)./((exp(E/(k*T_s)))-1));
Pin= a*(int(fun1,0,inf));%input power
Intensity=double(Pin); %W/m^2
%Intensity= 1.3570e3 W/m^2, this is almost the exact number for the actual
%power,which is 1350 W/m^2, just over by 7
%b
E_g=1.43;%eV
fun2= (E.^2)./((exp(E/(k*T_s))-1));
J_l= a*int(fun2,E_g,inf);%light generated current density
%c
theta_e=pi/2;
b=q*(pi/2)*(1-cos(2*theta_e))*(2/(h^3)*(c^2));
fun3= (E.^2)./(exp(E/(k*T_c))-1);
J_0= b*int(fun3,E_g,inf);%reverse saturation current density
%d
syms V;
P= V*(J_l + J_0*(exp((q*V)/(k*T_c))-1));
V_max=double(solve(P,V));
J_max= (J_l + J_0*(exp((q*V)/(k*T_c))-1));
V_max is the part of the code that is giving me problems and I can't figure out what is wrong. Please help me. Thank you!
8 comentarios
Rik
el 24 de Oct. de 2017
I don't have much experience with the solve function, but I would have thought it would time out after a while, if it is a too complicated formula.
Savanna
el 24 de Oct. de 2017
Walter Roberson
el 24 de Oct. de 2017
solve() has no timeout.
Savanna
el 24 de Oct. de 2017
Walter Roberson
el 24 de Oct. de 2017
Editada: Walter Roberson
el 24 de Oct. de 2017
You cannot: your formulae generate infinities.
Walter Roberson
el 24 de Oct. de 2017
... though I am finding hints that the infinities might be false constructs... checking more...
Savanna
el 24 de Oct. de 2017
Walter Roberson
el 25 de Oct. de 2017
I have determined that fun2 and fun3 do have closed-form integrals in the form specified, but I am still working on characterizing them.
Respuestas (1)
Walter Roberson
el 24 de Oct. de 2017
1 voto
Your J_l and J_0 both have limit() operations that look to me as if they suggest non-convergence. Trying to solve() under those conditions is going to be a failure.
Maple says that the integral of fun2 and fun3 are complex infinity; when I prod it a different way, it says the limit as E approaches infinity is undefined, as it starts to involve negative infinity plus infinity.
You should recheck your formula.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!