Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7009 > unrolled thread
| Started by | Chris Young <cy56@comcast.net> |
|---|---|
| First post | 2011-12-08 10:21 +0000 |
| Last post | 2011-12-09 11:03 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Function for complex polynomial with variable number of arguments Chris Young <cy56@comcast.net> - 2011-12-08 10:21 +0000
Re: Function for complex polynomial with variable number of arguments Simon <simonjtyler@gmail.com> - 2011-12-09 11:03 +0000
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Date | 2011-12-08 10:21 +0000 |
| Subject | Function for complex polynomial with variable number of arguments |
| Message-ID | <jbq33b$ica$1@smc.vnet.net> |
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. ‘™˜ButtonBox["",
Appearance->{Automatic, None},
BaseStyle->"Link",
ButtonData:>"paclet:ref/message/General/partw",
ButtonNote->"Part::partw"]"
Out[556]= x + I y - {}[[1]]
[toc] | [next] | [standalone]
| From | Simon <simonjtyler@gmail.com> |
|---|---|
| Date | 2011-12-09 11:03 +0000 |
| Message-ID | <jbspto$3t8$1@smc.vnet.net> |
| In reply to | #7009 |
You could just add a Default for the pattern p__, i.e.
poly[z_, p__: 0] := Product[z - {p}[[i]], {i, Max[1, Length[{p}]]}]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web