1
$\begingroup$

I have a long expression, only representative terms are given below. As a first step, I want to collect terms in terms of u[x,t] and its derivatives. The second step is to make those coefficients equal to zero as separate equations. For example, if I have the expression:

xpr=a[x, t, u]*Derivative[1, 0][u][x, t] + 2*Derivative[0, 1][u][x, t]*
Derivative[1, 0][u][x, t]*Derivative[0, 0, 1][b][x, t, u] + 
2*u[x, t]*Derivative[1, 0][u][x, t]^2*Derivative[0, 0, 1][b][x, t, u] + 
 2*Derivative[1, 0][u][x, t]*Derivative[1, 1][u][x, t]*Derivative[0, 0, 1][c][x, t, u]+2*Derivative[0, 1][u][x, t]*
Derivative[1, 0][u][x, t]*Derivative[0, 0, 1][d][x, t, u];

The first step should result in:

stp1=a[x, t, u]*Derivative[1, 0][u][x, t] + 2*u[x, t]*Derivative[1, 0][u][x, t]^2*
Derivative[0, 0, 1][b][x, t, u] + 2*Derivative[1, 0][u][x, t]*
 Derivative[1, 1][u][x, t]*Derivative[0, 0, 1][c][x, t, u] + 
Derivative[0, 1][u][x, t]*Derivative[1, 0][u][x, t]*
 (2*Derivative[0, 0, 1][b][x, t, u] + 2*Derivative[0, 0, 1][d][x, t, u])

The last step will give rise to:

 eqns={a[x, t, u] == 0, 2*Derivative[0, 0, 1][b][x, t, u] == 0, 
  2*Derivative[0, 0, 1][c][x, t, u] == 0, 
  2*Derivative[0, 0, 1][b][x, t, u] + 2*Derivative[0, 0, 1][d][x, t, u] == 0},

Your help is much appreciated.

$\endgroup$

1 Answer 1

3
$\begingroup$
xpr = a[x, t, u]*Derivative[1, 0][u][x, t] + 
   2*Derivative[0, 1][u][x, t]*Derivative[1, 0][u][x, t]*
    Derivative[0, 0, 1][b][x, t, u] + 
   2*u[x, t]*Derivative[1, 0][u][x, t]^2*
    Derivative[0, 0, 1][b][x, t, u] + 
   2*Derivative[1, 0][u][x, t]*Derivative[1, 1][u][x, t]*
    Derivative[0, 0, 1][c][x, t, u];

eqns = Thread[((List @@ xpr) /. {Derivative[_, _][u][__] :> 1, 
       u[_, _] :> 1}) == 0] // DeleteDuplicates

 (* {a[x, t, u] == 0, 
   2*Derivative[0, 0, 1][b][x, t, u] == 0, 
   2*Derivative[0, 0, 1][c][x, t, u] == 0} *)

EDIT: For the clarified question

Clear["Global`*"]

xpr = a[x, t, u]*Derivative[1, 0][u][x, t] + 
   2*Derivative[0, 1][u][x, t]*Derivative[1, 0][u][x, t]*
    Derivative[0, 0, 1][b][x, t, u] + 
   2*u[x, t]*Derivative[1, 0][u][x, t]^2*Derivative[0, 0, 1][b][x, t, u] + 
   2*Derivative[1, 0][u][x, t]*Derivative[1, 1][u][x, t]*
    Derivative[0, 0, 1][c][x, t, u] + 
   2*Derivative[0, 1][u][x, t]*Derivative[1, 0][u][x, t]*
    Derivative[0, 0, 1][d][x, t, u];

eqns = Thread[
   DeleteCases[
     CoefficientList[xpr, 
       DeleteCases[
        Variables[
         Level[xpr, {-2}]], _?(FreeQ[#, u[__] | Derivative[__][u]] &)]] // 
      Flatten, 0] == 0] // Simplify

(* {a[x, t, u] == 0, 
   Derivative[0, 0, 1][c][x, t, u] == 0, 
   Derivative[0, 0, 1][b][x, t, u] + 
       Derivative[0, 0, 1][d][x, t, u] == 0, 
   Derivative[0, 0, 1][b][x, t, u] == 0} *)

The Simplify removes the constants (e.g., 2) that are common to all terms of an equation.

$\endgroup$
7
  • $\begingroup$ Many thanks. However, I need to group similar terms that have common u[x,t] and its derivatives before applying your function. $\endgroup$
    – qahtah
    Commented Apr 4, 2020 at 20:05
  • $\begingroup$ @qahtah - please edit your question to clarify what you want and provide explicit examples of the types of inputs that need to be addressed. $\endgroup$
    – Bob Hanlon
    Commented Apr 4, 2020 at 20:24
  • $\begingroup$ thanks for your help. I edited the question, hopefully it is clear now. $\endgroup$
    – qahtah
    Commented Apr 4, 2020 at 21:12
  • $\begingroup$ That is exactly what I need. Many thanks for your help. $\endgroup$
    – qahtah
    Commented Apr 5, 2020 at 21:54
  • $\begingroup$ Bob, Unfortunately, the code doesn't work as expected, a simple example if xpr=-(u[x, t]^2*Derivative[0, 1][u][x, t]*Derivative[0, 0, 1][[Eta]][x, t, u]) - Derivative[0, 2][u][x, t]*Derivative[1, 0][u][x, t]*Derivative[0, 0, 1][[Xi]][x, t, u]; it doesn't group these two terms. $\endgroup$
    – qahtah
    Commented Apr 8, 2020 at 14:20

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.