1
$\begingroup$

For example, if I have,

e = a0 + a1 x + a2 (-x + x^2) + a3(-x + x^3) + .... + an (-x + x^n)

how do I find and list

{x, (-x + x^2), ..., (-x + x^n)}?

I tried

Coefficient[e, a[i], {i, 0, 10}]` 

where, n = 10. It shows some error. Please help.

$\endgroup$
1
  • 3
    $\begingroup$ Basis with respect to what notion of independence? $\endgroup$ Commented Jul 5, 2017 at 18:01

2 Answers 2

1
$\begingroup$
e = a0 + a1 x + a2 (-x + x^2) + a3 (-x + x^3) + an (-x + x^n); 

Cases[List @@ e, a_ b_ /; (FreeQ[a, x] && Not[FreeQ[b, x]]) :> b]

{x, -x + x^2, -x + x^3, -x + x^n}

Or

rule = Alternatives @@ Select[Variables[e], FreeQ[#, x] &] -> 1;
Rest[List @@ e /. rule]

{x, -x + x^2, -x + x^3, -x + x^n}

$\endgroup$
1
  • 1
    $\begingroup$ Since "The first argument to Cases need not have head List", you can use Cases[e, a_ b_ /; (FreeQ[a, x] && Not[FreeQ[b, x]]) :> b] $\endgroup$
    – Bob Hanlon
    Commented Nov 2, 2017 at 12:06
1
$\begingroup$
coef = Table[a[i], {i, 0, 10}];
e = coef.Table[If[i >= 2, x^i - x, x^i], {i, 0, 10}];

Reap[Collect[e, coef, Sow]][[2, 1]]
(* or *)
Reap[Collect[e, Complement[Variables[e], {x}], Sow]][[2, 1]]
{1, x, -x + x^2, -x + x^3, -x + x^4, -x + x^5, -x + x^6, -x + x^7, -x + x^8, -x + x^9, -x + x^10}

Did you forget 1 when writing the desired output or shouldn't it be there?

$\endgroup$

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.