MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Function for complex polynomial with variable number of arguments

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123496] Re: Function for complex polynomial with variable number of arguments
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Fri, 9 Dec 2011 05:55:07 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Clear[poly]

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

poly[x + y I, a + b I, c + d I, c + d I]

(-a - I*b + x + I*y)*(-c - I*d + x + I*y)^2

poly[x + y I, a + b I]

-a - I*b + x + I*y

poly[x + y I, 0]

x + I*y

poly[x + y I]

1

This last result comes from

x + I*y - {}

{}

Times @@ {}

1


Bob Hanlon


On Thu, Dec 8, 2011 at 5:21 AM, Chris Young <cy56 at comcast.net> 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. =91=99=98ButtonBox["",
> Appearance->{Automatic, None},
> BaseStyle->"Link",
> ButtonData:>"paclet:ref/message/General/partw",
> ButtonNote->"Part::partw"]"
> Out[556]== x + I y - {}[[1]]
>



  • Prev by Date: Re: Evaluate[expr]
  • Next by Date: Can FindFit take two (or more) equations?
  • Previous by thread: Re: Function for complex polynomial with variable number of arguments
  • Next by thread: Re: Function for complex polynomial with variable number of arguments