Skip to content

Commit 8249eea

Browse files
Update wronskian_second_order_de.py
1 parent 8e0db7c commit 8249eea

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

maths/wronskian_second_order_de.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
References: https://tutorial.math.lamar.edu/classes/de/wronskian.aspx
1515
"""
1616

17-
import math
1817
import cmath
1918

20-
2119
def compute_characteristic_roots(
2220
a: float, b: float, c: float
2321
) -> tuple[complex, complex]:
2422
"""
2523
Compute characteristic roots for a second-order homogeneous linear DE.
26-
24+
a, b, c -> coefficients
25+
2726
>>> compute_characteristic_roots(1, -3, 2)
2827
(2.0, 1.0)
2928
>>> compute_characteristic_roots(1, 2, 5)
@@ -65,19 +64,27 @@ def classify_solution_type(root1: complex, root2: complex) -> str:
6564
return "Distinct Real Roots"
6665

6766

68-
def compute_wronskian(f, g, f_prime, g_prime, x: float) -> float:
67+
def compute_wronskian(
68+
function_1: Callable[[float], float],
69+
function_2: Callable[[float], float],
70+
derivative_1: Callable[[float], float],
71+
derivative_2: Callable[[float], float],
72+
evaluation_point: float
73+
) -> float:
6974
"""
70-
Compute Wronskian determinant W(f, g) = f * g' - f' * g.
71-
72-
>>> import math
73-
>>> def f(x): return math.exp(x)
74-
>>> def g(x): return x * math.exp(x)
75-
>>> def f_prime(x): return math.exp(x)
76-
>>> def g_prime(x): return math.exp(x) + x * math.exp(x)
77-
>>> round(compute_wronskian(f, g, f_prime, g_prime, 0), 3)
78-
1.0
75+
Compute the Wronskian of two functions at a given point.
76+
77+
Parameters:
78+
function_1 (Callable[[float], float]): The first function f(x).
79+
function_2 (Callable[[float], float]): The second function g(x).
80+
derivative_1 (Callable[[float], float]): Derivative of the first function f'(x).
81+
derivative_2 (Callable[[float], float]): Derivative of the second function g'(x).
82+
evaluation_point (float): The point x at which to evaluate the Wronskian.
83+
84+
Returns:
85+
float: Value of the Wronskian at the given point.
7986
"""
80-
return f(x) * g_prime(x) - f_prime(x) * g(x)
87+
return function_1(evaluation_point) * derivative_2(evaluation_point) - function_2(evaluation_point) * derivative_1(evaluation_point)
8188

8289

8390
def construct_general_solution(root1: complex, root2: complex) -> str:
@@ -104,7 +111,8 @@ def construct_general_solution(root1: complex, root2: complex) -> str:
104111
def analyze_differential_equation(a: float, b: float, c: float) -> None:
105112
"""
106113
Analyze the DE and print the roots, type, and general solution.
107-
114+
a, b, c -> coefficients
115+
108116
>>> analyze_differential_equation(1, -3, 2) # doctest: +ELLIPSIS
109117
Characteristic Roots: (2.0, 1.0)
110118
Solution Type: Distinct Real Roots
@@ -142,3 +150,4 @@ def main() -> None:
142150

143151
if __name__ == "__main__":
144152
main() # doctest: +SKIP
153+

0 commit comments

Comments
 (0)