Miscellaneous functions and classes.


Classes

struct  Sparse
 Sparse Matrix structure. More...

Typedefs

typedef double(* fx_t )(double x, void *data)
 Function-callback that is passed to gauss_kronrod15.

Functions

double ipow (double x, int p)
 Power function.
int gauss (double *A, double *b, double *x, int n)
 The Gauss method.
double trapezoid_integral (int k, int n, double k1, double b1, double k2, double b2, double x1, double x3)
 Take the integral of $x^k y^n$ over trapezoid.
double trapezoid_integral_cos (int k, int n, double k1, double b1, double k2, double b2, double x1, double x3)
 Take the integral of $x^k y^n cos(x)$ over trapezoid.
double trapezoid_integral_sin (int k, int n, double k1, double b1, double k2, double b2, double x1, double x3)
 Take the integral of $x^k y^n sin(x)$ over trapezoid.
double trapezoid_integral_1_cos (int k, int n, double k1, double b1, double k2, double b2, double x1, double x3)
 Take the integral of $x^k y^n / cos(x)$ over trapezoid.
void mat_print (const double *A, int n)
 Print NxN matrix to stdout.
void vec_print (const double *A, int n)
 Print vector to stdout.
void mat_mult_vector (double *r, const double *A, const double *x, int n)
 Product of NxN matrix and vector.
void sparse_mult_vector_l (double *r, const struct Sparse *A, const double *x, int n)
 If matrix is stored by columns then left multiply by vector: r = x A If matrix is stored by rows then right multiply by vector: r = A x.
void sparse_mult_vector_r (double *r, const struct Sparse *A, const double *x, int n)
 If matrix is stored by columns then right multiply by vector: r = A x If matrix is stored by rows then left multiply by vector: r = x A.
void sparse_print (const struct Sparse *A, int n, FILE *f)
 Print sparse matrix to file.
void vec_sum1 (double *r, const double *a, const double *b, double k1, double k2, int n)
 Linear combination of two vectors.
void vec_mult_scalar (double *a, const double *b, double k, int n)
 Product of vector by number.
void vec_sum (double *r, const double *a, const double *b, int n)
 Sum of two vectors.
double vec_norm2 (const double *v, int n)
 Vector norm.
double vec_scalar2 (const double *a, const double *b, int n)
 Inner product of two vectors.
void vec_mult (double *r, const double *a, const double *b, int n)
 Element by element vector multiplication.
void vec_diff (double *r, const double *a, const double *b, int n)
 Difference of two vectors.
double get_full_time ()
 Returns the number of seconds since epoch.
double gauss_kronrod15 (double a, double b, fx_t fm, void *data)
 Gauss Kronrod quadrature formula.
void set_fpe_except ()
 Sets FPU exceptions.

Typedef Documentation

typedef double(* fx_t)(double x, void *data)

Function-callback that is passed to gauss_kronrod15.

Parameters:
x - function argument
data - user data
Returns:
the value of f(x)

Definition at line 327 of file util.h.


Function Documentation

int gauss ( double *  A,
double *  b,
double *  x,
int  n 
)

The Gauss method.

Solves a linear system Ax=b.

Parameters:
A - the matrix of the system.
b - the right part.
x - the answer.
n - dimension.
Returns:
0 on success.

Definition at line 76 of file util.cpp.

double gauss_kronrod15 ( double  a,
double  b,
fx_t  fm,
void *  data 
)

Gauss Kronrod quadrature formula.

http://en.wikipedia.org/wiki/Gauss-Kronrod_quadrature

Parameters:
a 
b 
fm - function
data - the user data that are passed to the function
Returns:
the integral of fm over the segment [a, b]

Definition at line 99 of file quadrature.c.

double get_full_time (  ) 

Returns the number of seconds since epoch.

Returns:
the number of seconds since epoch.

Definition at line 543 of file util.cpp.

double ipow ( double  x,
int  p 
) [inline]

Power function.

Parameters:
x - value
p - power
Returns:
the value of x raised to the power of p
Examples:
test_baroclin.cpp, test_barvortex.cpp, test_schafe.cpp, and test_slaplace.cpp.

Definition at line 70 of file util.h.

void mat_mult_vector ( double *  r,
const double *  A,
const double *  x,
int  n 
)

Product of NxN matrix and vector.

Parameters:
r - output vector, r = Ax
A - intput matrix
x - input vector
n - dimension of matrix and vector

Definition at line 285 of file util.cpp.

void mat_print ( const double *  A,
int  n 
)

Print NxN matrix to stdout.

Parameters:
A - matrix
n - dimension

Definition at line 267 of file util.cpp.

void sparse_mult_vector_l ( double *  r,
const struct Sparse A,
const double *  x,
int  n 
)

If matrix is stored by columns then left multiply by vector: r = x A If matrix is stored by rows then right multiply by vector: r = A x.

Parameters:
r - output vector
A - sparse matrix
x - intput vector
n - the size of vector and matrix

Definition at line 296 of file util.cpp.

void sparse_mult_vector_r ( double *  r,
const struct Sparse A,
const double *  x,
int  n 
)

If matrix is stored by columns then right multiply by vector: r = A x If matrix is stored by rows then left multiply by vector: r = x A.

