[R] tensor product of equispaced Bsplines in the unit square
Patrizio Frederic
frederic.patrizio at gmail.com
Tue Jul 29 18:00:37 CEST 2008
Dear all,
I need to compute tensor product of Bspline defined over equispaced
breakpoints.
I wrote my own program (it works in a 2dimensional setting)
library(splines)
# set the breakpoints
Knots = seq(1,1,length=10)
# number of splines
M = (length(Knots)4)^2
# short cut to splineDesign function
bspline = function(x) splineDesign(Knots,x,outer.ok = T)
# bivariate tensor product of bspline
btens = function(x) t(bspline(x[1]))%*%bspline(x[2])
# numebr of points to plot
ng = 51
# create vectors for plotting
xgr = seq(1,1,length=ng)
xgr2 = expand.grid(xgr,xgr)
# generate random coef. of linear combination
bet = rnorm(M)
# create matrix for contourtype plot
Bx = apply(xgr2,1,btens)
Bmat = matrix(t(Bx)%*%bet,ng)
# plot the result
contour(xgr,xgr,Bmat)
persp(xgr,xgr,Bmat,theta=15)
any of you have a better idea (ie more efficient)?
Thanks in advance,
Patrizio Frederic
+
 Patrizio Frederic
 Research associate in Statistics,
 Department of Economics,
 University of Modena and Reggio Emilia,
 Via Berengario 51,
 41100 Modena, Italy

 tel: +39 059 205 6727
 fax: +39 059 205 6947
 mail: patrizio.frederic at unimore.it
+
More information about the Rhelp
mailing list