0
$\begingroup$

I have large expressions linear in x. I would like to take all multiples of x off the expressions to have only the remaining terms free of x. For example, if I have U=(y+3z t)x-(5 y^2-t)x+2t^2, I want to extract and keep 2t^2. I have tried U - Coefficient[U,x]and Collect[U,x], but they take long time given that the expressions are large and I have to use Simplify to get the final expression. Is there some efficient way for doing this?

$\endgroup$
2
  • 1
    $\begingroup$ Why not simply set x to zero: (y+3z t)x-(5 y^2-t)x+2t^2 /. x->0 $\endgroup$ Commented Nov 7, 2020 at 20:42
  • $\begingroup$ @DanielHuber Thanks. But some of the terms contain some functions of x and other variables e.g. f[x,y], not sure the effect of setting x to 0 on this? $\endgroup$
    – Bran
    Commented Nov 7, 2020 at 20:47

1 Answer 1

1
$\begingroup$

You can use Select and FreeQ as follows:

Select[FreeQ @ x][ExpandAll @ U]
2 t^2
$\endgroup$
3
  • $\begingroup$ Thanks but it is not working. It just gives 0, although the answer is not. $\endgroup$
    – Bran
    Commented Nov 7, 2020 at 20:29
  • $\begingroup$ @Bran, trySelect[FreeQ @ x][ExpandAll @ U], If it does not work, please update the example in your post with an example U that shows the issue. $\endgroup$
    – kglr
    Commented Nov 7, 2020 at 20:48
  • 1
    $\begingroup$ That seems to do the trick. Thank you. $\endgroup$
    – Bran
    Commented Nov 7, 2020 at 21:14

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.