Special case of ODE45 for coupled 2nd order differential equations
1 view (last 30 days)
Show older comments
Hello all,
I would like to solve the following coupled 2nd order equations using ODE45:
y'=2y-z
z'+y''=4y-2z
where y and z are functions of x. The analytic solution for this problem is know, and it is just summing of some exponents. However, this is a simplification of the problem I'm trying to solve which is basically nonlinear. The original problem here is not relevant.
Following previous threads on the same manner, I tried to use 3 variables convention namely y, y', and z on ODE45. However, this method cannot work in this case since z'+y'' will be inseparable. Is there a way that MATLAB can solve it?
Thnx, Tal.
0 Comments
Answers (1)
Yu Jiang
on 11 Aug 2014
Edited: Yu Jiang
on 11 Aug 2014
Hi Tal
From what I understand, you would like to simulation the system
y'=2y-z
z'+y''=4y-2z
using ODE45. Also, you are facing an issue that the term z'+y'' is not separable.
In fact, there are only two independent variables in this system. This can be seen if you perform the following steps on the first equation
1) Rearrange it as y'+z=2y
2) Take the derivative of the above equation, and obtain y''+z'=2y'
3) Substitute y' = 2y - z in the above equation, and the resultant equation is the same as the second equation in your original system.
Therefore, to simulate the system, you only need the first equation
|y' = 2y -z |
However, since z is not dependent on y, it has to be manually defined in other ways. Once you have z as function of x, or can define z' as a function of y or y', MATLAB should be able to solve the system for you. Notice at this point that the equation should be independent from the first equation in your system.
For example, if z=sin(x), you can create the following MATLAB function
function dy = mySys(x,y) z = sin(x); dy = 2*y - z; end
Then, in the MATLAB command line, or in a MATLAB file, you may try the following command
[x,y] = ode45(@mySys, [0,1], 1)
figure(1);
plot(x,y);
xlabel('x');
ylabel('y');
This will give you the trajectory of y. More details regarding the function ode45 can be found here http://www.mathworks.com/help/matlab/ref/ode45.html
-Yu
0 Comments
See Also
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!