[R] a really simple question on polynomial multiplication
Rolf Turner
r.turner at auckland.ac.nz
Thu Oct 16 00:25:57 CEST 2008
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}}
More information about the R-help
mailing list