Polynomial to List

3 προβολές
Παράβλεψη και μετάβαση στο πρώτο μη αναγνωσμένο μήνυμα

Nick Hoffman

μη αναγνωσμένη,
29 Μαΐ 2007, 5:25:45 π.μ.29/5/07
ως
I have a polynomial,
Lets say:

1 + x + x^2 + x^3 + x^4


and all I need to do is get that into a list of this form

{x^4, x^3, x^2, x, 1}

Any help would be greatly appreciated! Thanks!


dimitris

μη αναγνωσμένη,
30 Μαΐ 2007, 5:08:40 π.μ.30/5/07
ως
It is very easy.
See below

In[26]:=
o = 1 + x + x^2 + x^3 + x^4
Out[26]=


1 + x + x^2 + x^3 + x^4

1)

In[28]:=
Reverse[List @@ o]
Out[28]=


{x^4, x^3, x^2, x, 1}

2)

In[36]:=
Cases[o, x^(n_.) | (x_Integer)]//Reverse
Out[36]=


{x^4, x^3, x^2, x, 1}

3)

In[39]:=
Reverse[o /. (x_) + (y___) -> {x, y}]
Out[39]=


{x^4, x^3, x^2, x, 1}

Dimitris

/ Nick Hoffman :

Adriano Pascoletti

μη αναγνωσμένη,
30 Μαΐ 2007, 5:09:40 π.μ.30/5/07
ως
List @@ (1 + x + x^2 + x^3 + x^4)

Adriano Pascoletti

Bob Hanlon

μη αναγνωσμένη,
30 Μαΐ 2007, 5:10:44 π.μ.30/5/07
ως
expr = 1 + x + x^2 + x^3 + x^4;

Reverse[List @@ expr]

{x^4, x^3, x^2, x, 1}


Bob Hanlon

Christoph Lhotka

μη αναγνωσμένη,
30 Μαΐ 2007, 5:13:47 π.μ.30/5/07
ως
Try one of those...

List@@polynomial

polynomial/.Plus->List

Table[polynmoial[[i]],{,1,Length[polynomial]}]


wkr Christoph

On Tue, 29 May 2007 05:07:44 -0400 (EDT)


"Nick Hoffman" <hoffm...@gmail.com> wrote:
> I have a polynomial,
> Lets say:
>
> 1 + x + x^2 + x^3 + x^4
>
>
> and all I need to do is get that into a list of this form
>
> {x^4, x^3, x^2, x, 1}
>
> Any help would be greatly appreciated! Thanks!
>
>

-- Mag. Christoph Lhotka --
University of Vienna / Department of Astronomy
Tuerkenschanzstrasse 17, A-1180 Vienna, Austria
fon. +43 (1) 4277 51841
mail. lho...@astro.univie.ac.at

Jens-Peer Kuska

μη αναγνωσμένη,
30 Μαΐ 2007, 5:14:48 π.μ.30/5/07
ως
Hi,

