MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_mat.h File Reference

MRTKLIB Matrix Module — Matrix/vector operations and estimation. More...

#include <stdio.h>
#include "mrtklib/mrtk_foundation.h"
Include dependency graph for mrtk_mat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void fatalfunc_t(const char *)
 Fatal callback function type for allocation failures.

Functions

void add_fatal (fatalfunc_t *func)
 Add fatal callback function for mat(), zeros(), imat().
double * mat (int n, int m)
 Allocate memory for a double matrix.
int * imat (int n, int m)
 Allocate memory for an integer matrix.
double * zeros (int n, int m)
 Allocate a new zero matrix.
double * eye (int n)
 Generate a new identity matrix.
double dot (const double *a, const double *b, int n)
 Inner product of vectors.
double norm (const double *a, int n)
 Euclidean norm of vector.
void cross3 (const double *a, const double *b, double *c)
 Cross product of 3D vectors.
int normv3 (const double *a, double *b)
 Normalize 3D vector.
void matcpy (double *A, const double *B, int n, int m)
 Copy matrix.
void matmul (const char *tr, int n, int k, int m, double alpha, const double *A, const double *B, double beta, double *C)
 Multiply matrix by matrix (C = alpha*A*B + beta*C).
int matinv (double *A, int n)
 Inverse of matrix (A = A^-1).
