How does matlab solve a pair of coupled differential equations?

5 vues (au cours des 30 derniers jours)
William Royle
William Royle le 15 Août 2017
Commenté : William Royle le 15 Août 2017
I'm trying to solve a pair of coupled differential equations following the Matlab article in:
https://uk.mathworks.com/help/symbolic/solve-a-system-of-differential-equations.html
When trying to use this example to solve my own equations the code runs but the diff function gives a different function to what I was expecting. I was expecting to get an equation of the form N(t) = N_{0}exp(-t/T). Instead I get N(t) = A - A*exp(-t/T), where A is constant defined by the boundary conditions. This is giving me the wrong time dependence of N(t).
Why am I getting the incorrect solution? Is there something wrong with my code or is there a problem with one of the Matlab functions?
Thanks
Simplified code below.
% Define lifetime variables
T_th = 10e-11;
% set up problems, represent u and v with symbolic functions
syms N_ex(t) N_cb(t)
% set up the differential equations.
A = [ -1/T_th 0 ;
1/T_th 0 ];
B = [N_ex ; N_cb];
ordinary_diff_eqns = diff(B) == A*B
% apply the initial conditions
Initial_conds = B(0) == [1000 ; 0]
% solve the differential equations
[N_exSol(t), N_cbSol(t)] = dsolve(ordinary_diff_eqns, Initial_conds)
%Plot the solutions to see the time dependence.
clf
hold on
fplot(N_exSol)
xlim([0,10e-9])
ylim([0,1000])
xlabel('Time')
ylabel('Population')
fplot(N_cbSol)

Réponse acceptée

Steven Lord
Steven Lord le 15 Août 2017
"When solving for multiple functions, dsolve returns a structure by default. Alternatively, you can directly assign solutions to functions or variables by specifying the outputs explicitly as a vector. dsolve sorts outputs in alphabetical order using symvar."
dsolve returns the correct solutions, just not in the order you expect. Call dsolve with one output and extract the appropriate fields of the struct array to view/use the solutions.

Plus de réponses (1)

Torsten
Torsten le 15 Août 2017
Correct solution is
N_ex(t) = 1000*exp(-t/T_th)
N_cb(t) = 1000*(1-exp(-t/T_th))
Best wishes
Torsten.
  1 commentaire
William Royle
William Royle le 15 Août 2017
But Matlab gives me
N_ex(t) = 1000*(1-exp(-t/T_th))
and
N_cb(t) = 1000*exp(-t/T_th)
Thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Computations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by