Skip to content

Commit

Permalink
MNT: rename cardanos_root_finding to find_roots_cubic_function in Fun…
Browse files Browse the repository at this point in the history
…ction class
  • Loading branch information
Gui-FernandesBR committed Apr 18, 2024
1 parent 2602e4d commit b55236e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b55236e

Please sign in to comment.