Parameters:
r - output vector
A - sparse matrix
x - intput vector
n - the size of vector and matrix

Definition at line 313 of file util.cpp.

void sparse_print ( const struct Sparse A,
int  n,
FILE *  f 
)

Print sparse matrix to file.

Parameters:
A - input sparse matrix
n - dimension of sparse matrix
f - output file

Definition at line 403 of file util.cpp.

double trapezoid_integral ( int  k,
int  n,
double  k1,
double  b1,
double  k2,
double  b2,
double  x1,
double  x3 
)

Take the integral of $x^k y^n$ over trapezoid.

y=k1x+b1 y=k2x+b2 - bounding lines. x belongs to segment [x1, x3].

\[ \int_{x_1}^{x_3}\int_{k_1 x+b_1}^{k_2 x+b_2} x^k y ^n dx dy \]

Parameters:
k - power
n - power
k1 - coefficient
b1 - coefficient
k2 - coefficient
b2 - coefficient
x1 - the begging of segment
x3 - the end of segment

Definition at line 179 of file util.cpp.

double trapezoid_integral_1_cos ( int  k,
int  n,
double  k1,
double  b1,
double  k2,
double  b2,
double  x1,
double  x3 
)

Take the integral of $x^k y^n / cos(x)$ over trapezoid.

\[ \int_{x_1}^{x_3}\int_{k_1 x+b_1}^{k_2 x+b_2} \frac{x^k y ^n}{cos(x)} dx dy \]

Parameters:
k - power
n - power
k1 - coefficient
b1 - coefficient
k2 - coefficient
b2 - coefficient
x1 - the begging of segment
x3 - the end of segment

Definition at line 258 of file util.cpp.

double trapezoid_integral_cos ( int  k,
int  n,
double  k1,
double  b1,
double  k2,
double  b2,
double  x1,
double  x3 
)

Take the integral of $x^k y^n cos(x)$ over trapezoid.

\[ \int_{x_1}^{x_3}\int_{k_1 x+b_1}^{k_2 x+b_2} x^k y ^n cos(x) dx dy \]

Parameters:
k - power
n - power
k1 - coefficient
b1 - coefficient
k2 - coefficient
b2 - coefficient
x1 - the begging of segment
x3 - the end of segment

Definition at line 234 of file util.cpp.

double trapezoid_integral_sin ( int  k,
int  n,
double  k1,
double  b1,
double  k2,
double  b2,
double  x1,
double  x3 
)

Take the integral of $x^k y^n sin(x)$ over trapezoid.

\[ \int_{x_1}^{x_3}\int_{k_1 x+b_1}^{k_2 x+b_2} x^k y ^n sin(x) dx dy \]

Parameters:
k - power
n - power
k1 - coefficient
b1 - coefficient
k2 - coefficient
b2 - coefficient
x1 - the begging of segment
x3 - the end of segment

Definition at line 246 of file util.cpp.

void vec_diff ( double *  r,
const double *  a,
const double *  b,
int  n 
)

Difference of two vectors.

Parameters:
r - the output vector
a - the input vector
b - the input vector
n - the dimension of vectors
Returns:
r = a - b

Definition at line 372 of file util.cpp.

void vec_mult ( double *  r,
const double *  a,
const double *  b,
int  n 
)

Element by element vector multiplication.

r = a * b

Parameters:
r - output vector
a - input vector
b - input vector
n - dimension of vectors

Definition at line 348 of file util.cpp.

void vec_mult_scalar ( double *  a,
const double *  b,
double  k,
int  n 
)

Product of vector by number.

Parameters:
a - output vector
b - input vector
k - input number
n - dimension of vector
Returns:
a = b * k

Definition at line 360 of file util.cpp.

double vec_norm2 ( const double *  v,
int  n 
)

Vector norm.

\[ \sqrt{\sum_{i=0}v_i^2} \]

Parameters:
v - input vector
n - dimension of vector
Returns:
vector norm

Definition at line 381 of file util.cpp.

void vec_print ( const double *  A,
int  n 
)

Print vector to stdout.

Parameters:
A - vector
n - dimension

Definition at line 277 of file util.cpp.

double vec_scalar2 ( const double *  a,
const double *  b,
int  n 
)

Inner product of two vectors.

\[ \sum_{i=0}^{n}a_i b_i \]

Parameters:
a - input vector
b - input vector
n - dimension of vectors
Returns:
inner product of a and b

Definition at line 392 of file util.cpp.

void vec_sum ( double *  r,
const double *  a,
const double *  b,
int  n 
)

Sum of two vectors.

Parameters:
r - output vector
a - input vector
b - input vector
n - dimension of vectors
Returns:
r = a + b

Definition at line 339 of file util.cpp.

void vec_sum1 ( double *  r,
const double *  a,
const double *  b,
double  k1,
double  k2,
int  n 
)

Linear combination of two vectors.

Parameters:
r - output vector
a - input vector
b - input vector
k1 - coefficient
k2 - coefficient
n - dimension of vectors
Returns:
r = k1 * a + k2 * b

Definition at line 330 of file util.cpp.


Phelm Library
Copyright © 2009 Alexey Ozeritsky. All rights reserved.
http://resetius.ru