gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
l2appr.f
Go to the documentation of this file.
1  subroutine l2appr ( t, n, k, q, diag, bcoef )
2 
3 c*********************************************************************72
4 c
5 cc L2APPR constructs a weighted L2 spline approximation to given data.
6 c
7 c from * a practical guide to splines * by c. de boor
8 c to be called in main program l 2 m a i n .
9 calls subprograms bsplvb, bchfac/slv
10 c
11 constructs the (weighted discrete) l2-approximation by splines of order
12 c k with knot sequence t(1), ..., t(n+k) to given data points
13 c ( tau(i), gtau(i) ), i=1,...,ntau. the b-spline coefficients
14 c b c o e f of the approximating spline are determined from the
15 c normal equations using cholesky's method.
16 c
17 c****** i n p u t ******
18 c t(1), ..., t(n+k) the knot sequence
19 c n.....the dimension of the space of splines of order k with knots t.
20 c k.....the order
21 c
22 c w a r n i n g . . . the restriction k .le. kmax (= 20) is impo-
23 c sed by the arbitrary dimension statement for biatx below, but
24 c is n o w h e r e c h e c k e d for.
25 c
26 c****** w o r k a r r a y s ******
27 c q....a work array of size (at least) k*n. its first k rows are used
28 c for the k lower diagonals of the gramian matrix c .
29 c diag.....a work array of length n used in bchfac .
30 c
31 c****** i n p u t via c o m m o n /data/ ******
32 c ntau.....number of data points
33 c (tau(i),gtau(i)), i=1,...,ntau are the ntau data points to be
34 c fitted .
35 c weight(i), i=1,...,ntau are the corresponding weights .
36 c
37 c****** o u t p u t ******
38 c bcoef(1), ..., bcoef(n) the b-spline coeffs. of the l2-appr.
39 c
40 c****** m e t h o d ******
41 c the b-spline coefficients of the l2-appr. are determined as the sol-
42 c ution of the normal equations
43 c sum ( (b(i),b(j))*bcoef(j) : j=1,...,n) = (b(i),g),
44 c i = 1, ..., n .
45 c here, b(i) denotes the i-th b-spline, g denotes the function to
46 c be approximated, and the i n n e r p r o d u c t of two funct-
47 c ions f and g is given by
48 c (f,g) := sum ( f(tau(i))*g(tau(i))*weight(i) : i=1,...,ntau) .
49 c the arrays t a u and w e i g h t are given in common block
50 c d a t a , as is the array g t a u containing the sequence
51 c g(tau(i)), i=1,...,ntau.
52 c the relevant function values of the b-splines b(i), i=1,...,n, are
53 c supplied by the subprogram b s p l v b .
54 c the coeff.matrix c , with
55 c c(i,j) := (b(i), b(j)), i,j=1,...,n,
56 c of the normal equations is symmetric and (2*k-1)-banded, therefore
57 c can be specified by giving its k bands at or below the diagonal. for
58 c i=1,...,n, we store
59 c (b(i),b(j)) = c(i,j) in q(i-j+1,j), j=i,...,min0(i+k-1,n)
60 c and the right side
61 c (b(i), g ) in bcoef(i) .
62 c since b-spline values are most efficiently generated by finding sim-
63 c ultaneously the value of e v e r y nonzero b-spline at one point,
64 c the entries of c (i.e., of q ), are generated by computing, for
65 c each ll, all the terms involving tau(ll) simultaneously and adding
66 c them to all relevant entries.
67 c
68  implicit none
69 
70  integer k,n, i,j,jj,kmax,left,leftmk,ll,mm,ntau,ntmax
71  parameter(kmax=20,ntmax=200)
72  double precision bcoef(n),diag(n),q(k,n),t(n+k),
73  & biatx(kmax),dw,gtau,tau,weight
74  common / i4data / ntau
75  common / r8data / tau(ntmax),gtau(ntmax),weight(ntmax)
76 c
77  do 7 j=1,n
78  bcoef(j) = 0.0d+00
79  do 7 i=1,k
80  7 q(i,j) = 0.0d+00
81  left = k
82  leftmk = 0
83  do 20 ll=1,ntau
84 c locate l e f t s.t. tau(ll) in (t(left),t(left+1))
85  10 if (left .eq. n) go to 15
86  if (tau(ll) .lt. t(left+1)) go to 15
87  left = left+1
88  leftmk = leftmk + 1
89  go to 10
90  15 call bsplvb ( t, k, 1, tau(ll), left, biatx )
91 c biatx(mm) contains the value of b(left-k+mm) at tau(ll).
92 c hence, with dw := biatx(mm)*weight(ll), the number dw*gtau(ll)
93 c is a summand in the inner product
94 c (b(left-k+mm), g) which goes into bcoef(left-k+mm)
95 c and the number biatx(jj)*dw is a summand in the inner product
96 c (b(left-k+jj), b(left-k+mm)), into q(jj-mm+1,left-k+mm)
97 c since (left-k+jj) - (left-k+mm) + 1 = jj - mm + 1 .
98  do 20 mm=1,k
99  dw = biatx(mm)*weight(ll)
100  j = leftmk + mm
101  bcoef(j) = dw*gtau(ll) + bcoef(j)
102  i = 1
103  do 20 jj=mm,k
104  q(i,j) = biatx(jj)*dw + q(i,j)
105  20 i = i + 1
106 c
107 c construct cholesky factorization for c in q , then use
108 c it to solve the normal equations
109 c c*x = bcoef
110 c for x , and store x in bcoef .
111  call bchfac ( q, k, n, diag )
112  call bchslv ( q, k, n, bcoef )
113  return
114  end
subroutine bsplvb(t, jhigh, index, x, left, biatx)
Definition: bsplvb.f:2
subroutine bchslv(w, nbands, nrow, b)
Definition: bchslv.f:2
subroutine bchfac(w, nbands, nrow, diag)
Definition: bchfac.f:2
subroutine l2appr(t, n, k, q, diag, bcoef)
Definition: l2appr.f:2
gtkIOStream: /tmp/gtkiostream/src/deBoor/l2appr.f Source File
GTK+ IOStream  Beta