1
$\begingroup$

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]

$\endgroup$

1 Answer 1

3
$\begingroup$

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!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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