1 18 19 package org.apache.commons.math.analysis.derivative; 20 21 import org.apache.commons.math.MathException; 22 import org.apache.commons.math.analysis.UnivariateRealFunction; 23 24 28 public class CenterDifferenceDerivative extends AbstractDifferenceDerivative { 29 30 33 public CenterDifferenceDerivative(UnivariateRealFunction function, double h) { 34 super(function, h); 35 } 36 37 40 public double value(double x) throws MathException { 41 UnivariateRealFunction f = getFunction(); 42 double h2 = getDelta(); 43 double h = h2 * .5; 44 return (f.value(x + h) - f.value(x - h)) / h2; 45 } 46 47 50 public static UnivariateRealFunction decorate(UnivariateRealFunction function, double h) { 51 return new CenterDifferenceDerivative(function, h); 52 } 53 } 54 | Popular Tags |