Having problem with the ode45 solver
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Giacomo Gloria
el 9 de Feb. de 2017
Respondida: John D'Errico
el 9 de Feb. de 2017
I'm trying to solve rate equations for a fabry-perot laser using ode45 solver, but I'm having issues. I'm basically new to solving this kind of problems using ode, so Im not sure if it is just me doing something wrong. I've tried different builds with pretty much the same output, the solver appears to get stuck somewhere (or maybe it just takes a looong time to handle it). The easier to read version should be this one:
%constants
c=2.99*10^5; %m/s
beta=10^-6;
d=5*10^-6; %m
tau_rr=100*10^-9; %s
tau_tot=tau_rr+10^-3; %s
L=500*10^-6; %m
R1=0.33;
R2=0.33;
J=28*10^3; %KA/cm^2
e=1.602*10^-19;
n_tilde=3.6;
gamma=10; %cm^-1
nt=10^18; %cm^-3
a=10^17; %cm
p=1;
% Initial Condition
N0=10;
n0=10^3;
gth=gamma+(1/(2*L))*log(1/(R1*R2))
tau_ph=(c/n_tilde)*(gamma+((1/(2*L))*log(1/(R1*R2))));
f = @(t,x) [(c/n_tilde)*a*(x(2)-nt)*x(1)+(x(2)*beta/tau_rr)-x(1)/tau_ph;-(c/n_tilde)*a*(x(2)-nt)*x(1)-x(2)/tau_tot+J/(e*d)];
[t,xa] = ode45(f,[0 p],[N0 n0]);
As I said it appears to get stuck, is it something I messed up in the code itself or I'm doing something wrong in the approach I'm taking? Thanks everyone for your help
0 comentarios
Respuesta aceptada
John D'Errico
el 9 de Feb. de 2017
Problems with large variations in coefficients are often described as stiff. You can think of it as a problem with several things happening, but with very rapid transients compared to the other components.
Those problems tend to cause ODE45 to stall. It will try to make the time step EXTREMELY small, since ODE45 is an adaptive solver. But when the time step goes essentially to zero, and still no success, guess what happens? So when I see a problem that someone says has stalled, AND it has large variations in coefficients, the odds are good that it is stiff.
The easiest test of this assertion is to use a stiff solver instead. So use one of the ODE suite of tools that ends in an s instead of ODE45.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!