forked from johannesgerer/jburkardt-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbernstein_polynomial.html
366 lines (321 loc) · 9.99 KB
/
bernstein_polynomial.html
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<html>
<head>
<title>
BERNSTEIN_POLYNOMIAL - The Bernstein Polynomials
</title>
</head>
<body bgcolor="#EEEEEE" link="#CC0000" alink="#FF3300" vlink="#000055">
<h1 align = "center">
BERNSTEIN_POLYNOMIAL <br> The Bernstein Polynomials
</h1>
<hr>
<p>
<b>BERNSTEIN_POLYNOMIAL</b>
is a C++ library which
evaluates the Bernstein polynomials.
</p>
<p>
The k-th Bernstein basis polynomial of degree n is defined by
<pre>
B(n,k)(x) = C(n,k) * (1-x)^(n-k) * x^k
</pre>
for k = 0 to n and C(n,k) is the combinatorial function "N choose K"
defined by
<pre>
C(n,k) = n! / k! / ( n - k )!
</pre>
</p>
<p>
For an arbitrary value of n, the set B(n,k) forms a basis
for the space of polynomials of degree n or less.
</p>
<p>
Every basis polynomial B(n,k) is nonnegative in [0,1], and may be zero
only at the endpoints.
</p>
<p>
Except for the case n = 0, the basis polynomial B(n,k)(x) has a
unique maximum value at
<pre>
x = k/n.
</pre>
</p>
<p>
For any point x, (including points outside [0,1]), the basis polynomials
for an arbitrary value of n sum to 1:
<pre>
sum ( 1 <= k <= n ) B(n,k)(x) = 1
</pre>
</p>
<p>
For 0 < n, the Bernstein basis polynomial can be written as a combination
of two lower degree basis polynomials:
<pre>
B(n,k)(x) = ( 1 - x ) * B(n-1,k)(x) + x * B(n-1,k-1)(x) +
</pre>
where, if k is 0, the factor B(n-1,k-1)(x) is taken to be 0,
and if k is n, the factor B(n-1,k)(x) is taken to be 0.
</p>
<p>
A Bernstein basis polynomial can be written as a combination
of two higher degree basis polynomials:
<pre>
B(n,k)(x) = ( (n+1-k) * B(n+1,k)(x) + (k+1) * B(n+1,k+1)(x) ) / ( n + 1 )
</pre>
</p>
<p>
The derivative of B(n,k)(x) can be written as:
<pre>
d/dx B(n,k)(x) = n * B(n-1,k-1)(x) - B(n-1,k)(x)
</pre>
</p>
<p>
A Bernstein polynomial can be written in terms of the standard power basis:
<pre>
B(n,k)(x) = sum ( k <= i <= n ) (-1)^(i-k) * C(n,k) * C(i,k) * x^i
</pre>
</p>
<p>
A power basis monomial can be written in terms of the Bernstein basis
of degree n where k <= n:
<pre>
x^k = sum ( k-1 <= i <= n-1 ) C(i,k) * B(n,k)(x) / C(n,k)
</pre>
</p>
<p>
Over the interval [0,1], the n-th degree Bernstein approximation polynomial to
a function f(x) is defined by
<pre>
BA(n,f)(x) = sum ( 0 <= k <= n ) f(k/n) * B(n,k)(x)
</pre>
As a function of n, the Bernstein approximation polynomials form a sequence
that slowly, but uniformly, converges to f(x) over [0,1].
</p>
<p>
By a simple linear process, the Bernstein basis polynomials can be shifted
to an arbitrary interval [a,b], retaining their properties.
</p>
<h3 align = "center">
Licensing:
</h3>
<p>
The computer code and data files described and made available on this
web page are distributed under
<a href = "../../txt/gnu_lgpl.txt">the GNU LGPL license.</a>
</p>
<h3 align = "center">
Languages:
</h3>
<p>
<b>BERNSTEIN_POLYNOMIAL</b> is available in
<a href = "../../c_src/bernstein_polynomial/bernstein_polynomial.html">a C version</a> and
<a href = "../../cpp_src/bernstein_polynomial/bernstein_polynomial.html">a C++ version</a> and
<a href = "../../f77_src/bernstein_polynomial/bernstein_polynomial.html">a FORTRAN77 version</a> and
<a href = "../../f_src/bernstein_polynomial/bernstein_polynomial.html">a FORTRAN90 version</a> and
<a href = "../../m_src/bernstein_polynomial/bernstein_polynomial.html">a MATLAB version</a>.
</p>
<h3 align = "center">
Related Data and Programs:
</h3>
<p>
<a href = "../../cpp_src/chebyshev/chebyshev.html">
CHEBYSHEV</a>,
a C++ library which
computes the Chebyshev interpolant/approximant to a given function
over an interval.
</p>
<p>
<a href = "../../cpp_src/divdif/divdif.html">
DIVDIF</a>,
a C++ library which
uses divided differences to interpolate data.
</p>
<p>
<a href = "../../cpp_src/hermite/hermite.html">
HERMITE</a>,
a C++ library which
computes the Hermite interpolant, a polynomial that matches function values
and derivatives.
</p>
<p>
<a href = "../../cpp_src/hermite_cubic/hermite_cubic.html">
HERMITE_CUBIC</a>,
a C++ library which
can compute the value, derivatives or integral of a Hermite cubic polynomial,
or manipulate an interpolating function made up of piecewise Hermite cubic
polynomials.
</p>
<p>
<a href = "../../cpp_src/lobatto_polynomial/lobatto_polynomial.html">
LOBATTO_POLYNOMIAL</a>,
a C++ library which
evaluates Lobatto polynomials, similar to Legendre polynomials
except that they are zero at both endpoints.
</p>
<p>
<a href = "../../cpp_src/spline/spline.html">
SPLINE</a>,
a C++ library which
constructs and evaluates spline interpolants and approximants.
</p>
<p>
<a href = "../../cpp_src/test_approx/test_approx.html">
TEST_APPROX</a>,
a C++ library which
defines test problems for approximation,
provided as a set of (x,y) data.
</p>
<p>
<a href = "../../cpp_src/test_interp_1d/test_interp_1d.html">
TEST_INTERP_1D</a>,
a C++ library which
defines test problems for interpolation of data y(x),
depending on a 1D argument.
</p>
<h3 align = "center">
Reference:
</h3>
<p>
<ol>
<li>
Kenneth Joy,<br>
"Bernstein Polynomials",<br>
On-Line Geometric Modeling Notes,<br>
idav.ucdavis.edu/education/CAGDNotes/Bernstein-Polynomials.pdf
</li>
<li>
David Kahaner, Cleve Moler, Steven Nash,<br>
Numerical Methods and Software,<br>
Prentice Hall, 1989,<br>
ISBN: 0-13-627258-4,<br>
LC: TA345.K34.
</li>
<li>
Josef Reinkenhof,<br>
Differentiation and integration using Bernstein's polynomials,<br>
International Journal of Numerical Methods in Engineering,<br>
Volume 11, Number 10, 1977, pages 1627-1630.
</li>
</ol>
</p>
<h3 align = "center">
Source Code:
</h3>
<p>
<ul>
<li>
<a href = "bernstein_polynomial.cpp">bernstein_polynomial.cpp</a>, the source code.
</li>
<li>
<a href = "bernstein_polynomial.hpp">bernstein_polynomial.hpp</a>, the include file.
</li>
<li>
<a href = "bernstein_polynomial.sh">bernstein_polynomial.sh</a>,
BASH commands to compile the source code.
</li>
</ul>
</p>
<h3 align = "center">
Examples and Tests:
</h3>
<p>
<ul>
<li>
<a href = "bernstein_polynomial_prb.cpp">bernstein_polynomial_prb.cpp</a>,
a sample calling program.
</li>
<li>
<a href = "bernstein_polynomial_prb.sh">bernstein_polynomial_prb.sh</a>,
BASH commands to compile and run the sample program.
</li>
<li>
<a href = "bernstein_polynomial_prb_output.txt">bernstein_polynomial_prb_output.txt</a>,
the output file.
</li>
</ul>
</p>
<h3 align = "center">
List of Routines:
</h3>
<p>
<ul>
<li>
<b>BERNSTEIN_MATRIX</b> returns the Bernstein matrix.
</li>
<li>
<b>BERNSTEIN_MATRIX_INVERSE</b> returns the inverse Bernstein matrix.
</li>
<li>
<b>BERNSTEIN_POLY_01</b> evaluates the Bernstein polynomials based in [0,1].
</li>
<li>
<b>BERNSTEIN_POLY_01_VALUES</b> returns some values of the Bernstein polynomials.
</li>
<li>
<b>BERNSTEIN_POLY_AB</b> evaluates at X the Bernstein polynomials based in [A,B].
</li>
<li>
<b>BERNSTEIN_POLY_AB_APPROX:</b> Bernstein approximant to F(X) on [A,B].
</li>
<li>
<b>I4_MAX</b> returns the maximum of two I4's.
</li>
<li>
<b>I4_MIN</b> returns the minimum of two I4's.
</li>
<li>
<b>R8_ABS</b> returns the absolute value of an R8.
</li>
<li>
<b>R8_CHOOSE</b> computes the binomial coefficient C(N,K) as an R8.
</li>
<li>
<b>R8_MAX</b> returns the maximum of two R8's.
</li>
<li>
<b>R8_MOP</b> returns the I-th power of -1 as an R8 value.
</li>
<li>
<b>R8_UNIFORM_01</b> returns a unit pseudorandom R8.
</li>
<li>
<b>R8MAT_IS_IDENTITY</b> determines if an R8MAT is the identity.
</li>
<li>
<b>R8MAT_MM_NEW</b> multiplies two matrices.
</li>
<li>
<b>R8MAT_NORM_FRO</b> returns the Frobenius norm of an R8MAT.
</li>
<li>
<b>R8MAT_PRINT</b> prints an R8MAT.
</li>
<li>
<b>R8MAT_PRINT_SOME</b> prints some of an R8MAT.
</li>
<li>
<b>R8VEC_DOT_PRODUCT</b> computes the dot product of a pair of R8VEC's.
</li>
<li>
<b>R8VEC_LINSPACE_NEW</b> creates a vector of linearly spaced values.
</li>
<li>
<b>R8VEC_SUM</b> returns the sum of an R8VEC.
</li>
<li>
<b>TIMESTAMP</b> prints the current YMDHMS date as a time stamp.
</li>
</ul>
</p>
<p>
You can go up one level to <a href = "../cpp_src.html">
the C++ source codes</a>.
</p>
<hr>
<i>
Last revised on 13 May 2013.
</i>
<!-- John Burkardt -->
</body>
<!-- Initial HTML skeleton created by HTMLINDEX. -->
</html>