How does matlab solve a pair of coupled differential equations?
조회 수: 5 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
채택된 답변
Steven Lord
2017년 8월 15일
"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.
추가 답변 (1개)
Torsten
2017년 8월 15일
Correct solution is
N_ex(t) = 1000*exp(-t/T_th)
N_cb(t) = 1000*(1-exp(-t/T_th))
Best wishes
Torsten.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Computations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!