Cases[1 + x + x^2 + x^3 + x^4, x^_ | a_?(FreeQ[#, x] &)]

Regards
Jens

Jean-Marc Gulliet

μη αναγνωσμένη,
30 Μαΐ 2007, 5:24:56 π.μ.30/5/07
ως

The head of the expression poly is Plus. We replace it by List thanks to
the Apply function (short cut @@), then sort the resulting list to get
the desired form.

In[1]:=
poly = 1 + x + x^2 + x^3 + x^4;
Head[poly]
Reverse[List @@ poly]

Out[2]=
Plus

Out[3]=


{x^4, x^3, x^2, x, 1}

Regards,
Jean-Marc

Chris Scullard

μη αναγνωσμένη,
30 Μαΐ 2007, 5:25:59 π.μ.30/5/07
ως
Hi Nick,

In[1]:=
p=1+x+x^2+x^3+x^4

Out[1]=


1 + x + x^2 + x^3 + x^4

In[2]:=
t=Table[p[[i]],{i,1,Length[p]}]

Out[2]=
{1, x, x^2, x^3, x^4}

You can use Reverse[] if you want the list in the opposite order.

Regards,
Chris

Harvey P. Dale

μη αναγνωσμένη,
30 Μαΐ 2007, 5:29:06 π.μ.30/5/07
ως
Nick:

lst=1+x+x^2+x^3+x^4

Table[lst[[i]],{i,Length[lst]}]

Best,

Harvey

_____

From:NickHoffman[mailto:hoffm...@gmail.com]
Sent:Tuesday,May29,20075:08AM
To:math...@smc.vnet.net
Subject:PolynomialtoList

Ihaveapolynomial,
Letssay:

1+x+x^2+x^3+x^4


andallIneedtodoisgetthatintoalistof=
thisform

{x^4,x^3,x^2,x,1}

Anyhelpwouldbegreatlyappreciated!Thanks!


______________________________________________________________________
ThisemailhasbeenscannedbytheMessageLabsEmailSec=
uritySystem.
Formoreinformationpleasevisithttp://www.messagelabs.com/email

Sseziwa Mukasa

μη αναγνωσμένη,
30 Μαΐ 2007, 5:32:22 π.μ.30/5/07
ως

On May 29, 2007, at 5:07 AM, Nick Hoffman wrote:

> I have a polynomial,
> Lets say:
>
> 1 + x + x^2 + x^3 + x^4
>
>
> and all I need to do is get that into a list of this form
>
> {x^4, x^3, x^2, x, 1}
>
> Any help would be greatly appreciated! Thanks!

For that form of polynomial

List@@(1 + x + x^2 + x^3 + x^4)

works.

Regards,

Ssezi

János

μη αναγνωσμένη,
30 Μαΐ 2007, 5:39:28 π.μ.30/5/07
ως

On May 29, 2007, at 5:07 AM, Nick Hoffman wrote:

> I have a polynomial,
> Lets say:
>
> 1 + x + x^2 + x^3 + x^4
>
>
> and all I need to do is get that into a list of this form
>
> {x^4, x^3, x^2, x, 1}
>
> Any help would be greatly appreciated! Thanks!
>

Here is a newbie approach:

In[4]:=
Reverse[Table[(1 + x + x^2 +
x^3 + x^4)[[i]],
{i, 1, Length[1 + x +
x^2 + x^3 + x^4]}]]
Out[4]=


{x^4, x^3, x^2, x, 1}

J=E1nos


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)


DrMajorBob

μη αναγνωσμένη,
30 Μαΐ 2007, 5:47:40 π.μ.30/5/07
ως
1 + x + x^2 + x^3 + x^4 /. Plus -> List
Reverse@%

{1, x, x^2, x^3, x^4}

{x^4, x^3, x^2, x, 1}

or

Reverse@(List @@ (1 + x + x^2 + x^3 + x^4))

{x^4, x^3, x^2, x, 1}

Bobby

On Tue, 29 May 2007 04:07:44 -0500, Nick Hoffman <hoffm...@gmail.com>
wrote:

> I have a polynomial,
> Lets say:
>
> 1 + x + x^2 + x^3 + x^4
>
>
> and all I need to do is get that into a list of this form
>
> {x^4, x^3, x^2, x, 1}
>
> Any help would be greatly appreciated! Thanks!
>
>
>

--
DrMaj...@bigfoot.com

David Bailey

μη αναγνωσμένη,
30 Μαΐ 2007, 5:53:50 π.μ.30/5/07
ως
Assuming you KNOW that you have a sum of terms:

poly=1 + x + x^2 + x^3 + x^4


Reverse[List @@ poly]

David Bailey
http://www.dbaileyconsultancy.co.uk

Murray Eisenberg

μη αναγνωσμένη,
30 Μαΐ 2007, 6:02:17 π.μ.30/5/07
ως
First, let's make the problem a bit more complicated by looking at, say,
the polynomial:

p = c + k x - 7 x^2 + x^3 + Pi x^4

Now how does Mathematica parse that? Use FullForm:

FullForm[p]
Plus[c,Times[k,x],Times[-7,Power[x,2]],Power[x,3],Times[Pi,Power[x,4]]]

Thus the structure is Plus[...] where the argument of Plus is a sequence
of the various terms. You want a list consisting of these terms, so a
way to do it is to change Plus to List. The Apply function does this:

Apply[List,p]
{c, k*x, -7*x^2, x^3, Pi*x^4}

(There, and below, I show the linear, 1-dimensional InputForm of the 2D
standard form in which Mathematica would display the output.)

Finally, if you want to save some punctuation, use the @@ input form for
Apply, like this:

List@@p
{c, k*x, -7*x^2, x^3, Pi*x^4}

Finally, reverse the order of the terms by using -- what else? -- Reverse:

Reverse[List@@p]
{Pi*x^4, x^3, -7*x^2, k*x, c}


Nick Hoffman wrote:
> I have a polynomial,
> Lets say:
>
> 1 + x + x^2 + x^3 + x^4
>
>
> and all I need to do is get that into a list of this form
>
> {x^4, x^3, x^2, x, 1}
>
> Any help would be greatly appreciated! Thanks!
>
>

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

Szabolcs

μη αναγνωσμένη,
30 Μαΐ 2007, 6:10:39 π.μ.30/5/07
ως

In[3]:=
List@@(3+2x+x^2)

Out[3]=
{3, 2*x, x^2}

Also look up CoefficientList[] in the help.

dh

μη αναγνωσμένη,
31 Μαΐ 2007, 3:12:59 π.μ.31/5/07
ως

Hi Nick,

consider the full form of your expression poly=1 + x + x^2 + x^3 + x^4:

FullForm[poly]

this nearly looks like the list you want (besides reversion), only the

Head is Plus instead of List. But this is easily fixed by Apply:

List @@ poly

If you want to reverse the list, you may use Reverse.

hope this helps, Daniel

dimitris

μη αναγνωσμένη,
31 Μαΐ 2007, 3:29:13 π.μ.31/5/07
ως
Hello Janos.

Is it a particular reason (from progarmming aspects)
that in various answers of you regarding if the query is about
something
trivial (as in the current thread) or not you seem
to have sticked to Table structures?

Dimitris

/ J=E1nos :

Απάντηση σε όλους
Απάντηση στον συντάκτη
Προώθηση
0 νέα μηνύματα