[R] a really simple question on polynomial multiplication

2008-10-15 Thread Erin Hodgess
Dear R people:

Is there a way to perform simple polynomial multiplication; that is,
something like
(x - 3) * (x + 3) = x^2 - 9, please?

I looked in poly and polyroot and expression.  There used to be a
package that had this, maybe?

thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] a really simple question on polynomial multiplication

2008-10-15 Thread Jorge Ivan Velez
Dear Erin,
Yes. Take a look at page 13 in [1].

HTH,

Jorge

[1]  http://cran.r-project.org/web/packages/Ryacas/vignettes/Ryacas.pdf



On Wed, Oct 15, 2008 at 5:44 PM, Erin Hodgess [EMAIL PROTECTED]wrote:

 Dear R people:

 Is there a way to perform simple polynomial multiplication; that is,
 something like
 (x - 3) * (x + 3) = x^2 - 9, please?

 I looked in poly and polyroot and expression.  There used to be a
 package that had this, maybe?

 thanks,
 Erin


 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: [EMAIL PROTECTED]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] a really simple question on polynomial multiplication

2008-10-15 Thread Moshe Olshansky
One way is to use convolution (?convolve):

If A(x) = a_p*x^p + ... + a_1*x + a_0
and B(x) = b_q*x^q + ... + b_1*x + b_0
and if C(x) = A(x)*B(x) = c_(p+q)*x^(p+q) + ... + c_0 
then c = convolve(a,rev(b),type=open)
where c is the vector (c_(p+q),...,c_0), a is (a_p,...,a_0) and b is 
(b_q,...,b_0).
In your case:

 a - c(1,-3)
 b - c(1,3)
 c - convolve(a,rev(b),type=open)
 c
[1]  1.0e+00 -6.49654e-16 -9.0e+00

Note that the coefficient of x is not exactly 0 due to the use of fft to 
compute convolutions. 



--- On Thu, 16/10/08, Erin Hodgess [EMAIL PROTECTED] wrote:

 From: Erin Hodgess [EMAIL PROTECTED]
 Subject: [R]  a really simple question on polynomial multiplication
 To: R Help r-help@r-project.org
 Received: Thursday, 16 October, 2008, 8:44 AM
 Dear R people:
 
 Is there a way to perform simple polynomial multiplication;
 that is,
 something like
 (x - 3) * (x + 3) = x^2 - 9, please?
 
 I looked in poly and polyroot and expression.  There used
 to be a
 package that had this, maybe?
 
 thanks,
 Erin
 
 
 -- 
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: [EMAIL PROTECTED]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained,
 reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] a really simple question on polynomial multiplication

2008-10-15 Thread Rolf Turner


On 16/10/2008, at 10:44 AM, Erin Hodgess wrote:


Dear R people:

Is there a way to perform simple polynomial multiplication; that is,
something like
(x - 3) * (x + 3) = x^2 - 9, please?

I looked in poly and polyroot and expression.  There used to be a
package that had this, maybe?


The PolynomF package from CRAN will do this.  E.g.

install.packages(PolynomF)
library(PolynomF)
a - polynom(-3,1)
b - polynom(3,1)
a*b

The default is to print ``-9 + x^2'' rather than ``x^2 - 9''.

You can of course type
print(a*b,decreasing=TRUE)

to get ``x^2 - 9'', but this is a bit kludgy.  It would be nice to have
an options() setting to change the default.  You could program that up
yourself of course.  (And then send the contributed the improvement to
Bill Venables!)

cheers,

Rolf

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] a really simple question on polynomial multiplication

2008-10-15 Thread Rolf Turner


On 16/10/2008, at 2:27 PM, Moshe Olshansky wrote:


Hi Rolf,

Thank you for making me aware of the existence of PolynomF package.

By the way, your solution needs a small modification:
a - polynom(c(-3,1)) and not polynom(-3,1) and similar for b.


Indeed; I typed the code into the email separately from typing it into
my R window.  (Bad move!)  I did try the code out (honest!) but then
retyped when I sent my email r.t. copying and pasting.  (Copying and
pasting on a Mac --- on which I am forced to work --- is fraught with
frustrations.)

cheers,

Rolf

P. S.  PolynomF seems to be slickly designed.  But then, what do you
expect?  Bill Venables wrote it!

R.

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.