# [R] a really simple question on polynomial multiplication

Moshe Olshansky m_olshansky at yahoo.com
Thu Oct 16 00:25:40 CEST 2008

```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).

> a <- c(1,-3)
> b <- c(1,3)
> c <- convolve(a,rev(b),type="open")
> c
[1]  1.00000e+00 -6.49654e-16 -9.00000e+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 <erinm.hodgess at gmail.com> wrote:

> From: Erin Hodgess <erinm.hodgess at gmail.com>
> Subject: [R]  a really simple question on polynomial multiplication
> To: "R Help" <r-help at 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: erinm.hodgess at gmail.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help