aboutsummaryrefslogtreecommitdiff
path: root/math/curfit/cv_b1eval.gx
blob: bd77f0ed41fcf61df3c388f4033b4e9ab533fa7f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

# CV_B1LEG -- Procedure to evaluate all the non-zero Legendrefunctions for
# a single point and given order.

procedure $tcv_b1leg (x, order, k1, k2, basis)

PIXEL	x		# array of data points
int	order		# order of polynomial, order = 1, constant
PIXEL	k1, k2		# normalizing constants
PIXEL	basis[ARB]	# basis functions

int	i
PIXEL	ri, xnorm

begin
	basis[1] = PIXEL(1.0)
	if (order == 1)
	    return

	xnorm = (x + k1) * k2 
	basis[2] = xnorm
	if (order == 2)
	    return

	do i = 3, order {
	    ri = i
	    basis[i] = ((PIXEL(2.0) * ri - PIXEL(3.0)) * xnorm * basis[i-1] -
		(ri - PIXEL(2.0)) * basis[i-2]) / (ri - PIXEL(1.0))	
	}
end


# CV_B1CHEB -- Procedure to evaluate all the non zero Chebyshev function
# for a given x and order.

procedure $tcv_b1cheb (x, order, k1, k2, basis)

PIXEL	x		# number of data points
int	order		# order of polynomial, 1 is a constant
PIXEL	k1, k2		# normalizing constants
PIXEL	basis[ARB]	# array of basis functions

int	i
PIXEL	xnorm

begin
	basis[1] = PIXEL(1.0)
	if (order == 1)
	    return

	xnorm = (x + k1) * k2
	basis[2] = xnorm
	if (order == 2)
	    return

	do i = 3, order
	    basis[i] = PIXEL(2.0) * xnorm * basis[i-1] - basis[i-2]
end


# CV_B1SPLINE1 -- Evaluate all the non-zero spline1 functions for a
# single point.

procedure $tcv_b1spline1 (x, npieces, k1, k2, basis, left)

PIXEL	x		# set of data points
int	npieces		# number of polynomial pieces minus 1
PIXEL	k1, k2		# normalizing constants
PIXEL	basis[ARB]	# basis functions
int	left		# index of the appropriate spline functions

PIXEL	xnorm

begin
	xnorm = (x + k1) * k2
	left = min (int (xnorm), npieces)

	basis[2] = max (PIXEL(0.0), min (PIXEL(1.0), xnorm - left))
	basis[1] = max (PIXEL(0.0), min (PIXEL(1.0), PIXEL(1.0) - basis[2]))
end


# CV_B1SPLINE3 --  Procedure to evaluate all the non-zero basis functions
# for a cubic spline.

procedure $tcv_b1spline3 (x, npieces, k1, k2, basis, left)

PIXEL	x		# array of data points
int	npieces		# number of polynomial pieces
PIXEL	k1, k2		# normalizing constants
PIXEL	basis[ARB]	# array of basis functions
int	left		# array of indices for first non-zero spline

PIXEL	sx, tx

begin
	sx = (x + k1) * k2
	left = min (int (sx), npieces)

	sx = max (PIXEL(0.0), min (PIXEL(1.0), sx - left))
	tx = max (PIXEL(0.0), min (PIXEL(1.0), PIXEL(1.0) - sx))

	basis[1] = tx * tx * tx
	basis[2] = PIXEL(1.0) + tx * (PIXEL(3.0) + tx * (PIXEL(3.0) -
	    PIXEL(3.0) * tx))
	basis[3] = PIXEL(1.0) + sx * (PIXEL(3.0) + sx * (PIXEL(3.0) -
	    PIXEL(3.0) * sx))
	basis[4] = sx * sx * sx
end