# Find Order of a Differential Equation (ODE or PDE)

In Mathematica, I need a code in order to find the order of ODEs and PDEs.

Here are some examples using different notations:

• For fifth-order ODE:

D[u[t], {t,5}]-D[u[t], {t,3}] u[t] +D[u[t],t] +Cot[t]==0

• For Second-order PDE:

D[u[x,t], x] + u[x,t] +D[u[x,t], x,t] - Sin[t]==0

• For Third-order PDE using Derivative :

 Derivative[1, 1, 1 ][f][x, y, t ] == Exp[x y t]

Try the following function:

    Clear[findOrder];

findOrder[equation_] := Module[{pos},
pos = Position[equation, Derivative[n___][_][___]];
Map[Total,
equation[[Sequence @@ #]] & /@ pos /.
Derivative[n__][x_][y___] -> {n}] // Max
]


Let us try it on your equations:

eq1 = D[u[t], {t, 5}] - D[u[t], {t, 3}] u[t] + D[u[t], t] + Cot[t] == 0
findOrder[eq]

(*  5  *)


Then

    eq2 = D[u[x, t], x] + u[x, t] + D[u[x, t], x, t] - Sin[t] == 0
findOrder[eq2]

(* 2 *)


and

eq3 = Derivative[1, 1, 1][f][x, y, t] == Exp[x y t]
findOrder[eq3]

(*  3  *)


Have fun!

• It should be: findOrder[eq1] :) Sep 27, 2021 at 16:27
• @Mariusz Iwaniuk Yes, you are right, of course. I initially named it eq, and later changed it to eq1 to make coherent notations. Sep 27, 2021 at 17:44