Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7045
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!goblin1!goblin.stu.neva.ru!feed.xsnews.nl!border-1.ams.xsnews.nl!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail |
|---|---|
| From | Heike Gramberg <heike.gramberg@gmail.com> |
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Function for complex polynomial with variable number of arguments |
| Date | Fri, 9 Dec 2011 10:54:34 +0000 (UTC) |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Sender | steve@smc.vnet.net |
| Approved | Steven M. Christensen <steve@smc.vnet.net>, Moderator |
| Message-ID | <jbspda$3lp$1@smc.vnet.net> (permalink) |
| References | <201112081021.FAA18802@smc.vnet.net> |
| Lines | 47 |
| NNTP-Posting-Date | 09 Dec 2011 09:59:11 GMT |
| NNTP-Posting-Host | fe3e341e.news.twtelecom.net |
| X-Trace | DXC=U6TBkhbC3canBa5FI7EIm`C_A=>8kQj6mm^eQlV`f18g48X_PZCZ2faEFiONJ7[Gof[_<XTFiGGEc |
| X-Complaints-To | abuse@twtelecom.net |
| Xref | x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:7045 |
Show key headers only | View raw
You could do something like this
poly[z_, p___] := Fold[(z - #2) #1 &, 1, {p}]
This works for p=={} as well, i.e.
poly[x+I y]
returns 1.
Heike
On 8 Dec 2011, at 11:21, 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. =91=99=98ButtonBox["",
> Appearance->{Automatic, None},
> BaseStyle->"Link",
> ButtonData:>"paclet:ref/message/General/partw",
> ButtonNote->"Part::partw"]"
> Out[556]= x + I y - {}[[1]]
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Function for complex polynomial with variable number of arguments Heike Gramberg <heike.gramberg@gmail.com> - 2011-12-09 10:54 +0000
csiph-web