Does anybody know if Mathematica has an analogue of MATLAB's ode45 command? I need to solve a second order coupled ODE system of equations.
Asked
Active
Viewed 3,162 times
5
2 Answers
18
According to the Mathematica documentation on this page:
Here is how to define a 5(4) pair of Dormand and Prince coefficients [DP80]. This is currently the method used by
ode45in MATLAB.DOPRIamat = { {1/5}, {3/40, 9/40}, {44/45, -56/15, 32/9}, {19372/6561, -25360/2187, 64448/6561, -212/729}, {9017/3168, -355/33, 46732/5247, 49/176, -5103/18656}, {35/384, 0, 500/1113, 125/192, -2187/6784, 11/84}}; DOPRIbvec = {35/384, 0, 500/1113, 125/192, -2187/6784, 11/84, 0}; DOPRIcvec = {1/5, 3/10, 4/5, 8/9, 1, 1}; DOPRIevec = {71/57600, 0, -71/16695, 71/1920, -17253/339200, 22/525, -1/40}; DOPRICoefficients[5, p_] := N[{DOPRIamat, DOPRIbvec, DOPRIcvec, DOPRIevec}, p];
Then:
NDSolve[system,
Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 5,
"Coefficients" -> DOPRICoefficients, "StiffnessTest" -> False}]
where
system
is the second order ODE specified in the usual Mathematica manner for ODE's.
J. M.'s missing motivation
- 124,525
- 11
- 401
- 574
Eric Brown
- 4,406
- 1
- 18
- 36
-
The simple NDSolve solves the ODE's i am using but it returns an interpolationg function. Whereas I want the function itself so that I can make further changes to it. How should I get the function from the interpolating function. – Pawan Jun 19 '13 at 16:07
-
5@user4402 -- Matlab's ODE45 returns a vector of values and the times at which those values occur. If you wish to duplicate this output, you can simply evaluate the interpolating function at the points you wish. For example, with
fIntthe interpolating function,Table[fInt[x],{x,0,10,0.1}]will return the values at the points 0, 0.1, 0.2, ... 10. – bill s Jun 19 '13 at 17:21 -
1
4
Check the documentation centre right here: LINK
And a simple example (modelling coupled springs with added nonlinear restoring forces (for large vibrations)):
eqn = {x''[t] ==
0.4 x[t] + -1/6 x[t]^3 - 1.808 (x[t] - y[t]) -
1/10 (x[t] - y[t])^3,
y''[t] == -1.808 (y[t] - x[t]) - 1/10 (y[t] - x[t])^3,
x[0] == -0.6, x'[0] == 1/2, y[0] == 3.001, y'[0] == 5.9};
sol = NDSolve[eqn, {x, y}, {t, 0, 200}]
ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 200}]
![x[t] vs y[t] Plot](../../images/e0102ee5442cf7229c4de74668628150.webp)
ParametricPlot[Evaluate[{x[t], x'[t]} /. sol], {t, 0, 200}]
![x[t] vs x'[t] Phase Plot](../../images/871923cba72955fd87f77f43e34439cd.webp)
ParametricPlot[Evaluate[{y[t], y'[t]} /. sol], {t, 0, 200}]
![y[t] vs y'[t] Phase Plot](../../images/02105b647c4ee827198d06cb58e51abc.webp)
Sektor
- 3,320
- 7
- 27
- 36
-
This is nice, but is it a coupled second-order system? I think that would be more helpful to the original poster. – Verbeia Jun 18 '13 at 23:23
-
-
NDSolvereturn for your specific system of ODEs? – Jun 19 '13 at 07:11