I want to reduce a n-order ordinary differential equation into a first order system of equations. This is in preparation for numerical analysis. I use both Sympy and Sagemath for Computer Algebra, but I have not found any functions in them to do this type of reduction. I was not sure if anyone else could indicate whether this functionality exists within either Sympy or Sagemath.

An example of this would be reducing the equation:

$$ x''' - 2x'' + x' = 0 $$

to a system of first order equations $y'(t) = Ay$ with

$$ A = \begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & -1 & 2 \end{pmatrix}. $$


closed as off-topic by Ricardo Andrade, abx, Andrey Rekalo, Stefan Kohl, Chris Godsil Sep 23 '14 at 1:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about research level mathematics within the scope defined in the help center." – Ricardo Andrade, abx, Andrey Rekalo, Stefan Kohl, Chris Godsil
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ You might want to specify what kind of ODEs you are interested in. In general, the ODE $f^{(n)}(t)=F(f^{(n-1)}(t),\dots,f^{(0)}(t),t)$ can be reduced to $\dot x_n=F(x_{n-1},\dots,x_0,t)$ and $\dot x_k=x_{k+1}$ for $k\in\{0,\dots,n-1\}$ by letting $x_k(t)=f^{(k)}(t)$. Depending on how the original ODE is given, implementing this could be simple. $\endgroup$ – Joonas Ilmavirta Aug 31 '14 at 9:43
  • $\begingroup$ @JoonasIlmavirta Yes Joonas, you are correct. This is exactly the reduction that I want to do. I was just wondering whether Sage or Sympy or similar system can do this reduction. As the number of equations in the system gets larger, I just want a say to check my own algebra. $\endgroup$ – krishnab Aug 31 '14 at 9:59
  • $\begingroup$ Questions about the use of software are not normally appropriate on this site. $\endgroup$ – Chris Godsil Sep 23 '14 at 1:02

You want companion_matrix(poly, format='bottom'), where poly=[0,1,-2,1] are the coefficients for the derivatives of $x$, starting from the $0$th derivative (function value). You can use a polynomial (that is, the member of a polynomial ring, but not a symbolic expression) as the parameter poly. Depending on how you store your equation, some conversion or input massaging could be needed; I am not aware of a pre-canned method to extract the characteristic polynomial of a linear ODE.

The matrix that represent this linearization is, indeed, called (Frobenius) companion matrix. Several variants of it exist, depending on the order that you choose for the monomial basis and the transposedness of your vector.


Not the answer you're looking for? Browse other questions tagged or ask your own question.