Question about using ODE45 to solve a system of linear first order DE's using "initial" conditions specified at a later time
Show older comments
Hi,
I have a system of three linear ordinary differential equations that I am trying to solve in MATLAB. I understand that MATLAB's 'dsolve' function only analytically solves a system of ODEs and thus, the use of a function like ODE45 in required in order to numerically solve a system of ODE's.
My system of equations are:
s = 2; g = 5/3;
eqn1 = '(U - t)*t*DM + (t*DU + s*U)*M = 0';
eqn2 = '-1.5*M*U + (U - t)*M*DU + DP = 0';
eqn3 = '-3*M*P + (U - t)*M*DP - g*P*DM = 0';
where DU is the first derivative of U w.r.t. time and etc. for the other derivatives. I used 'solve' to solve these three equations for DU, DM, and DP in terms of the other variables and obtained the following:
DU = (- 3*M*U^2*t + 3*M*U*t^2 - 2*P*g*s*U + 6*P*t)/(2*t*(- M*U^2 + 2*M*U*t - M*t^2 + P*g));
DM = -(M*(6*P*t - 2*M*U^3*s + 3*M*U*t^2 - 3*M*U^2*t - 2*M*U*s*t^2 + 4*M*U^2*s*t))/(2*t*(U - t)*(- M*U^2 + 2*M*U*t - M*t^2 + P*g));
DP = (M*(6*P*t^2 - 6*P*U*t + 2*P*U^2*g*s + 3*P*U*g*t - 2*P*U*g*s*t))/(2*t*(- M*U^2 + 2*M*U*t - M*t^2 + P*g));
Now, as far as I understand the ODE45 function after looking in the help section, the commands should be:
[t,y] = ode45(@myodefun,[0:1],[Condition1 Condition2 Condition3],[],g,s);
function yp = myodefun(t,y,g,s)
U = y(1);
M = y(2);
P = y(3);
DU = (- 3*M*U^2*t + 3*M*U*t^2 - 2*P*g*s*U + 6*P*t)/(2*t*(- M*U^2 + 2*M*U*t - M*t^2 + P*g));
DM = -(M*(6*P*t - 2*M*U^3*s + 3*M*U*t^2 - 3*M*U^2*t - 2*M*U*s*t^2 + 4*M*U^2*s*t))/(2*t*(U - t)*(- M*U^2 + 2*M*U*t - M*t^2 + P*g));
DP = (M*(6*P*t^2 - 6*P*U*t + 2*P*U^2*g*s + 3*P*U*g*t - 2*P*U*g*s*t))/(2*t*(- M*U^2 + 2*M*U*t - M*t^2 + P*g));
yp = [DU;DM;DP];
This code executes properly, but the results are not correct. I think the issue might be because, instead of initial conditions (Conditions1, Conditions2, Conditions3), I have conditions at a later time. Is there a way to pass on conditions at a later time to ODE45 instead of the initial conditions?
If this is not possible, does anyone know of how I can numerically solve a system of first order linear DE's in MATLAB with conditions specified at a later time? Btw, I am using MATLAB 2010 with the symbolic toolbox.
Thanks everyone!
2 Comments
Jan
on 17 Feb 2013
RahulTandon
on 10 Jul 2015
Edited: RahulTandon
on 10 Jul 2015
An explicit solution to your differential equations cannot be found! I have solved to a certain extent Had i got an explicit solution, believe me, the rest is simple!
Check the point where i have stopped!
clc; s = 2; g = 5/3; eqn1 = '(U - t)*t*DM + (t*DU + s*U)*M = 0'; eqn2 = '-1.5*M*U + (U - t)*M*DU + DP = 0'; eqn3 = '-3*M*P + (U - t)*M*DP - g*P*DM = 0';
[DU,DP,DM] = solve(eqn1,eqn2,eqn3);
[U,M,P] = dsolve(['DU == ' char(DU)],['DM == ' char(DM)],['DP == ' char(DP)],'t')
Answers (1)
James Tursa
on 10 Jul 2015
0 votes
Call ode45 twice. Run it once to integrate backwards in time to the "initial" time you want. Then run it again to integrate forwards in time to your desired "end" time. Then piece the two solutions together.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!