Chebyshev.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #include <gtsam/basis/Chebyshev.h>
20 
21 namespace gtsam {
22 
35 static double scale(double x, double a, double b, double t1, double t2) {
36  return ((t2 - t1) * (x - a) / (b - a)) + t1;
37 }
38 
40  double b) {
41  Weights Tx(1, N);
42 
43  x = scale(x, a, b, -1, 1);
44 
45  Tx(0) = 1;
46  Tx(1) = x;
47  for (size_t i = 2; i < N; i++) {
48  // instead of cos(i*acos(x)), this recurrence is much faster
49  Tx(i) = 2 * x * Tx(i - 1) - Tx(i - 2);
50  }
51  return Tx;
52 }
53 
55  double b) {
57  Weights weights = Weights::Zero(N);
58  for (size_t n = 1; n < N; n++) {
59  weights(n) = n * Ux(n - 1);
60  }
61  return weights;
62 }
63 
65  double b) {
66  Weights Ux(N);
67 
68  x = scale(x, a, b, -1, 1);
69 
70  Ux(0) = 1;
71  Ux(1) = 2 * x;
72  for (size_t i = 2; i < N; i++) {
73  // instead of cos(i*acos(x)), this recurrence is much faster
74  Ux(i) = 2 * x * Ux(i - 1) - Ux(i - 2);
75  }
76  return Ux;
77 }
78 
80  double b) {
81  Weights Tx = Chebyshev1Basis::CalculateWeights(N + 1, x, a, b);
83 
84  Weights weights(N);
85 
86  x = scale(x, a, b, -1, 1);
87  if (x == -1 || x == 1) {
88  throw std::runtime_error(
89  "Derivative of Chebyshev2 Basis does not exist at range limits.");
90  }
91 
92  for (size_t n = 0; n < N; n++) {
93  weights(n) = ((n + 1) * Tx(n + 1) - x * Ux(n)) / (x * x - 1);
94  }
95  return weights;
96 }
97 
98 } // namespace gtsam
static Weights CalculateWeights(size_t N, double x, double a=-1, double b=1)
Evaluate Chebyshev Weights on [-1,1] at x up to order N-1 (N values)
Definition: Chebyshev.cpp:39
static Weights CalculateWeights(size_t N, double x, double a=-1, double b=1)
Definition: Chebyshev.cpp:64
static Weights DerivativeWeights(size_t N, double x, double a=-1, double b=1)
Evaluate Chebyshev derivative at x.
Definition: Chebyshev.cpp:79
int n
Chebyshev basis decompositions.
#define N
Definition: gksort.c:12
const G & b
Definition: Group.h:86
traits
Definition: chartTesting.h:28
static double scale(double x, double a, double b, double t1, double t2)
Scale x from [a, b] to [t1, t2].
Definition: Chebyshev.cpp:35
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
static Weights DerivativeWeights(size_t N, double x, double a=-1, double b=1)
Evaluate Chebyshev derivative at x. The derivative weights are pre-multiplied to the polynomial Param...
Definition: Chebyshev.cpp:54


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:01