Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Compute real eigen values and eigen vectors of a symmetric matrix using QR decomposition method. More...
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "qr_decompose.h"
Macros | |
#define | LIMS 9 |
limit of range of matrix values | |
#define | EPSILON 1e-10 |
accuracy tolerance limit | |
Functions | |
void | create_matrix (double **A, int N) |
create a square matrix of given size with random elements | |
double ** | mat_mul (double **A, double **B, double **OUT, int R1, int C1, int R2, int C2) |
Perform multiplication of two matrices. | |
double | eigen_values (double **A, double *eigen_vals, int mat_size, char debug_print) |
Compute eigen values using iterative shifted QR decomposition algorithm as follows: | |
void | test1 () |
test function to compute eigen values of a 2x2 matrix | |
void | test2 () |
test function to compute eigen values of a 2x2 matrix | |
int | main (int argc, char **argv) |
main function | |
Compute real eigen values and eigen vectors of a symmetric matrix using QR decomposition method.
void create_matrix | ( | double ** | A, |
int | N | ||
) |
create a square matrix of given size with random elements
[out] | A | matrix to create (must be pre-allocated in memory) |
[in] | N | matrix size |
double eigen_values | ( | double ** | A, |
double * | eigen_vals, | ||
int | mat_size, | ||
char | debug_print | ||
) |
Compute eigen values using iterative shifted QR decomposition algorithm as follows:
[in,out] | A | matrix to compute eigen values for |
[out] | eigen_vals | resultant vector containing computed eigen values |
[in] | mat_size | matrix size |
[in] | debug_print | 1 to print intermediate Q & R matrices, 0 for not to |
int main | ( | int | argc, |
char ** | argv | ||
) |
main function
double ** mat_mul | ( | double ** | A, |
double ** | B, | ||
double ** | OUT, | ||
int | R1, | ||
int | C1, | ||
int | R2, | ||
int | C2 | ||
) |
Perform multiplication of two matrices.
[in] | A | first matrix to multiply |
[in] | B | second matrix to multiply |
[out] | OUT | output matrix (must be pre-allocated) |
[in] | R1 | number of rows of first matrix |
[in] | C1 | number of columns of first matrix |
[in] | R2 | number of rows of second matrix |
[in] | C2 | number of columns of second matrix |
void test1 | ( | ) |
test function to compute eigen values of a 2x2 matrix
\[\begin{bmatrix} 5 & 7\\ 7 & 11 \end{bmatrix}\]
which are approximately, {15.56158, 0.384227}
void test2 | ( | ) |
test function to compute eigen values of a 2x2 matrix
\[\begin{bmatrix} -4& 4& 2& 0& -3\\ 4& -4& 4& -3& -1\\ 2& 4& 4& 3& -3\\ 0& -3& 3& -1&-1\\ -3& -1& -3& -3& 0 \end{bmatrix}\]
which are approximately, {9.27648, -9.26948, 2.0181, -1.03516, -5.98994}