3 #define DBL_EPSILON 2.22045e-16
5 double *
V_Zero (
double *v,
const int n)
7 for (
int i = 0; i < n; i++) {
13 double *
V_Unit (
double *v,
const int n,
const int k)
15 for (
int i = 0; i < n; i++) {
22 void V_Print (
const double *v,
const int n)
25 for (
int i = 0; i < n; i++) {
28 std::cout << std::endl;
32 void V_Print (
const double *v,
const double *w,
const int n)
35 for (
int i = 0; i < n; i++) {
36 std::cout << v[i] <<
" | " << w[i];
38 std::cout << std::endl;
51 double UNorm (
const double *A,
int n,
const int m)
54 double help, Max = 0.0;
60 if (Max < (help = fabs (*(B))))
92 for( i = 0; i < n; i++ ) {
93 for( j = i; j < n; j++ ) {
95 for( k = i-1; k >= 0; k-- )
96 sum -= A[i][k] * A[j][k];
130 void RowMult (
const double a,
double *A,
const double b,
const double *B,
const int n)
132 for (
int i = 0; i < n; i++)
133 A[i] = a*A[i] + b*B[i];
150 for (
int i = 0; i < n; i++) {
152 for (
int j = 0; j < n; j++) {
153 std::cout << A[i*n+j] <<
' ';
155 std::cout <<
']' << std::endl;
157 std::cout << std::endl;
171 void M_Print (
const double *A,
const double *B,
const int n)
174 for (
int i = 0; i < n; i++) {
176 for (
int j = 0; j < n; j++) {
177 std::cout << A[i*n+j] <<
' ';
180 for (
int j = 0; j < n; j++) {
181 std::cout << B[i*n+j] <<
' ';
183 std::cout <<
']' << std::endl;
185 std::cout << std::endl;
201 for (
int i = 0; i < n; i++) {
202 for (
int j = 0; j < n; j++) {
222 for (
int i = 0; i < n; i++) {
223 for (
int j = 0; j < n; j++) {
240 double*
M_Invert (
double *Ap,
double *Bp,
const int n)
254 double det = (Ap[0] * Ap[3]) - (Ap[1] * Ap[2]);
256 Bp[1] = -Ap[1] / det;
257 Bp[2] = -Ap[2] / det;
266 for (
int i = 1; i < n; i++) {
278 for (
int i = 2; i < n; i++) {
309 for (
int i = 0; i < n-1; i++) {
328 for (
int i = 0; i < 2; i++) {
389 for (
int i = 0; i < n; i++) {
391 for (
int j = 0; j < n; j++ ) {
397 for (
int i = 0; i < n; i++) {
398 A[i][i] = 1.0 / p[i];
399 for (
int j = i+1; j < n; j++) {
401 for (
int k = i; k < j; k++)
402 sum -= A[j][k] * A[k][i];
403 A[j][i] = sum / p[j];
407 for (
int i = 0; i < n; i++) {
408 for (
int j = i; j < n; j++) {
410 for (
int k = j; k < n; k++)
411 sum += A[k][i] * A[k][j];
412 inv[i][j] = inv[j][i] = sum;
417 for (
int i = 0; i < n; i++) {
418 for (
int j = 0; j < n; j++) {
426 std::cout <<
"Cholesky decomposition failed!" << std::endl;
443 double *
M_A_times_b (
double *y,
const double *A,
const int n,
const int m,
const double *b)
445 for (
int i = 0; i < n; i++) {
447 for (
int j = 0; j <
m; j++) {
448 y[i] += A[i*n+j] * b[j];
double * M_Invert(double *Ap, double *Bp, const int n)
Matrix inversion of Ap will be stored in Bp.
double * V_Zero(double *v, const int n)
double * M_Cholesky(double *B, double *q, const int n)
Calculates the Cholesky decomposition of the positive-definite matrix B.
double * M_InvertPos(double *B, const int n)
Calculates a*A + b*B, where both A and B are rows of length n.
double * V_Unit(double *v, const int n, int k)
double UNorm(const double *A, int n, const int m)
Calculates the least upper bound norm.
void RowMult(const double a, double *A, const double b, const double *B, const int n)
Calculates a*A + b*B, where both A and B are rows of length n, returns as A.
void M_Print(const double *A, const int n)
Print matrix A of dimension [n,n] to cout.
double * M_A_times_b(double *y, const double *A, const int n, const int m, const double *b)
Calculates y[n] = A[n,m] * b[m], with dimensions indicated.
double * M_Zero(double *A, const int n)
Creates zero matrix A.
void V_Print(const double *v, const int n)
double * M_Unit(double *A, const int n)
Creates unit matrix A.