MCPcopy Create free account
hub / github.com/Aghajari/MathParser / Derivative

Class Derivative

MathParser/src/com/aghajari/math/custom/Derivative.java:6–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5// https://github.com/allusai/calculus-solver/blob/master/Calculus.java
6public class Derivative {
7 /*
8 *These constants can modified to change the accuracy of approximation
9 *A smaller epsilon/step size uses more memory but yields a more
10 *accurate approximation of the derivative/integral respectively
11 */
12 private final static double EPSILON = 0.0000001;
13
14
15 /**
16 * Calculates the derivative around a certain point using
17 * a numerical approximation.
18 *
19 * @param x the x-coordinate at which to approximate the derivative
20 * @return double the derivative at the specified point
21 */
22 public static double getDerivative(FunctionWrapper function, double x) throws MathParserException {
23 //The y-coordinates of the points close to the specified x-coordinates
24 double yOne = function.apply(x - EPSILON);
25 double yTwo = function.apply(x + EPSILON);
26
27 return (yTwo - yOne) / (2 * EPSILON);
28 }
29
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected