[R] tensor product of equi-spaced B-splines in the unit square

From: Patrizio Frederic <frederic.patrizio_at_gmail.com>
Date: Tue, 29 Jul 2008 18:00:37 +0200


Dear all,
I need to compute tensor product of B-spline defined over equi-spaced break-points.
I wrote my own program (it works in a 2-dimensional setting)

library(splines)
# set the break-points

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 contour-type 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
+-------------------------------------------------

______________________________________________
R-help_at_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. Received on Tue 29 Jul 2008 - 16:08:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 31 Jul 2008 - 15:33:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive