// store previous polynomials to make the recursive process faster
unordered_map legendre_cache;
// Recursive function to compute the coefficients of the nth Legendre polynomial
vector legendre_polynomial(int n) { // uses Bonnet's recursion formula P_{n+1} = ( (2n+1) x P_n - n P_{n-1} )/(n+1)
// Check if the result is already in the cache
if (legendre_cache.find(n) != legendre_cache.end()) {
return legendre_cache[n];
}
// Base cases
if (n == 0) {
return { 1.0 }; // P0(x) = 1
}
if (n == 1) {
return { 1.0, 0.0 }; // P1(x) = x
}
// Get coefficients for P_(n-1) and P_(n-2)
vector Pn_minus_1 = legendre_polynomial(n - 1);
vector Pn_minus_2 = legendre_polynomial(n - 2);
// Get the sizes of the vectors to n+1
Pn_minus_1.push_back(0.0); // P_{n-1} gets multiplied by x
Pn_minus_2.insert(Pn_minus_2.begin(), 0.0); // P_{n-2} needs two leading digits
Pn_minus_2.insert(Pn_minus_2.begin(), 0.0);
// Calculate coefficients for P_n
vector Pn(n + 1, 0.0); // Initialize Pn with n+1 zeros
// Using the recurrence relation to fill coefficients
for (int k = 0; k
Подробнее здесь: [url]https://stackoverflow.com/questions/79116069/function-which-returns-coefficients-of-legendre-polynomials-not-accurate-enough[/url]
Я пытаюсь написать функцию, которая возвращает коэффициенты n-го полинома Лежандра. [code]// store previous polynomials to make the recursive process faster unordered_map legendre_cache;
// Recursive function to compute the coefficients of the nth Legendre polynomial vector legendre_polynomial(int n) { // uses Bonnet's recursion formula P_{n+1} = ( (2n+1) x P_n - n P_{n-1} )/(n+1) // Check if the result is already in the cache if (legendre_cache.find(n) != legendre_cache.end()) { return legendre_cache[n]; }
// Base cases if (n == 0) { return { 1.0 }; // P0(x) = 1 } if (n == 1) { return { 1.0, 0.0 }; // P1(x) = x }
// Get coefficients for P_(n-1) and P_(n-2) vector Pn_minus_1 = legendre_polynomial(n - 1); vector Pn_minus_2 = legendre_polynomial(n - 2);
// Get the sizes of the vectors to n+1 Pn_minus_1.push_back(0.0); // P_{n-1} gets multiplied by x Pn_minus_2.insert(Pn_minus_2.begin(), 0.0); // P_{n-2} needs two leading digits Pn_minus_2.insert(Pn_minus_2.begin(), 0.0);
// Calculate coefficients for P_n vector Pn(n + 1, 0.0); // Initialize Pn with n+1 zeros
// Using the recurrence relation to fill coefficients for (int k = 0; k
Я пытаюсь написать функцию, которая возвращает коэффициенты n-го полинома Лежандра.
// store previous polynomials to make the recursive process faster
unordered_map legendre_cache;
// Recursive function to compute the coefficients of the nth...
Я только начинаю с языка бедра AMD (ROCM) для параллелизма HPC. Я сам не очень хороший программист, просто прохожу время ...
Я видел основные примеры ROMC от Amd Github .. Я только что написал следующий пример, чтобы увидеть, как он работает,...
У меня есть mp3-файл со значением частоты дискретизации 44100, назовем его a.mp3.
Итак, я получаю продолжительность файла a. mp3 с помощью следующей команды ffprobe:
ffprobe -v error -show_entries format=duration -of...
Учитывая 1024-битный модуль и несколько длинных целых чисел, я хотел выяснить, какое из этих значений является квадратичным остатком.
Символ Лежандра должен возвращать -1,0, или 1, но мой код возвращает значения на несколько порядков больше этих.
p...