MathPHP\NumericalAnalysis\NumericalDifferentiation\SecondDerivativeMidpointFormulaTest::testNonzeroError PHP Method

testNonzeroError() public method

public testNonzeroError ( )
    public function testNonzeroError()
    {
        // f(x) = x⁴ - 13x² -92x + 96
        $f = function ($x) {
            return $x ** 4 - 13 * $x ** 2 - 92 * $x + 96;
        };
        /*
         *                                                        h²
         * Error term for the Second Derivative Midpoint Formula: - f⁽⁴⁾(ζ)
         *                                                        12
         *
         *     where ζ lies between x₀ - h and x₀ + h
         */
        // f'(x)   = 4x³ - 26x - 92
        // f''(x)  = 12x² - 26
        // f⁽³⁾(x) = 24x
        // f⁽⁴⁾(x) = 24
        // Error in Second Derivative Midpoint Formula on [0,2] (where h=1) < 2
        $f’’ = function ($x) {
            return 12 * $x ** 2 - 26;
        };
        $n = 3;
        $a = 0;
        $b = 2;
        // Check that the midpoint formula agrees with f'(x) at x = 1
        $target = 1;
        $tol = 2;
        $expected = $f’’($target);
        $actual = SecondDerivativeMidpointFormula::differentiate($target, $f, $a, $b, $n);
        $this->assertEquals($expected, $actual, '', $tol);
    }