Skip to content

Commit

Permalink
add javadoc
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer committed Oct 7, 2024
1 parent b4deacb commit f3e3bff
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1225,11 +1225,20 @@ public static double xyToKelvin(double[] xy) {
return (437 * Math.pow(n, 3)) + (3601 * Math.pow(n, 2)) + (6861 * n) + 5517;
}

/**
* Calculates a polynomial regression.
*
* This calculates the equation K[4]*x^0 + K[3]*x^1 + K[2]*x^2 + K[1]*x^3 + K[0]*x^4
*
* @param x The independent variable distributed through each term of the polynomial
* @param coefficients The coefficients of the polynomial. Note that the terms are in
* order from largest exponent to smallest exponent, which is the reverse order
* of the usual way of writing it in academic papers
* @return the result of substituting x into the regression polynomial
*/
private static BigDecimal polynomialFit(BigDecimal x, BigDecimal[] coefficients) {
var result = BigDecimal.ZERO;
var xAccumulator = BigDecimal.ONE;
// forms K[4]*x^0 + K[3]*x^1 + K[2]*x^2 + K[1]*x^3 + K[0]*x^4
// (or reverse the order of terms for the usual way of writing it in academic papers)
for (int i = coefficients.length - 1; i >= 0; i--) {
result = result.add(coefficients[i].multiply(xAccumulator));
xAccumulator = xAccumulator.multiply(x);
Expand Down

0 comments on commit f3e3bff

Please sign in to comment.