mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
feat: move gram_schmidt
to numerical_methods
(#1940)
Numerical methods already contains and uses linear algebra methods. Graham Schmidt doesn't need its own folder.
This commit is contained in:
parent
37a29008e6
commit
2a076c1b03
@ -36,10 +36,10 @@
|
|||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace linear_algebra
|
* @namespace numerical_methods
|
||||||
* @brief Linear Algebra algorithms
|
* @brief Numerical Methods algorithms
|
||||||
*/
|
*/
|
||||||
namespace linear_algebra {
|
namespace numerical_methods {
|
||||||
/**
|
/**
|
||||||
* @namespace gram_schmidt
|
* @namespace gram_schmidt
|
||||||
* @brief Functions for [Gram Schmidt Orthogonalisation
|
* @brief Functions for [Gram Schmidt Orthogonalisation
|
||||||
@ -173,7 +173,7 @@ void gram_schmidt(int r, const int& c,
|
|||||||
display(r, c, B); // for displaying orthogoanlised vectors
|
display(r, c, B); // for displaying orthogoanlised vectors
|
||||||
}
|
}
|
||||||
} // namespace gram_schmidt
|
} // namespace gram_schmidt
|
||||||
} // namespace linear_algebra
|
} // namespace numerical_methods
|
||||||
/**
|
/**
|
||||||
* Test Function. Process has been tested for 3 Sample Inputs
|
* Test Function. Process has been tested for 3 Sample Inputs
|
||||||
* @returns void
|
* @returns void
|
||||||
@ -183,12 +183,12 @@ static void test() {
|
|||||||
{{1, 0, 1, 0}, {1, 1, 1, 1}, {0, 1, 2, 1}}};
|
{{1, 0, 1, 0}, {1, 1, 1, 1}, {0, 1, 2, 1}}};
|
||||||
std::array<std::array<double, 10>, 20> b1 = {{0}};
|
std::array<std::array<double, 10>, 20> b1 = {{0}};
|
||||||
double dot1 = 0;
|
double dot1 = 0;
|
||||||
linear_algebra::gram_schmidt::gram_schmidt(3, 4, a1, b1);
|
numerical_methods::gram_schmidt::gram_schmidt(3, 4, a1, b1);
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
for (int j = i + 1; j < 3; ++j) {
|
for (int j = i + 1; j < 3; ++j) {
|
||||||
dot1 = fabs(
|
dot1 = fabs(
|
||||||
linear_algebra::gram_schmidt::dot_product(b1[i], b1[j], 4));
|
numerical_methods::gram_schmidt::dot_product(b1[i], b1[j], 4));
|
||||||
if (dot1 > 0.1) {
|
if (dot1 > 0.1) {
|
||||||
flag = 0;
|
flag = 0;
|
||||||
break;
|
break;
|
||||||
@ -203,12 +203,12 @@ static void test() {
|
|||||||
std::array<std::array<double, 10>, 20> a2 = {{{3, 1}, {2, 2}}};
|
std::array<std::array<double, 10>, 20> a2 = {{{3, 1}, {2, 2}}};
|
||||||
std::array<std::array<double, 10>, 20> b2 = {{0}};
|
std::array<std::array<double, 10>, 20> b2 = {{0}};
|
||||||
double dot2 = 0;
|
double dot2 = 0;
|
||||||
linear_algebra::gram_schmidt::gram_schmidt(2, 2, a2, b2);
|
numerical_methods::gram_schmidt::gram_schmidt(2, 2, a2, b2);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
for (int i = 0; i < 1; ++i) {
|
for (int i = 0; i < 1; ++i) {
|
||||||
for (int j = i + 1; j < 2; ++j) {
|
for (int j = i + 1; j < 2; ++j) {
|
||||||
dot2 = fabs(
|
dot2 = fabs(
|
||||||
linear_algebra::gram_schmidt::dot_product(b2[i], b2[j], 2));
|
numerical_methods::gram_schmidt::dot_product(b2[i], b2[j], 2));
|
||||||
if (dot2 > 0.1) {
|
if (dot2 > 0.1) {
|
||||||
flag = 0;
|
flag = 0;
|
||||||
break;
|
break;
|
||||||
@ -223,12 +223,12 @@ static void test() {
|
|||||||
std::array<std::array<double, 10>, 20> a3 = {{{1, 2, 2}, {-4, 3, 2}}};
|
std::array<std::array<double, 10>, 20> a3 = {{{1, 2, 2}, {-4, 3, 2}}};
|
||||||
std::array<std::array<double, 10>, 20> b3 = {{0}};
|
std::array<std::array<double, 10>, 20> b3 = {{0}};
|
||||||
double dot3 = 0;
|
double dot3 = 0;
|
||||||
linear_algebra::gram_schmidt::gram_schmidt(2, 3, a3, b3);
|
numerical_methods::gram_schmidt::gram_schmidt(2, 3, a3, b3);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
for (int i = 0; i < 1; ++i) {
|
for (int i = 0; i < 1; ++i) {
|
||||||
for (int j = i + 1; j < 2; ++j) {
|
for (int j = i + 1; j < 2; ++j) {
|
||||||
dot3 = fabs(
|
dot3 = fabs(
|
||||||
linear_algebra::gram_schmidt::dot_product(b3[i], b3[j], 3));
|
numerical_methods::gram_schmidt::dot_product(b3[i], b3[j], 3));
|
||||||
if (dot3 > 0.1) {
|
if (dot3 > 0.1) {
|
||||||
flag = 0;
|
flag = 0;
|
||||||
break;
|
break;
|
||||||
@ -268,14 +268,14 @@ int main() {
|
|||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
linear_algebra::gram_schmidt::gram_schmidt(r, c, A, B);
|
numerical_methods::gram_schmidt::gram_schmidt(r, c, A, B);
|
||||||
|
|
||||||
double dot = 0;
|
double dot = 0;
|
||||||
int flag = 1; /// To check whether vectors are orthogonal or not
|
int flag = 1; /// To check whether vectors are orthogonal or not
|
||||||
for (int i = 0; i < r - 1; ++i) {
|
for (int i = 0; i < r - 1; ++i) {
|
||||||
for (int j = i + 1; j < r; ++j) {
|
for (int j = i + 1; j < r; ++j) {
|
||||||
dot =
|
dot = fabs(
|
||||||
fabs(linear_algebra::gram_schmidt::dot_product(B[i], B[j], c));
|
numerical_methods::gram_schmidt::dot_product(B[i], B[j], c));
|
||||||
if (dot > 0.1) /// take make the process numerically stable, upper
|
if (dot > 0.1) /// take make the process numerically stable, upper
|
||||||
/// bound for the dot product take 0.1
|
/// bound for the dot product take 0.1
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user