0
$\begingroup$

I would like to find the derivatives of a function U[x,y,t] occurring in an expression X. I use

DeleteDuplicates[Cases[X, Derivative[__][U][__], Infinity]].

An output would be something like this:

{Derivative[1, 0, 0][U][x, y, t], 
 Derivative[0, 1, 0][U][x, y, t], 
 Derivative[0, 2, 0][U][x, y, t], 
 Derivative[1, 1, 0][U][x, y, t], 
 Derivative[2, 0, 0][U][x, y, t], 
 Derivative[0, 1, 1][U][x, y, t], 
 Derivative[1, 0, 1][U][x, y, t], 
 Derivative[0, 0, 1][U][x, y, t],
 Derivative[1, 1, 1][U][x, y, t], 
 Derivative[0, 2, 1][U][x, y, t]}

However, if I want to find a particular nth derivative of U, say 3rd derivative, in the expression to get the following:

 {Derivative[1, 1, 1][U][x, y, t], 
 Derivative[0, 2, 1][U][x, y, t]}

how would I achieve that?

$\endgroup$
4
  • $\begingroup$ do you have a specific example of an input? $\endgroup$
    – Nasser
    Jun 16, 2020 at 17:16
  • $\begingroup$ I have added more details. $\endgroup$
    – Bran
    Jun 16, 2020 at 17:26
  • $\begingroup$ I meant an example of the PDE itself, you want to find those patterns in, so to be clear. i.e. the PDE which to apply the pattern on. I can then show how to do it on the PDE. This way there is no confusion. It is what you call the expression X $\endgroup$
    – Nasser
    Jun 16, 2020 at 17:31
  • $\begingroup$ X can be any PDE, even a system of PDEs, not necessarily linear. Using the above function will result something like the output provided. $\endgroup$
    – Bran
    Jun 16, 2020 at 17:34

2 Answers 2

2
$\begingroup$

You need to specialise your pattern:

DeleteDuplicates[Cases[X, Derivative[i__][U][__]/;Plus[i]==3, -1]]
$\endgroup$
0
1
$\begingroup$

X can be any PDE, even a system of PDEs, not necessarily linear.

getPatterns[expr_, pat_] := 
  Last@Reap[expr /. a : pat :> Sow[a], _, Sequence @@ #2 &];

pde = Derivative[1, 1, 1][U][x, y, t] + 
   Derivative[0, 2, 1][U][x, y, t]^3 + 
   Derivative[0, 1, 1][U][x, y, t] + Sin[x] + F'[x] + 
   Derivative[3, 0, 0][U][x, y, t] + Derivative[2, 1, 0][U][x, y, t];

getPatterns[pde, 
 Derivative[x0_, y0_, t0_][U][_, _, _] /; x0 + y0 + t0 == 3]

Mathematica graphics

Function getPatterns is thanks to Carl Woll.

$\endgroup$

Your Answer

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

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