TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Gram Schmidt Orthogonalisation Process More...
#include <array>
#include <cassert>
#include <cmath>
#include <iostream>
#include "math.h"
Go to the source code of this file.
Namespaces | |
namespace | numerical_methods |
for assert | |
namespace | gram_schmidt |
Functions for Gram Schmidt Orthogonalisation Process | |
Functions | |
double | numerical_methods::gram_schmidt::dot_product (const std::array< double, 10 > &x, const std::array< double, 10 > &y, const int &c) |
double | numerical_methods::gram_schmidt::projection (const std::array< double, 10 > &x, const std::array< double, 10 > &y, const int &c) |
void | numerical_methods::gram_schmidt::display (const int &r, const int &c, const std::array< std::array< double, 10 >, 20 > &B) |
void | numerical_methods::gram_schmidt::gram_schmidt (int r, const int &c, const std::array< std::array< double, 10 >, 20 > &A, std::array< std::array< double, 10 >, 20 > B) |
static void | test () |
int | main () |
Main Function. | |
Gram Schmidt Orthogonalisation Process
Takes the input of Linearly Independent Vectors, returns vectors orthogonal to each other.
Take the first vector of given LI vectors as first vector of Orthogonal vectors. Take projection of second input vector on the first vector of Orthogonal vector and subtract it from the 2nd LI vector. Take projection of third vector on the second vector of Othogonal vectors and subtract it from the 3rd LI vector. Keep repeating the above process until all the vectors in the given input array are exhausted.
For Example: In R2, Input LI Vectors={(3,1),(2,2)} then Orthogonal Vectors= {(3, 1),(-0.4, 1.2)}
Have defined maximum dimension of vectors to be 10 and number of vectors taken is 20. Please do not give linearly dependent vectors
Definition in file gram_schmidt.cpp.
void numerical_methods::gram_schmidt::display | ( | const int & | r, |
const int & | c, | ||
const std::array< std::array< double, 10 >, 20 > & | B ) |
Function to print the orthogonalised vector
r | number of vectors |
c | dimenaion of vectors |
B | stores orthogonalised vectors |
Definition at line 101 of file gram_schmidt.cpp.
double numerical_methods::gram_schmidt::dot_product | ( | const std::array< double, 10 > & | x, |
const std::array< double, 10 > & | y, | ||
const int & | c ) |
Dot product function. Takes 2 vectors along with their dimension as input and returns the dot product.
x | vector 1 |
y | vector 2 |
c | dimension of the vectors |
Definition at line 59 of file gram_schmidt.cpp.
void numerical_methods::gram_schmidt::gram_schmidt | ( | int | r, |
const int & | c, | ||
const std::array< std::array< double, 10 >, 20 > & | A, | ||
std::array< std::array< double, 10 >, 20 > | B ) |
Function for the process of Gram Schimdt Process
r | number of vectors |
c | dimension of vectors |
A | stores input of given LI vectors |
B | stores orthogonalised vectors |
we check whether appropriate dimensions are given or not.
First vector is copied as it is.
array to store projections
First initialised to zero
to store previous projected array
to store the factor by which the previous array will change
projected array created
we take the projection with all the previous vector and add them.
subtract total projection vector from the input vector
Definition at line 121 of file gram_schmidt.cpp.
int main | ( | void | ) |
Main Function.
a 2-D array for storing all vectors
a 2-D array for storing orthogonalised vectors
storing vectors in array A
Input of vectors is taken
To check whether vectors are orthogonal or not
take make the process numerically stable, upper bound for the dot product take 0.1
Definition at line 248 of file gram_schmidt.cpp.
double numerical_methods::gram_schmidt::projection | ( | const std::array< double, 10 > & | x, |
const std::array< double, 10 > & | y, | ||
const int & | c ) |
Projection Function Takes input of 2 vectors along with their dimension and evaluates their projection in temp
x | Vector 1 |
y | Vector 2 |
c | dimension of each vector |
The dot product of two vectors is taken
The norm of the second vector is taken.
multiply that factor with every element in a 3rd vector, whose initial values are same as the 2nd vector.
Definition at line 79 of file gram_schmidt.cpp.
|
static |
Test Function. Process has been tested for 3 Sample Inputs
Definition at line 181 of file gram_schmidt.cpp.