Message Boards Message Boards

how to get coefficient list from a polynomial with positive and negative powers?

Posted 4 days ago

Hi,

This is a math problem. Solving an equation

How to collect y power coefficients and then solve as a device, both positive and negative power? Can you help me? This is example enter image description here

POSTED BY: Sami Heidari
5 Replies

I don't understand what goes wrong in your code. I copied the notebook you posted and ran it. I got the following below, which is the same result as I obtained originally:

https://www.wolframcloud.com/obj/mroge02/Published/361378166

(For some reason, the "Add Notebook" does seem to add the notebook. So I just pasted a link.)

POSTED BY: Michael Rogers
Posted 20 hours ago

I attached the code.

Another question?

"Why does func return the correct result, but func1 does not?"

POSTED BY: Sami Heidari

I don't get the output you showed. I get the output I showed.

Your unformatted code is missing the *s from the comment, but I fixed that when I tested. As I said, I got what I showed, not what you showed in your reply.

This seems obvious: If you don't want the exponent, leave it off and just use the CoefficientList[..] part of the code without the braces. So if you want something else, please explain.

POSTED BY: Michael Rogers
Posted 2 days ago

You didn't understand what I meant. I want, for example, the same function u that you considered to give me a list as follows:

{b, 0, 0, c, 0, a}

But it goes like this:

In[154]:= u = b/y^3 + c + a y^2;

coeffs =(*{coefficient list,max degree}*){CoefficientList[
   u/y^Exponent[Series[u, y -> 0], y], y], Exponent[u, y]}

Out[155]= {{c + b/y^3, 0, a}, 2}
POSTED BY: Sami Heidari

Shift the powers to make a polynomial; store the max degree in the data structure (somewhat like RealDigits)l

u = b/y^3 + c + a y^2;

coeffs =(* {coefficient list, max degree}*)
 {CoefficientList[u/y^Exponent[Series[u, y -> 0], y], y], 
  Exponent[u, y]}

(*  {{b, 0, 0, c, 0, a}, 2}  *)

Reconstruct the expression:

First[coeffs] . (y^Range[Last[coeffs] - Length@First[coeffs] + 1, Last[coeffs]])

(*  c + b/y^3 + a y^2  *)
POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract