Beispiel #1
0
    def test_3(self):
        """
        Unit test for exercise 1.3c-g.
        """
        # Run Newton's method. Last starting point is wildly high. How will Newton perform??
        starting_points = (0.1, 4.0, -0.2, -0.1)
        assert len(starting_points) == 4

        logging.info("\nRUNNING EXERCISE 1.3C")
        newton_roots = [undertest.newton(self.func, self.derivative, x0, 50)
                for x0 in starting_points]

        # Run secant-based methods. Last interval has a high right endpoint. How will the algos do?
        secant_intervals = [(0.9, 10.0), (-0.2, 3.0), (0.1, 6.0), (1.9, 20.0), (20.0, 1.9)]
        assert len(secant_intervals) == 5
        logging.info("\nRUNNING EXERCISE 1.3D")
        secant_results = [undertest.secant(self.func, prev, current, self.maxit)
                for (prev, current) in secant_intervals]
        logging.info("\nRUNNING EXERCISE 1.3E")
        regula_falsi_results = [undertest.regula_falsi(self.func, prev, current, 100)
                for (prev, current) in secant_intervals]
        logging.info("\nRUNNING EXERCISE 1.3F")
        wheeler_results = [undertest.wheeler(self.func, prev, current, 20)
                for (prev, current) in secant_intervals]