int solve (const char *tr, const double *A, const double *Y, int n, int m, double *X)
 Solve linear equation (X = A\Y or X = A'\Y).
int lsq (const double *A, const double *y, int n, int m, double *x, double *Q)
 Least square estimation by solving normal equation.
int filter (double *x, double *P, const double *H, const double *v, const double *R, int n, int m)
 Kalman filter state update.
int smoother (const double *xf, const double *Qf, const double *xb, const double *Qb, int n, double *xs, double *Qs)
 Combine forward and backward filters by fixed-interval smoother.
void matfprint (const double *A, int n, int m, int p, int q, FILE *fp)
 Print matrix to file pointer.
void matprint (const double *A, int n, int m, int p, int q)
 Print matrix to stdout.

Detailed Description

MRTKLIB Matrix Module — Matrix/vector operations and estimation.

This header provides matrix and vector allocation, arithmetic, linear algebra (LU decomposition, matrix inversion, linear solve), and estimation algorithms (least squares, Kalman filter, smoother).

Note
All functions in this module are pure cut-and-paste extractions from rtkcmn.c with zero algorithmic changes.

Definition in file mrtk_mat.h.

Typedef Documentation

◆ fatalfunc_t

typedef void fatalfunc_t(const char *)

Fatal callback function type for allocation failures.

Definition at line 43 of file mrtk_mat.h.

Function Documentation

◆ add_fatal()

void add_fatal ( fatalfunc_t * func)

Add fatal callback function for mat(), zeros(), imat().

Parameters
[in]funcCallback function

Definition at line 65 of file mrtk_mat.c.

References fatalfunc.

◆ cross3()

void cross3 ( const double * a,
const double * b,
double * c )

Cross product of 3D vectors.

Parameters
[in]aVector a (3 x 1)
[in]bVector b (3 x 1)
[out]cCross product a x b (3 x 1)

Definition at line 172 of file mrtk_mat.c.

Referenced by clas_osr_adjust_r_dts(), clas_osr_satcorr_update(), plane(), satantoff(), satpos_ssr(), and windupcorr().

Here is the caller graph for this function:

◆ dot()

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

Inner product of vectors.

Parameters
[in]aVector a (n x 1)
[in]bVector b (n x 1)
[in]nSize of vectors
Returns
a' * b

Definition at line 151 of file mrtk_mat.c.

Referenced by antmodel(), clas_osr_satcorr_update(), clas_stec_grid_data(), clas_trop_grid_data(), deq(), ecef2pos(), find_grid_surround_pos(), norm(), ocean_tide_clasgrid(), peph2pos(), resdop(), satazel(), satpos_ssr(), tide_pl(), toml_rtod_ex(), valsol(), and windupcorr().

Here is the caller graph for this function:

◆ eye()

double * eye ( int n)

Generate a new identity matrix.

Parameters
[in]nNumber of rows and columns
Returns
Matrix pointer (NULL if n<=0)

Definition at line 129 of file mrtk_mat.c.

References zeros().

Referenced by filter2_(), filter2_(), filter_(), lambda(), udpos(), udpos(), and udpos_ppp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filter()

int filter ( double * x,
double * P,
const double * H,
const double * v,
const double * R,
int n,
int m )

Kalman filter state update.

K=P*H*(H'*P*H+R)^-1, xp=x+K*v, Pp=(I-K*H')*P

Parameters
[in,out]xStates vector (n x 1)
[in,out]PCovariance matrix of states (n x n)
[in]HTranspose of design matrix (n x m)
[in]vInnovation (measurement - model) (m x 1)
[in]RCovariance matrix of measurement error (m x m)
[in]nNumber of states
[in]mNumber of measurements
Returns
Status (0:ok, <0:error)
Note
Matrix stored by column-major order (Fortran convention). If state x[i]==0.0, does not update state x[i]/P[i+i*n].

Definition at line 524 of file mrtk_mat.c.

References filter_(), free, imat(), and mat().

Referenced by holdamb(), holdamb(), holdamb(), and relpos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imat()

int * imat ( int n,
int m )

Allocate memory for an integer matrix.

Parameters
[in]nNumber of rows
[in]mNumber of columns
Returns
Matrix pointer (NULL if n<=0 or m<=0)

Definition at line 92 of file mrtk_mat.c.

References fatalerr(), and malloc.

Referenced by clas_trop_grid_data(), filter(), filter2(), filter2(), filter2_(), filter2_(), matinv(), raim_fde(), resamb_LAMBDA(), and udpos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lsq()

int lsq ( const double * A,
const double * y,
int n,
int m,
double * x,
double * Q )

Least square estimation by solving normal equation.

Solves x = (A*A')^-1 * A * y.

Parameters
[in]ATranspose of (weighted) design matrix (n x m)
[in]y(Weighted) measurements (m x 1)
[in]nNumber of parameters
[in]mNumber of measurements (n <= m)
[out]xEstimated parameters (n x 1)
[out]QEstimated parameters covariance matrix (n x n)
Returns
Status (0:ok, <0:error)
Note
For weighted least square, replace A and y by A*w and w*y (w=W^(1/2)). Matrix stored by column-major order (Fortran convention).

Definition at line 470 of file mrtk_mat.c.

References free, mat(), matinv(), and matmul().

Referenced by estpos(), and estvel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mat()

double * mat ( int n,
int m )

Allocate memory for a double matrix.

Parameters
[in]nNumber of rows
[in]mNumber of columns
Returns
Matrix pointer (NULL if n<=0 or m<=0)

Definition at line 76 of file mrtk_mat.c.

References fatalerr(), and malloc.

Referenced by calc_3points_weight(), clas_get_grid_index(), clas_ssr2osr(), clas_stec_grid_data(), clas_trop_grid_data(), ddres(), ddres(), ddres(), estpos(), estvel(), filter(), filter2(), filter2(), filter2_(), filter2_(), filter_(), holdamb(), holdamb(), holdamb(), lambda(), lambda_reduction(), lambda_search(), LD(), lsq(), ludcmp(), matinv(), pntpos(), ppp_rtk_pos(), raim_fde(), relpos(), relposvrs(), resamb_LAMBDA(), resamb_LAMBDA(), resamb_LAMBDA(), sddop(), sddop(), search(), smoother(), solve(), udpos(), udpos(), udpos_ppp(), zddop(), zddop(), and zeros().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ matcpy()

void matcpy ( double * A,
const double * B,
int n,
int m )

Copy matrix.

Parameters
[out]ADestination matrix (n x m)
[in]BSource matrix (n x m)
[in]nNumber of rows
[in]mNumber of columns

Definition at line 205 of file mrtk_mat.c.

Referenced by clas_get_grid_index(), decode_bdsraw(), decode_bnx_00(), decode_cnav(), decode_enav(), decode_galrawfnav(), decode_galrawinav(), decode_glorawca(), decode_gnav(), decode_ionutc(), decode_ionutc(), decode_L1ionutc(), decode_navicraw(), decode_qzssrawsubframeb(), estvel(), filter2_(), filter2_(), filter_(), matinv(), pntpos(), ppp_rtk_pos(), raim_fde(), raw2rtcm(), readpcv(), relpos(), relposvrs(), send_nmea(), setopt_apppos(), setopt_sta(), smoother(), solve(), strsvrthread(), udpos(), udpos_ppp(), and update_ionutc().

Here is the caller graph for this function:

◆ matfprint()

void matfprint ( const double * A,
int n,
int m,
int p,
int q,
FILE * fp )

Print matrix to file pointer.

Parameters
[in]AMatrix A (n x m)
[in]n,mNumber of rows and columns
[in]p,qTotal columns, columns under decimal point
[in]fpOutput file pointer
Note
Matrix stored by column-major order (Fortran convention).

◆ matinv()

int matinv ( double * A,
int n )

Inverse of matrix (A = A^-1).

Parameters
[in,out]AMatrix (n x n)
[in]nSize of matrix
Returns
Status (0:ok, <0:error)

Definition at line 421 of file mrtk_mat.c.

References free, imat(), lubksb(), ludcmp(), mat(), and matcpy().

Referenced by calc_3points_weight(), clas_get_grid_index(), dops(), filter2_(), filter2_(), filter_(), lsq(), resamb_LAMBDA(), resamb_LAMBDA(), resamb_LAMBDA(), sddop(), sddop(), smoother(), and solve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ matmul()

void matmul ( const char * tr,
int n,
int k,
int m,
double alpha,
const double * A,
const double * B,
double beta,
double * C )

Multiply matrix by matrix (C = alpha*A*B + beta*C).

Parameters
[in]trTranspose flags ("N":normal, "T":transpose)
[in]n,k,mSize of (transposed) matrix A, B
[in]alphaAlpha coefficient
[in]A,B(Transposed) matrix A (n x m), B (m x k)
[in]betaBeta coefficient
[in,out]CMatrix C (n x k)

Definition at line 310 of file mrtk_mat.c.

Referenced by calc_3points_weight(), clas_stec_grid_data(), clas_trop_grid_data(), covecef(), covenu(), dops(), ecef2enu(), eci2ecef(), enu2ecef(), filter2_(), filter2_(), filter_(), lambda(), lsq(), ocean_tide_clasgrid(), resamb_LAMBDA(), resamb_LAMBDA(), resamb_LAMBDA(), resdop(), sddop(), sddop(), smoother(), solve(), sunmoonpos(), tidedisp(), udpos(), udpos(), and udpos_ppp().

Here is the caller graph for this function:

◆ matprint()

void matprint ( const double * A,
int n,
int m,
int p,
int q )

Print matrix to stdout.

Parameters
[in]AMatrix A (n x m)
[in]n,mNumber of rows and columns
[in]p,qTotal columns, columns under decimal point

◆ norm()

double norm ( const double * a,
int n )

Euclidean norm of vector.

Parameters
[in]aVector a (n x 1)
[in]nSize of vector
Returns
|| a ||

Definition at line 165 of file mrtk_mat.c.

References dot().

Referenced by antpos(), baseline(), baseline(), baseline_len(), clas_osr_satcorr_update(), clas_osr_zdres(), clas_ssr2osr(), combpeph(), constbl(), convrnx_s(), estpos(), estvel(), find_grid_surround_pos(), geodist(), ionmodel(), ionocorr(), miono_sel_area(), normv3(), out_iono_sys(), out_leaps(), out_time_sys(), outrnxevent(), outsols(), pcv_slot_has_data(), pephpos(), pickup_candidates_of_grid(), pntpos(), posdist(), ppp_rtk_pos(), readpcv(), relposvrs(), resdop(), satpos_ssr(), send_nmea(), setopt_sta(), setpcv(), shapiro(), tide_pl(), tidedisp(), udpos(), udpos(), udpos_ppp(), windupcorr(), zdres(), and zdres().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normv3()

int normv3 ( const double * a,
double * b )

Normalize 3D vector.

Parameters
[in]aVector a (3 x 1)
[out]bNormalized vector (3 x 1), || b || = 1
Returns
Status (1:ok, 0:error)

Definition at line 183 of file mrtk_mat.c.

References norm().

Referenced by clas_osr_adjust_r_dts(), clas_osr_satcorr_update(), plane(), satantoff(), satpos_ssr(), and windupcorr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ smoother()

int smoother ( const double * xf,
const double * Qf,
const double * xb,
const double * Qb,
int n,
double * xs,
double * Qs )

Combine forward and backward filters by fixed-interval smoother.

xs=Qs*(Qf^-1*xf+Qb^-1*xb), Qs=(Qf^-1+Qb^-1)^-1

Parameters
[in]xfForward solutions (n x 1)
[in]QfForward solutions covariance matrix (n x n)
[in]xbBackward solutions (n x 1)
[in]QbBackward solutions covariance matrix (n x n)
[in]nNumber of solutions
[out]xsSmoothed solutions (n x 1)
[out]QsSmoothed solutions covariance matrix (n x n)
Returns
Status (0:ok, <0:error)
Note
Matrix stored by column-major order (Fortran convention).

Definition at line 579 of file mrtk_mat.c.

References free, mat(), matcpy(), matinv(), and matmul().

Referenced by combres().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solve()

int solve ( const char * tr,
const double * A,
const double * Y,
int n,
int m,
double * X )

Solve linear equation (X = A\Y or X = A'\Y).

Parameters
[in]trTranspose flag ("N":normal, "T":transpose)
[in]AInput matrix A (n x n)
[in]YInput matrix Y (n x m)
[in]n,mSize of matrix A, Y
[out]XSolution X = A\Y or X = A'\Y (n x m)
Returns
Status (0:ok, <0:error)
Note
Matrix stored by column-major order (Fortran convention). X can be same as Y.

Definition at line 443 of file mrtk_mat.c.

References free, mat(), matcpy(), matinv(), and matmul().

Referenced by lambda().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zeros()

double * zeros ( int n,
int m )

Allocate a new zero matrix.

Parameters
[in]nNumber of rows
[in]mNumber of columns
Returns
Matrix pointer (NULL if n<=0 or m<=0)

Definition at line 108 of file mrtk_mat.c.

References calloc, fatalerr(), and mat().

Referenced by clas_ssr2osr(), eye(), filter2(), holdamb(), holdamb(), holdamb(), lambda(), lambda_reduction(), lambda_search(), pntpos(), ppp_rtk_pos(), raim_fde(), relpos(), relposvrs(), resamb_LAMBDA(), resamb_LAMBDA(), residual_test(), residual_test(), rtkinit(), search(), set_init_pb(), set_init_pb(), udbias(), udbias_ppp(), and udbias_ppp().

Here is the call graph for this function:
Here is the caller graph for this function: