From b55236e78a243b94f036b19d77a92d85342e47e2 Mon Sep 17 00:00:00 2001 From: Gui-FernandesBR Date: Thu, 18 Apr 2024 19:44:54 -0400 Subject: [PATCH] MNT: rename cardanos_root_finding to find_roots_cubic_function in Function class --- rocketpy/mathutils/function.py | 4 ++-- rocketpy/simulation/flight.py | 4 ++-- tests/unit/test_function.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rocketpy/mathutils/function.py b/rocketpy/mathutils/function.py index d2cf6c0c5..8f96d49c5 100644 --- a/rocketpy/mathutils/function.py +++ b/rocketpy/mathutils/function.py @@ -2909,7 +2909,7 @@ def calculate_cubic_hermite_coefficients(x0, x1, y0, yp0, y1, yp1): return a, b, c, d @staticmethod - def cardanos_root_finding(a, b, c, d): + def find_roots_cubic_function(a, b, c, d): """Calculate the roots of a cubic function using Cardano's method. This method applies Cardano's method to find the roots of a cubic @@ -2944,7 +2944,7 @@ def cardanos_root_finding(a, b, c, d): First we define the coefficients of the function ax**3 + bx**2 + cx + d >>> a, b, c, d = 1, -3, -1, 3 - >>> x1, x2, x3 = Function.cardanos_root_finding(a, b, c, d) + >>> x1, x2, x3 = Function.find_roots_cubic_function(a, b, c, d) >>> x1, x2, x3 ((-1+0j), (3+7.401486830834377e-17j), (1-1.4802973661668753e-16j)) diff --git a/rocketpy/simulation/flight.py b/rocketpy/simulation/flight.py index 419ab75fe..2c24e70e5 100644 --- a/rocketpy/simulation/flight.py +++ b/rocketpy/simulation/flight.py @@ -822,7 +822,7 @@ def __simulate__(self, verbose): ) a += 1e-5 # TODO: why?? # Find roots - t_roots = Function.cardanos_root_finding(a, b, c, d) + t_roots = Function.find_roots_cubic_function(a, b, c, d) # Find correct root valid_t_root = [ t_root.real @@ -900,7 +900,7 @@ def __simulate__(self, verbose): yp1=float(self.solution[-1][6]), # vz1 ) # Find roots - t_roots = Function.cardanos_root_finding(a, b, c, d) + t_roots = Function.find_roots_cubic_function(a, b, c, d) # Find correct root t1 = self.solution[-1][0] - self.solution[-2][0] valid_t_root = [ diff --git a/tests/unit/test_function.py b/tests/unit/test_function.py index 633da2cf6..35a5b21e9 100644 --- a/tests/unit/test_function.py +++ b/tests/unit/test_function.py @@ -360,11 +360,11 @@ def test_calculate_cubic_hermite_coefficients(): def test_cardanos_root_finding(): - """Tests the cardanos_root_finding method of the Function class.""" + """Tests the find_roots_cubic_function method of the Function class.""" # Function: f(x) = x**3 + 2x**2 -1 # roots: (-1 - 5**0.5) / 2; -1; (-1 + 5**0.5) / 2 - roots = list(Function.cardanos_root_finding(a=1, b=2, c=0, d=-1)) + roots = list(Function.find_roots_cubic_function(a=1, b=2, c=0, d=-1)) roots.sort(key=lambda x: x.real) assert np.isclose(roots[0].real, (-1 - 5**0.5) / 2)