Bsoft 2.1.4
Bernard's software package
matrix_linear.cpp File Reference

Solving sets of linear equations through matrix algebra. More...

#include "Matrix.h"
#include "utilities.h"

Functions

double linear_least_squares (int n1, int n2, double *x, double *y, double &a, double &b)
 Does a linear least squares fit between two vectors. More...
 
double linear_least_squares (int n1, int n2, vector< double > &x, vector< double > &y, double &a, double &b)
 
double fit_polynomial (int n, vector< double > &x, vector< double > &y, int order, vector< double > &coeff)
 Fits a data set to a polynomial function. More...
 
double fit_polynomial (int n, double *x, double *y, int order, double *coeff)
 Fits a data set to a polynomial function. More...
 
Vector3< double > fit_plane (Matrix a, vector< double > b)
 Solves for fitting a plane through a model. More...
 
vector< double > fit_conic (vector< Vector3< double > > v)
 Solves for fitting a conic through a model. More...
 
vector< double > fit_ellipse (vector< Vector3< double > > v)
 Solves for fitting a conic through a model. More...
 
vector< double > fit_ellipse2 (vector< Vector3< double > > v)
 Solves for fitting a conic through a model. More...
 

Variables

int verbose
 

Detailed Description

Solving sets of linear equations through matrix algebra.

Author
Bernard Heymann
Date
Created: 20000501
Modified: 20220216

Function Documentation

◆ fit_conic()

vector< double > fit_conic ( vector< Vector3< double > >  v)

Solves for fitting a conic through a model.

Parameters
vset of xy coordinates.
Returns
vector<double> 6 coefficients.
The conic is defined as:
    0 = c0 + c1*x + c2*y + c3*x2 + c4*x*y + c5*y2

◆ fit_ellipse()

vector< double > fit_ellipse ( vector< Vector3< double > >  v)

Solves for fitting a conic through a model.

Parameters
vset of xy coordinates.
Returns
vector<double> 6 coefficients.
The conic is defined as:
    0 = c0 + c1*x + c2*y + c3*x2 + c4*x*y + c5*y2

◆ fit_ellipse2()

vector< double > fit_ellipse2 ( vector< Vector3< double > >  v)

Solves for fitting a conic through a model.

Parameters
vset of xy coordinates.
Returns
vector<double> 6 coefficients.
The conic is defined as:
    0 = c0 + c1*x + c2*y + c3*x2 + c4*x*y + c5*y2

◆ fit_plane()

Vector3< double > fit_plane ( Matrix  a,
vector< double >  b 
)

Solves for fitting a plane through a model.

Parameters
a3x3 matrix with cross-terms.
b3 vector with averages.
Returns
Vector3<double> plane normal.
A plane is fit through the components and the normal calculated from:
    n•p = d
where n is the normal vector, p is a point in the plane, and d is the offset.

◆ fit_polynomial() [1/2]

double fit_polynomial ( int  n,
double *  x,
double *  y,
int  order,
double *  coeff 
)

Fits a data set to a polynomial function.

Parameters
nnumber of data points.
*xx array (at least order+1 values).
*yy array (at least order+1 values).
orderpolynomial order.
*coeffarray in which coefficients are returned (order+1 values) (if NULL, no coefficients returned).
Returns
double the deviation.
A polynomial of any order is fitted to the data using a least squares.
The polynomial is defined as:
    f(x) = a0 + a1*x + a2*x^2 + ...
The number of coefficients returned is the order plus one.
The deviation is defined as:
    R = sqrt(sum(y - f(x))^2/n)

◆ fit_polynomial() [2/2]

double fit_polynomial ( int  n,
vector< double > &  x,
vector< double > &  y,
int  order,
vector< double > &  coeff 
)

Fits a data set to a polynomial function.

Parameters
nnumber of data points.
&xx array (at least order+1 values).
&yy array (at least order+1 values).
orderpolynomial order.
&coeffarray in which coefficients are returned (order+1 values) (if NULL, no coefficients returned).
Returns
double the deviation.
A polynomial of any order is fitted to the data using a least squares.
The polynomial is defined as:
    f(x) = a0 + a1*x + a2*x^2 + ...
The number of coefficients returned is the order plus one.
The deviation is defined as:
    R = sqrt(sum(y - f(x))^2/n)

◆ linear_least_squares() [1/2]

double linear_least_squares ( int  n1,
int  n2,
double *  x,
double *  y,
double &  a,
double &  b 
)

Does a linear least squares fit between two vectors.

Parameters
n1the starting index in each vector (usually 0).
n2the final index in each vector.
*xx vector (at least n2+1 elements).
*yy vector (at least n2+1 elements).
&athe intercept.
&bthe slope.
Returns
double the correlation index.
The two input vectors must have elements between indices n1 and n2.

◆ linear_least_squares() [2/2]

double linear_least_squares ( int  n1,
int  n2,
vector< double > &  x,
vector< double > &  y,
double &  a,
double &  b 
)

Variable Documentation

◆ verbose

int verbose
extern