2 second order differential equation using ode45
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have 2 second order differential equation which I want to solve using Rung-Kutta method. I tried it and I am getting the answer. But I am not sure if how I write the code is right or wrong.
After converting the 2nd order equation to first, my four first order equations are,
x2 = x1 '
y2 = y1 '
A1*x2 ' +B1*y2 ' +C1*x2+D1*y2+E1*x1 +F1*y1 =0
A2*x2 ' +B2*y2 ' +C2*x2+D2*y2+F2*y1 =0
------------------------------------ I wrote this part as follows in MATLAB, This part comes under the function which ode45 solves.:
yp = zeros(4,1);
yp(1) = r(2);
yp(2) = -(1/A1)*(B1*yp(4)+C1*r(2)+D1*r(4)+E1*r(1)+F1*r(3));
yp(3) = r(4);
yp(4) =-(1/B2)*(A2*yp(2)+C2*r(2)+D2*r(4)+F2*r(3));
Is this feasible?
Thankyou..
0 comentarios
Respuestas (1)
Mischa Kim
el 5 de Feb. de 2014
Editada: Mischa Kim
el 5 de Feb. de 2014
Vin, you are close. In the last two equations solve for x2' and y2' (so you end up with two equations containing only one or the other term).
For easier debugging and to speed up your code I recommend extracting the states from the state vector (I am calling it X) before computing Xp.
function Xp = my_ODE(t, X)
x1 = X(1);
x2 = X(2);
y1 = X(3);
y2 = X(4);
Xp = zeros(4,1);
Xp = [ x2; ...
[term for x2']; ...
y2; ...
[term for y2'] ];
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!