3
$\begingroup$

Say a polynomial x^2-x^(-2), I need to extract its coefficient. I tried the command CoefficientList[x^2-x^(-2)], but no result comes out.

enter image description here

I am confused why it happens. How can I get the desired result {-1,0,0,0,1}?

It should be an easy question, but I do not know the suitable command. Would you please give me some tips?

$\endgroup$

3 Answers 3

3
$\begingroup$

Would it be OK for you to look separately for the list of coefficients with positive and that with negative powers? If yes, try this. Let us introduce a rule transforming, say, x^-2 into y^2:

rule = Power[x, n_] /; n < 0 -> y^-n;

Here is your polynomial:

p = x^2 - x^(-2);

Now this:

CoefficientList[p /. rule, x] /. y -> 0
CoefficientList[p /. rule, y] /. x -> 0
(* {0, 0, 1}
   {0, 0, -1}   *)

gives us the answers separately for positive and negative powers.

Have fun!

$\endgroup$
2
  • $\begingroup$ Thank you for your answer! It is ok to separate items with positive and negative powers. But I still wonder why there is no such a direct command to gain coefficients for both items with positive and negative powers:) $\endgroup$
    – Robin_Lyn
    Nov 16, 2018 at 12:14
  • $\begingroup$ It is a general situation. Mma has no all functions that one can wish. In this case, we may write our own functions and use when needed. Taking my idea as a basis you might like to construct such a function. $\endgroup$ Nov 16, 2018 at 13:02
4
$\begingroup$

Could find the min exponent, then make it an explicit polynomial.

laurentCoefficientList[lpol_, x_] := With[
  {min = Exponent[lpol, x, Min]}, CoefficientList[lpol/x^min, x]]

In[56]:= laurentCoefficientList[x^2 - x^(-2), x]

(* Out[56]= {-1, 0, 0, 0, 1} *)
$\endgroup$
1
$\begingroup$

Check your spelling (upper-case L):

CoefficientList[x^2 - x^(-2), x]

From the documentation: "Terms that do not contain positive integer powers of a particular variable are included in the first element of the list for that variable."

$\endgroup$
1
  • 1
    $\begingroup$ It is a spelling mistake, and is trivial. The question has been updated. $\endgroup$
    – Robin_Lyn
    Nov 16, 2018 at 7:55

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.