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

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

#include "mrtklib/mrtk_mat.h"
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for mrtk_mat.c:

Go to the source code of this file.

Functions

static void fatalerr (const char *format,...)
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).
static int ludcmp (double *A, int n, int *indx, double *d)
static void lubksb (const double *A, int n, const int *indx, double *b)
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.
static int filter_ (const double *x, const double *P, const double *H, const double *v, const double *R, int n, int m, double *xp, double *Pp)
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)
void matprint (const double A[], int n, int m, int p, int q)

Variables

static fatalfunc_t * fatalfunc = NULL

Detailed Description

MRTKLIB Matrix Module — Matrix/vector operations and estimation.

This file contains all matrix/vector and estimation functions extracted from rtkcmn.c with zero algorithmic changes (pure cut-and-paste).

Definition in file mrtk_mat.c.

Function Documentation

◆ add_fatal()

void add_fatal ( fatalfunc_t * func)
extern

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 )
extern

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(), model_phw(), plane(), sat_yaw(), satantoff(), satpos_ssr(), and windupcorr().

Here is the caller graph for this function:

◆ dot()

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

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(), model_phw(), norm(), ocean_tide_clasgrid(), peph2pos(), resdop(), sat_yaw(), satantpcv(), satazel(), satpos_ssr(), testeclipse(), tide_pl(), toml_rtod_ex(), valsol(), and windupcorr().

Here is the caller graph for this function:

◆ eye()

double * eye ( int n)
extern

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(), udpos_ppp(), and udpos_ppp().

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

◆ fatalerr()

void fatalerr ( const char * format,
... )
static

Definition at line 41 of file mrtk_mat.c.

References fatalfunc.

Referenced by imat(), mat(), and zeros().

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 )
extern

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(), pppos(), relpos(), and update_states().

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

◆ filter_()

int filter_ ( const double * x,
const double * P,
const double * H,
const double * v,
const double * R,
int n,
int m,
double * xp,
double * Pp )
static

Definition at line 503 of file mrtk_mat.c.

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

Referenced by filter().

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

◆ imat()

int * imat ( int n,
int m )
extern

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(), udpos(), and udpos_ppp().

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 )
extern

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:

◆ lubksb()

void lubksb ( const double * A,
int n,
const int * indx,
double * b )
static

Definition at line 400 of file mrtk_mat.c.

Referenced by matinv().

Here is the caller graph for this function:

◆ ludcmp()

int ludcmp ( double * A,
int n,
int * indx,
double * d )
static

Definition at line 345 of file mrtk_mat.c.

References free, and mat().

Referenced by matinv().

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

◆ mat()

double * mat ( int n,
int m )
extern

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_amb_ILS(), ppp_rtk_pos(), pppos(), raim_fde(), relpos(), relposvrs(), resamb_LAMBDA(), resamb_LAMBDA(), resamb_LAMBDA(), sddop(), sddop(), search(), smoother(), solve(), udpos(), udpos(), udpos_ppp(), udpos_ppp(), write_trace_sd_amb(), 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 )
extern

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(), model_trop(), pntpos(), ppp_amb_ILS(), ppp_rtk_pos(), pppos(), raim_fde(), raw2rtcm(), readpcv(), relpos(), relposvrs(), sat_yaw(), 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 )
extern

Definition at line 615 of file mrtk_mat.c.

Referenced by matprint().

Here is the caller graph for this function:

◆ matinv()

int matinv ( double * A,
int n )
extern

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 )
extern

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(), udpos_ppp(), udpos_ppp(), and write_trace_sd_amb().

Here is the caller graph for this function:

◆ matprint()

void matprint ( const double A[],
int n,
int m,
int p,
int q )
extern

Definition at line 625 of file mrtk_mat.c.

References matfprint().

Here is the call graph for this function:

◆ norm()

double norm ( const double * a,
int n )
extern

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(), decode_solsss(), estpos(), estvel(), find_grid_surround_pos(), geodist(), ionmodel(), ionocorr(), miono_sel_area(), model_phw(), normv3(), out_iono_sys(), out_leaps(), out_time_sys(), outnmea_rmc(), outrnxevent(), outsols(), pcv_slot_has_data(), pephpos(), pickup_candidates_of_grid(), pntpos(), posdist(), ppp_amb_ILS(), ppp_rtk_pos(), pppos(), readpcv(), relposvrs(), resdop(), satpos_ssr(), send_nmea(), setopt_sta(), setpcv(), shapiro(), testeclipse(), tide_pl(), tidedisp(), udpos(), udpos(), udpos_ppp(), 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 )
extern

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(), model_phw(), plane(), sat_yaw(), satantoff(), satantpcv(), satpos_ssr(), testeclipse(), 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 )
extern

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 )
extern

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 )
extern

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_amb_ILS(), ppp_rtk_pos(), pppos(), raim_fde(), relpos(), relposvrs(), resamb_LAMBDA(), resamb_LAMBDA(), residual_test(), residual_test(), rtkinit(), search(), set_init_pb(), set_init_pb(), udbias(), udbias_ppp(), udbias_ppp(), update_states(), and write_trace_sd_amb().

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

Variable Documentation

◆ fatalfunc

fatalfunc_t* fatalfunc = NULL
static

Definition at line 34 of file mrtk_mat.c.

Referenced by add_fatal(), and fatalerr().