[R] Bivariate polynomials in R
Alaios
alaios at yahoo.com
Wed Jan 26 12:47:38 CET 2011
Have you ever worked in R with bivariate polynomials? How did you implement simple operators like addition/multiplication?
I found a package called multipol that seems to support these kinds of operators but I do keep receiving error.
Check for example the following snippet of code (you can copy & paste)
require('orthopolynom')
require('polynom')
require('multipol')
psi <-function (order){
psi<-matrix(data=polynomial.coefficients(legendre.polynomials(order)[[order+1]]),ncol=1)
}
phi <-function (order){
phi<-matrix(data=polynomial.coefficients(legendre.polynomials(order)[[order+1]]),nrow=1)
}
# Then I convert them to multinomials.
psipol<-as.multipol(psi(2))
phipol<-as.multipol(phi(2))
print(psipol)
print(phipol)
# Here error occurs
psipol*phipol
The multiplication above fails.
According the multipol pdf
http://cran.r-project.org/web/packages/multipol/vignettes/multipol.pdf
this works: (which does)
require(multipol)
a <- as.multipol(matrix(1:10, nrow = 2))
a*a # gives correct results
So I tried to see what is the str of a to understand if I did something wrong (that destroyed the structure of my data).
str(a)
Error in `[.multipol`(object, seq_len(ile)) :
incorrect number of dimensions
Calls: str ... formObj -> paste -> format.fun -> format -> [ -> [.multipol
And right now I am at a stalemate. I can not find out why my multiplication failed If I can not find the structure of a.
What should i do now?
Regards
Alex
More information about the R-help
mailing list