Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Library functions to compute QR decomposition of a given matrix. More...
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
Functions | |
void | print_matrix (double **A, int M, int N) |
function to display matrix on stdout | |
double | vector_dot (double *a, double *b, int L) |
Compute dot product of two vectors of equal lengths. | |
double | vector_mag (double *vector, int L) |
Compute magnitude of vector. | |
double * | vector_proj (double *a, double *b, double *out, int L) |
Compute projection of vector \(\vec{a}\) on \(\vec{b}\) defined as. | |
double * | vector_sub (double *a, double *b, double *out, int L) |
Compute vector subtraction. | |
void | qr_decompose (double **A, double **Q, double **R, int M, int N) |
Decompose matrix \(A\) using Gram-Schmidt process. | |
Library functions to compute QR decomposition of a given matrix.
void print_matrix | ( | double ** | A, |
int | M, | ||
int | N | ||
) |
function to display matrix on stdout
A | matrix to print |
M | number of rows of matrix |
N | number of columns of matrix |
void qr_decompose | ( | double ** | A, |
double ** | Q, | ||
double ** | R, | ||
int | M, | ||
int | N | ||
) |
Decompose matrix \(A\) using Gram-Schmidt process.
\begin{eqnarray*} \text{given that}\quad A &=& *\left[\mathbf{a}_1,\mathbf{a}_2,\ldots,\mathbf{a}_{N-1},\right]\\ \text{where}\quad\mathbf{a}_i &=& *\left[a_{0i},a_{1i},a_{2i},\ldots,a_{(M-1)i}\right]^T\quad\ldots\mbox{(column *vectors)}\\ \text{then}\quad\mathbf{u}_i &=& \mathbf{a}_i *-\sum_{j=0}^{i-1}\text{proj}_{\mathbf{u}_j}\mathbf{a}_i\\ \mathbf{e}_i &=&\frac{\mathbf{u}_i}{\left|\mathbf{u}_i\right|}\\ Q &=& \begin{bmatrix}\mathbf{e}_0 & \mathbf{e}_1 & \mathbf{e}_2 & \dots & *\mathbf{e}_{N-1}\end{bmatrix}\\ R &=& \begin{bmatrix}\langle\mathbf{e}_0\,,\mathbf{a}_0\rangle & *\langle\mathbf{e}_1\,,\mathbf{a}_1\rangle & *\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots \\ 0 & \langle\mathbf{e}_1\,,\mathbf{a}_1\rangle & *\langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\ 0 & 0 & \langle\mathbf{e}_2\,,\mathbf{a}_2\rangle & \dots\\ \vdots & \vdots & \vdots & \ddots \end{bmatrix}\\ \end{eqnarray*}
A | input matrix to decompose |
Q | output decomposed matrix |
R | output decomposed matrix |
M | number of rows of matrix A |
N | number of columns of matrix A |
double vector_dot | ( | double * | a, |
double * | b, | ||
int | L | ||
) |
Compute dot product of two vectors of equal lengths.
If \(\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\) and \(\vec{b}=\left[b_0,b_1,b_1,...,b_L\right]\) then \(\vec{a}\cdot\vec{b}=\displaystyle\sum_{i=0}^L a_i\times b_i\)
double vector_mag | ( | double * | vector, |
int | L | ||
) |
Compute magnitude of vector.
If \(\vec{a}=\left[a_0,a_1,a_2,...,a_L\right]\) then \(\left|\vec{a}\right|=\sqrt{\displaystyle\sum_{i=0}^L a_i^2}\)
double * vector_proj | ( | double * | a, |
double * | b, | ||
double * | out, | ||
int | L | ||
) |
Compute projection of vector \(\vec{a}\) on \(\vec{b}\) defined as.
\[\text{proj}_\vec{b}\vec{a}=\frac{\vec{a}\cdot\vec{b}}{\left|\vec{b}\right|^2}\vec{b}\]
check for division by zero
double * vector_sub | ( | double * | a, |
double * | b, | ||
double * | out, | ||
int | L | ||
) |
Compute vector subtraction.
\(\vec{c}=\vec{a}-\vec{b}\)
a | minuend |
b | subtrahend |
out | resultant vector |
L | length of vectors |