コード例 #1
0
    def test_bisection(self):
        def f3(x):
            return x**3 - 27

        self.assertIsNotNone(bisection(f3, 0, 6))
        self.assertEqual(bisection(f3, 2, 6), 3)
        self.assertGreater(bisection(f3, 2, 6), 2.999)
コード例 #2
0
def calc_c(f):
    ## calc f root by one method ScantMethod
    print("##################### scant method print ###################")
    scant_method_result = [
        ScantMethod.secant(f, 0, 0.5, 100),
        ScantMethod.secant(f, 0.6, 1.2, 100),
        ScantMethod.secant(f, -1.5, 0, 100)
    ]
    scant_method_result = filter_negative_number(scant_method_result)
    print("##################### end scant method print ###################")

    ## calc f root by one method bisection
    print("##################### bisection method print ###################")
    bisection_method_result = [
        bisection(f, 0, 0.5),
        bisection(f, 0.6, 1.2),
        bisection(f, -1.5, 0)
    ]
    bisection_method_result = filter_negative_number(bisection_method_result)
    print(
        "##################### end bisection method print ###################")
    print(scant_method_result)
    print(bisection_method_result)
    if round_list(scant_method_result) == round_list(bisection_method_result):
        print("C: the method solution result are equal.\n {0}".format(
            scant_method_result))
        return sum(scant_method_result) / len(scant_method_result)
    else:
        print("the result are not equal")
        exit()
コード例 #3
0
    def test_bisection(self):
        def f1(x):
            return x**2 - 9

    #  def f1a(x):
    #     return x**6-4*(x**5)+3*(x**2)+6

        self.assertIsNotNone(bisection(f1, 2, 6))
        self.assertEqual(bisection(f1, 2, 6), 3)
        self.assertGreater(bisection(f1, 2, 6), 2.999)
        self.assertAlmostEquals(bisection(f1, -1, 6), 3)
コード例 #4
0
def calc_mu(f):
    ## calc f root by one method ScantMethod
    scant_method_result = [
        ScantMethod.secant(f, 0.2, 1, 100),
        ScantMethod.secant(f, 1, 3, 100)
    ]
    scant_method_result = filter_negative_number(scant_method_result)

    ## calc f root by one method bisection
    bisection_method_result = [bisection(f, 0.2, 1), bisection(f, 1, 3)]
    bisection_method_result = filter_negative_number(bisection_method_result)
    print(scant_method_result)
    print(bisection_method_result)
    arr = np.array(scant_method_result)
    if round_list(scant_method_result) == round_list(bisection_method_result):
        print("MU: the method solution result are equal")
        return (arr.min() / 100)
    else:
        print("the result are not equal")
        exit()
コード例 #5
0
    def test_bisection(self):
        def f2(x):
            return x**2

        self.assertIsNone(bisection(f2, 2, 6))