Skip to content

Commit d97725b

Browse files
committed
added comments in quadratic root finder
1 parent d3880af commit d97725b

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

6_inv_free/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def smallest_positive_real_root_quad(a, b, c, tol = 1e-6):
2121
else:
2222
desc = b * b - 4 * a * c
2323
if desc > 0:
24-
t = (-b - math.sqrt(desc)) / (2 * a)
24+
t = (-b - math.sqrt(desc)) / (2 * a) # if a > 0, this is either the smaller positive root, or both roots are negative;
25+
# if a < 0, there are 1 negative and 1 positive real roots, and we just need the positive one.
2526
if t < 0:
2627
t = (-b + math.sqrt(desc)) / (2 * a)
2728
else: # desv<0 ==> imag, f(x) > 0 for all x > 0

7_self_contact/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def smallest_positive_real_root_quad(a, b, c, tol = 1e-6):
2020
else:
2121
desc = b * b - 4 * a * c
2222
if desc > 0:
23-
t = (-b - math.sqrt(desc)) / (2 * a)
23+
t = (-b - math.sqrt(desc)) / (2 * a) # if a > 0, this is either the smaller positive root, or both roots are negative;
24+
# if a < 0, there are 1 negative and 1 positive real roots, and we just need the positive one.
2425
if t < 0:
2526
t = (-b + math.sqrt(desc)) / (2 * a)
2627
else: # desv<0 ==> imag, f(x) > 0 for all x > 0

8_self_friction/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def smallest_positive_real_root_quad(a, b, c, tol = 1e-6):
2020
else:
2121
desc = b * b - 4 * a * c
2222
if desc > 0:
23-
t = (-b - math.sqrt(desc)) / (2 * a)
23+
t = (-b - math.sqrt(desc)) / (2 * a) # if a > 0, this is either the smaller positive root, or both roots are negative;
24+
# if a < 0, there are 1 negative and 1 positive real roots, and we just need the positive one.
2425
if t < 0:
2526
t = (-b + math.sqrt(desc)) / (2 * a)
2627
else: # desv<0 ==> imag, f(x) > 0 for all x > 0

9_reduced_DOF/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def smallest_positive_real_root_quad(a, b, c, tol = 1e-6):
2626
else:
2727
desc = b * b - 4 * a * c
2828
if desc > 0:
29-
t = (-b - math.sqrt(desc)) / (2 * a)
29+
t = (-b - math.sqrt(desc)) / (2 * a) # if a > 0, this is either the smaller positive root, or both roots are negative;
30+
# if a < 0, there are 1 negative and 1 positive real roots, and we just need the positive one.
3031
if t < 0:
3132
t = (-b + math.sqrt(desc)) / (2 * a)
3233
else: # desv<0 ==> imag, f(x) > 0 for all x > 0

0 commit comments

Comments
 (0)