2
$\begingroup$

A simple question:

I have this equation:

eq1=Derivative[0, 1][T1][x, t] - Derivative[1, 0][T0][x, t]^2 - 
 T0[x, t]*Derivative[2, 0][T0][x, t] - Derivative[2, 0][T1][x, t] == 0;

I want only to select terms that contain T0 or its derivatives only, that is:

-Derivative[1, 0][T0][x, t]^2 - T0[x, t]*Derivative[2, 0][T0][x, t]

Thanks in anticipation.

$\endgroup$
  • 2
    $\begingroup$ DeleteCases[eq1 /. Equal -> Subtract, _?(FreeQ[#,T0]&]? $\endgroup$ – Michael E2 Jan 15 '20 at 22:59
  • $\begingroup$ @MichaelE2 there is a parenthesis missing after the & symbol. Great answer though. More elegant than mine! $\endgroup$ – DiSp0sablE_H3r0 Jan 15 '20 at 23:01
  • 1
    $\begingroup$ Yeah, I'm using Gedanken Mathematica, you know the one that's basically a keyboard without a kernel. Hard to catch those typos. $\endgroup$ – Michael E2 Jan 15 '20 at 23:09
1
$\begingroup$

While the structural operation

DeleteCases[eq1 /. Equal -> Subtract, _?(FreeQ[#,T0]&)]

works, I prefer using an algebraic approach on a algebraic problem.

vars = Select[Not@*FreeQ[T0]]@Variables[eq1 /. Equal -> Subtract];
coeffs = CoefficientArrays[eq1 /. Equal -> Subtract, vars];
Fold[#2 + #1.vars &, Reverse@ReplacePart[coeffs, 1 -> 0]]

Mathematica graphics

The structural approach relies on the equation being in a particular form, a flat sum of terms, which does not always happend. The algebraic approach does not. However, CoefficientArrays does rely on it being a polynomial in the variables vars.

$\endgroup$
1
$\begingroup$
Block[{T1, Equal = Plus}, SetAttributes[T1, Constant]; eq1]
-Derivative[1, 0][T0][x, t]^2 - T0[x, t]*Derivative[2, 0][T0][x, t]

Or (thanks to Mr. Wizard here)

eq1 /. {s_Symbol /; StringMatchQ[SymbolName[Unevaluated@s], "T" ~~ Except["0"]] -> 0, Equal -> Plus}
-Derivative[1, 0][T0][x, t]^2 - T0[x, t]*Derivative[2, 0][T0][x, t]
$\endgroup$
1
$\begingroup$

Not the most elegant solution, but you can use the Collectcommand in the following manner

eq1 =  Derivative[0, 1][T1][x, t] - 
       Derivative[1, 0][T0][x, t]^2 - 
       T0[x, t]*Derivative[2, 0][T0][x, t] - 
       Derivative[2, 0][T1][x, t]; 
       (Coefficient[#1, {T0[x, t], Derivative[1, 0][T0][x, 
       t], Derivative[1, 0][T0][x, t]^2}] & )[eq1]

This is telling you the coefficient in front of T0[x, t] and so on.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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