Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
numerical_methods Namespace Reference

for assert More...

Functions

double babylonian_method (double radicand)
 Babylonian methods is an iterative function which returns square root of radicand.
 
std::complex< double > * FastFourierTransform (std::complex< double > *p, uint8_t n)
 FastFourierTransform is a recursive function which returns list of complex numbers.
 
std::complex< double > * InverseFastFourierTransform (std::complex< double > *p, uint8_t n)
 InverseFastFourierTransform is a recursive function which returns list of complex numbers.
 

Detailed Description

for assert

Numerical Methods.

for std::map container

for std::vector

for io operations

for math functions

for IO operations

Numerical algorithms/methods

for assert for integer allocation for std::atof for std::function for IO operations for std::map container

Numerical algorithms/methods

for math operations

Numerical methods

for assert for mathematical-related functions for storing points and coefficents for IO operations

Numerical algorithms/methods

for std::array for assert for fabs

Numerical Methods algorithms

for assert for math functions for integer allocation for std::atof for std::function for IO operations

Numerical algorithms/methods

Function Documentation

◆ babylonian_method()

double numerical_methods::babylonian_method ( double radicand)

Babylonian methods is an iterative function which returns square root of radicand.

Parameters
radicandis the radicand
Returns
x1 the square root of radicand

To find initial root or rough approximation

Real Initial value will be i-1 as loop stops on +1 value

Storing previous value for comparison

Storing calculated value for comparison

Temp variable to x0 and x1

Newly calculated root

Returning final root

30 {
31 int i = 1; /// To find initial root or rough approximation
32
33 while (i * i <= radicand) {
34 i++;
35 }
36
37 i--; /// Real Initial value will be i-1 as loop stops on +1 value
38
39 double x0 = i; /// Storing previous value for comparison
40 double x1 =
41 (radicand / x0 + x0) / 2; /// Storing calculated value for comparison
42 double temp = NAN; /// Temp variable to x0 and x1
43
44 while (std::max(x0, x1) - std::min(x0, x1) < 0.0001) {
45 temp = (radicand / x1 + x1) / 2; /// Newly calculated root
46 x0 = x1;
47 x1 = temp;
48 }
49
50 return x1; /// Returning final root
51}
T max(T... args)
T min(T... args)
Here is the call graph for this function:

◆ FastFourierTransform()

std::complex< double > * numerical_methods::FastFourierTransform ( std::complex< double > * p,
uint8_t n )

FastFourierTransform is a recursive function which returns list of complex numbers.

Parameters
pList of Coefficents in form of complex numbers
nCount of elements in list p
Returns
p if n==1
y if n!=1

Base Case To return

Declaring value of pi

Calculating value of omega

Coefficients of even power

Coefficients of odd power

Assigning values of even Coefficients

Assigning value of odd Coefficients

Recursive Call

Recursive Call

Final value representation list

Updating the first n/2 elements

Updating the last n/2 elements

Deleting dynamic array ye

Deleting dynamic array yo

41 {
42 if (n == 1) {
43 return p; /// Base Case To return
44 }
45
46 double pi = 2 * asin(1.0); /// Declaring value of pi
47
49 cos(2 * pi / n), sin(2 * pi / n)); /// Calculating value of omega
50
51 auto *pe = new std::complex<double>[n / 2]; /// Coefficients of even power
52
53 auto *po = new std::complex<double>[n / 2]; /// Coefficients of odd power
54
55 int k1 = 0, k2 = 0;
56 for (int j = 0; j < n; j++) {
57 if (j % 2 == 0) {
58 pe[k1++] = p[j]; /// Assigning values of even Coefficients
59
60 } else {
61 po[k2++] = p[j]; /// Assigning value of odd Coefficients
62 }
63 }
64
66 FastFourierTransform(pe, n / 2); /// Recursive Call
67
69 FastFourierTransform(po, n / 2); /// Recursive Call
70
71 auto *y = new std::complex<double>[n]; /// Final value representation list
72
73 k1 = 0, k2 = 0;
74
75 for (int i = 0; i < n / 2; i++) {
76 y[i] =
77 ye[k1] + pow(om, i) * yo[k2]; /// Updating the first n/2 elements
78 y[i + n / 2] =
79 ye[k1] - pow(om, i) * yo[k2]; /// Updating the last n/2 elements
80
81 k1++;
82 k2++;
83 }
84
85 if (n != 2) {
86 delete[] pe;
87 delete[] po;
88 }
89
90 delete[] ye; /// Deleting dynamic array ye
91 delete[] yo; /// Deleting dynamic array yo
92 return y;
93}
std::complex< double > * FastFourierTransform(std::complex< double > *p, uint8_t n)
FastFourierTransform is a recursive function which returns list of complex numbers.
Definition fast_fourier_transform.cpp:41
T pow(T... args)
Here is the call graph for this function:

◆ InverseFastFourierTransform()

std::complex< double > * numerical_methods::InverseFastFourierTransform ( std::complex< double > * p,
uint8_t n )

InverseFastFourierTransform is a recursive function which returns list of complex numbers.

Parameters
pList of Coefficents in form of complex numbers
nCount of elements in list p
Returns
p if n==1
y if n!=1

Base Case To return

Declaring value of pi

Calculating value of omega

One change in comparison with DFT

One change in comparison with DFT

Coefficients of even power

Coefficients of odd power

Assigning values of even Coefficients

Assigning value of odd Coefficients

Recursive Call

Recursive Call

Final value representation list

Updating the first n/2 elements

Updating the last n/2 elements

Deleting dynamic array ye

Deleting dynamic array yo

34 {
35 if (n == 1) {
36 return p; /// Base Case To return
37 }
38
39 double pi = 2 * asin(1.0); /// Declaring value of pi
40
42 cos(2 * pi / n), sin(2 * pi / n)); /// Calculating value of omega
43
44 om.real(om.real() / n); /// One change in comparison with DFT
45 om.imag(om.imag() / n); /// One change in comparison with DFT
46
47 auto *pe = new std::complex<double>[n / 2]; /// Coefficients of even power
48
49 auto *po = new std::complex<double>[n / 2]; /// Coefficients of odd power
50
51 int k1 = 0, k2 = 0;
52 for (int j = 0; j < n; j++) {
53 if (j % 2 == 0) {
54 pe[k1++] = p[j]; /// Assigning values of even Coefficients
55
56 } else {
57 po[k2++] = p[j]; /// Assigning value of odd Coefficients
58 }
59 }
60
62 InverseFastFourierTransform(pe, n / 2); /// Recursive Call
63
65 InverseFastFourierTransform(po, n / 2); /// Recursive Call
66
67 auto *y = new std::complex<double>[n]; /// Final value representation list
68
69 k1 = 0, k2 = 0;
70
71 for (int i = 0; i < n / 2; i++) {
72 y[i] =
73 ye[k1] + pow(om, i) * yo[k2]; /// Updating the first n/2 elements
74 y[i + n / 2] =
75 ye[k1] - pow(om, i) * yo[k2]; /// Updating the last n/2 elements
76
77 k1++;
78 k2++;
79 }
80
81 if (n != 2) {
82 delete[] pe;
83 delete[] po;
84 }
85
86 delete[] ye; /// Deleting dynamic array ye
87 delete[] yo; /// Deleting dynamic array yo
88 return y;
89}
T imag(T... args)
std::complex< double > * InverseFastFourierTransform(std::complex< double > *p, uint8_t n)
InverseFastFourierTransform is a recursive function which returns list of complex numbers.
Definition inverse_fast_fourier_transform.cpp:33
T real(T... args)
Here is the call graph for this function: