Having problem with the ode45 solver

4 ビュー (過去 30 日間)
Giacomo Gloria
Giacomo Gloria 2017 年 2 月 9 日
回答済み: John D'Errico 2017 年 2 月 9 日
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

採用された回答

John D'Errico
John D'Errico 2017 年 2 月 9 日
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 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by