Robotran C Documentation
Functions
mbs_polynomial.c File Reference
#include "mbs_polynomial.h"
#include "mbs_1D_array.h"
#include "mbs_matrix.h"
#include "mbs_message.h"
#include "nrfct.h"
#include <math.h>
#include <stdlib.h>

Functions

int factorial (int n)
 
int mbs_polynomial_check (MbsPolynomial *poly)
 Check the validity of the provided polynomial. More...
 
MbsPolynomialmbs_polynomial_new (int order)
 Allocate a polynomial. More...
 
void * mbs_polynomial_delete (MbsPolynomial *poly)
 Free a polynomial and return NULL. More...
 
MbsPolynomialmbs_polynomial_constrained (int nb_pos, double **pos_xy, int nb_deriv, double **deriv_xyp)
 Create a polynomial fulfilling the position and first derivative. More...
 
double mbs_polynomial_get_value (MbsPolynomial *poly, double x, int deriv)
 Evaluate the polynomial without any checks. More...
 
int mbs_polynomial_eval (MbsPolynomial *poly, double x, double *y, int deriv)
 Evaluate the polynomial (or its nth derivative) at the provided coordinate. More...
 
int mbs_polynomial_print (MbsPolynomial *poly)
 Print information about the polynomial. More...
 
int mbs_polynomial_eval_vec (MbsPolynomial *poly, int nx, double *vx, double **p_vy, int deriv)
 Evaluate the polynomial (or its nth derivative) at the provided coordinates vector. More...
 

Detailed Description

Implement polynomial-related function for MBsysC.

Creation date: 21-06-2023

Author
Robotran team

(c) Universite catholique de Louvain

Function Documentation

◆ factorial()

int factorial ( int  n)

◆ mbs_polynomial_check()

int mbs_polynomial_check ( MbsPolynomial poly)

Check the validity of the provided polynomial.

Parameters
[in]polyThe adress of the polynomial structure.
Returns
Status, null if polynomial is valid, negative value otherwhise.

◆ mbs_polynomial_constrained()

MbsPolynomial* mbs_polynomial_constrained ( int  nb_pos,
double **  pos_xy,
int  nb_deriv,
double **  deriv_xyp 
)

Create a polynomial fulfilling the position and first derivative.

The function is not optimized and may use a big amount of memory for heavily constrained polynomial. It uses a LU decomposition to solve the system.

Polynomial interpolation is not adapted when order is high due to the Runge's phenomenon.

The order of the polynomial is computed from the number of condition set.

Parameters
[in]nb_posThe number of position that the polynomial must pass by. Must be strictly positive.
[in]pos_xyThe array containing the x and y coordinates of the function. The size is [nb_pos; 2]. Duplicated x-coordinates are forbidden.
[in]nb_derivThe number of specified polynomial derivative. Must be positive or null.
[in]deriv_xypThe array containing the x coordinates and the yp derivative of the function. The size is [nb_pos; 2]. Duplicated x-coordinates are forbidden. NULL can be provided if nb_deriv is null.
Returns
A polynomial that fulfills the position and derivative. NULL if no such polynomial exists.

◆ mbs_polynomial_delete()

void* mbs_polynomial_delete ( MbsPolynomial poly)

Free a polynomial and return NULL.

Parameters
[in,out]polyThe polynomial to be free.
Returns
NULL

◆ mbs_polynomial_eval()

int mbs_polynomial_eval ( MbsPolynomial poly,
double  x,
double *  y,
int  deriv 
)

Evaluate the polynomial (or its nth derivative) at the provided coordinate.

Parameters
[in]polyThe polynomial of the function.
[in]xThe coordinate at which the the function must be computed.
[out]yThe pointer to store the function value.
[in]derivThe order of the derivative to be computed. The function is 0, the first derivative is 1...
Returns
Status, null if correct, negative if any error.

◆ mbs_polynomial_eval_vec()

int mbs_polynomial_eval_vec ( MbsPolynomial poly,
int  nx,
double *  vx,
double **  p_vy,
int  deriv 
)

Evaluate the polynomial (or its nth derivative) at the provided coordinates vector.

Parameters
[in]polyThe polynomial of the function.
[in]nxThe number of coordinate to be evaluated.
[in]vxThe array containing the coordinates at which the the function must be computed.
[in,out]p_vyThe pointer to array where the output array pointer is located. if it contains a NULL adress, the output array is allocated.
[in]derivThe order of the derivative to be computed. The function is 0, the first derivative is 1...
Returns
Status, null if correct, negative if any error.

◆ mbs_polynomial_get_value()

double mbs_polynomial_get_value ( MbsPolynomial poly,
double  x,
int  deriv 
)

Evaluate the polynomial without any checks.

Parameters
[in]polyThe polynomial of the function.
[in]xThe coordinate at which the the function must be computed.
[in]derivThe order of the derivative to be computed. The function is 0, the first derivative is 1...
Returns
The value of the polynomial.

◆ mbs_polynomial_new()

MbsPolynomial* mbs_polynomial_new ( int  order)

Allocate a polynomial.

If order is negative, pointer is set to NULL.

Parameters
[in]orderThe order of the polynomial. A negative value means that the coefficient array is not allocated.
Returns
The allocated polynomial, NULL in case of error.

◆ mbs_polynomial_print()

int mbs_polynomial_print ( MbsPolynomial poly)

Print information about the polynomial.

Parameters
[in]polyThe polynomial.
Returns
Status, null if polynomial is initialized, negative otherwhise.