Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7047 > unrolled thread

Re: Function for complex polynomial with variable number of arguments

Started byMurray Eisenberg <murray@math.umass.edu>
First post2011-12-09 10:57 +0000
Last post2011-12-09 10:57 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Function for complex polynomial with variable number of arguments Murray Eisenberg <murray@math.umass.edu> - 2011-12-09 10:57 +0000

#7047 — Re: Function for complex polynomial with variable number of arguments

FromMurray Eisenberg <murray@math.umass.edu>
Date2011-12-09 10:57 +0000
SubjectRe: Function for complex polynomial with variable number of arguments
Message-ID<jbspi6$3pf$1@smc.vnet.net>
I presume you want the constant 1 as result in case you have an empty
list of points, as the product of an empty list should be 1 in order for
the generalized associative rule to hold for multiplication.

There's an easy solution, obtained by making things simpler: avoid
indices entirely and directly use list-manipulation:

   poly[z_, p_] :== Times @@ (z - p)

   poly[z, {a + b I, c + d I, c + d I}]
(-a - I b + z) (-c - I d + z)^2

   poly[z, {a + b I}]
-a - I b + z

   poly[z, {}]
1

If you insist on your original syntax, then change the above to:

   poly2[z_, p___] :== Times @@ (z - {p})

On 12/8/11 5:21 AM, Chris Young wrote:
> I want to be able to pass any number of complex points to this
> polynomial function and have it return the product of factors (z - p_1)
> (z - p_2) etc. Works OK except when I pass in no arguments. Looks like
> I have to check for this, but I'm wondering if there's a better way to
> convert my arguments into factors, maybe using Fold.
>
> poly[z_, p___] :==
>   Product[z - (List@p)[[i]], {1, Max[1, Length[List[p]]]}]
>
>
>
> In[553]:== poly[x + y I, a + b I, c + d I, c + d I]
> Out[553]== (-a - I b + x + I y) (-c - I d + x + I y)^2
>
> In[554]:== poly[x + y I, a + b I]
> Out[554]== -a - I b + x + I y
>
> In[555]:== poly[x + y I, 0]
> Out[555]== x + I y
>
> In[556]:== poly[x + y I]
>
> During evaluation of In[556]:== Part::partw :  "Part 1 of {} does not
> exist. =E2=80=98=E2=84=A2=CB=9CButtonBox["",
> Appearance->{Automatic, None},
> BaseStyle->"Link",
> ButtonData:>"paclet:ref/message/General/partw",
> ButtonNote->"Part::partw"]"
> Out[556]== x + I y - {}[[1]]
>
>

--
Murray Eisenberg                     murray@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

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web