TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
chebyshev.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 Simons Foundation
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You may obtain a copy of the License at
14// https://www.gnu.org/licenses/gpl-3.0.txt
15//
16// Authors: Nils Wentzell
17
22
23#pragma once
24
25#include <nda/nda.hpp>
26
27#include <cmath>
28#include <numbers>
29
30namespace triqs::utility {
31
36
50 inline nda::vector<double> chebyshev_points(long N) {
51 nda::vector<double> points(N);
52 const double pi = std::numbers::pi;
53 for (long i = 0; i < N; ++i) {
54 // Store in ascending order (cos decreases as argument increases)
55 points[N - 1 - i] = std::cos((2.0 * static_cast<double>(i) + 1.0) * pi / (2.0 * static_cast<double>(N)));
56 }
57 return points;
58 }
59
73 inline nda::vector<double> chebyshev_barycentric_weights(long N) {
74 nda::vector<double> weights(N);
75 const double pi = std::numbers::pi;
76 for (long i = 0; i < N; ++i) {
77 // Match point ordering (ascending)
78 double sign = (i % 2 == 0) ? 1.0 : -1.0;
79 weights[N - 1 - i] = sign * std::sin((2.0 * static_cast<double>(i) + 1.0) * pi / (2.0 * static_cast<double>(N)));
80 }
81 return weights;
82 }
83
92 inline double to_standard_interval(double x, double a, double b) { return 2.0 * (x - 0.5 * (b + a)) / (b - a); }
93
102 inline double from_standard_interval(double x, double a, double b) { return 0.5 * (b - a) * x + 0.5 * (b + a); }
103
105
106} // namespace triqs::utility
nda::vector< double > chebyshev_barycentric_weights(long N)
Compute barycentric weights for Chebyshev points of the first kind.
Definition chebyshev.hpp:73
double to_standard_interval(double x, double a, double b)
Scale a value from interval to the standard interval .
Definition chebyshev.hpp:92
nda::vector< double > chebyshev_points(long N)
Compute Chebyshev points of the first kind on the interval .
Definition chebyshev.hpp:50
double from_standard_interval(double x, double a, double b)
Scale a value from the standard interval to interval .