-
Notifications
You must be signed in to change notification settings - Fork 1
/
polyFit.h
91 lines (78 loc) · 2.83 KB
/
polyFit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
******************************************************************************
* @file polyFit.h
* @brief Header file for fitting polynomials to datasets.
******************************************************************************
*/
#ifndef INC_POLYFIT_H_
#define INC_POLYFIT_H_
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
/**
* @brief Structure to hold the polynomial coefficients
*/
typedef struct {
float *coefficients; /**< Array of coefficients */
int32_t degree; /**< Degree of the polynomial */
} Polynomial;
/**
* @brief Function to initialise a polynomial
* @param degree Degree of the polynomial
* @return Pointer to initialised Polynomial structure
*/
Polynomial *initPolynomial(int32_t degree);
/**
* @brief Function to free memory allocated for a polynomial
* @param poly Pointer to the Polynomial structure to be freed
*/
void freePolynomial(Polynomial *poly);
/**
* @brief Function to perform Gaussian elimination
* @param A Matrix of coefficients
* @param B Array of constants
* @param x Array to store the solution
* @param n Size of the system (number of equations)
*/
void gaussianElimination(float **A, float *B, float *x, int32_t n);
/**
* @brief Function to perform least squares polynomial regression
* @param x Array of x values
* @param y Array of corresponding y values
* @param numPoints Number of data points
* @param degree Degree of the polynomial
* @param resultPoly Pointer to store the resulting polynomial
*/
void leastSquaresPolynomialRegression(const float *x, const float *y,
int32_t numPoints, int32_t degree,
Polynomial *resultPoly);
/**
* @brief Function to evaluate the polynomial at a given x value
* @param poly Pointer to the Polynomial structure
* @param x Value at which the polynomial is evaluated
* @return Result of the polynomial evaluation
*/
float evaluatePolynomial(const Polynomial *poly, float x);
/**
* @brief Get the maximum absolute magnitude among the polynomial coefficients.
*
* @param coefficients Array of polynomial coefficients.
* @param degree Degree of the polynomial.
* @return Maximum absolute magnitude among the coefficients.
*/
float getMaxCoefficientMagnitude(const float *coefficients, int32_t degree);
/**
* @brief Function to calculate the power of a base to an exponent.
* @brief This is to avoid having to link the MASSIVE math.h library.
* @param base The base value (float).
* @param exponent The exponent value (signed 32-bit integer).
* @return Result of base raised to the power of exponent.
*/
float tinyPow(float base, int32_t exponent);
/**
* @brief Calculate the absolute value of a floating-point number.
* @param x The input floating-point number.
* @return Absolute value of x.
*/
float tinyFabs(float x);
#endif /* INC_POLYFIT_H_ */