From d218dd15c50cd3dd1bbe8b58d266f61cd91f5730 Mon Sep 17 00:00:00 2001 From: Venkat Thadi Date: Thu, 9 Oct 2025 21:12:48 +0530 Subject: [PATCH 1/9] added wronskian_second_order_de.py --- maths/wronskian_second_order_de.py | 178 +++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 maths/wronskian_second_order_de.py diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py new file mode 100644 index 000000000000..8d9f13d7c357 --- /dev/null +++ b/maths/wronskian_second_order_de.py @@ -0,0 +1,178 @@ +""" +Module to analyze homogeneous linear differential equations. + +It supports: + - Second-order equations: a*y'' + b*y' + c*y = 0 + - First-order equations: b*y' + c*y = 0 (when a = 0) + +Features: + - Computes characteristic roots (for second-order) + - Derives fundamental solutions + - Calculates first derivatives + - Evaluates the Wronskian determinant + - Tests for linear independence + +References: + https://en.wikipedia.org/wiki/Linear_differential_equation +""" + +import cmath +from sympy import symbols, exp, cos, sin, diff, simplify + + +def compute_characteristic_roots( + coefficient_a: float, coefficient_b: float, coefficient_c: float +) -> tuple[complex, complex]: + """ + Compute roots of the characteristic equation: + a*r^2 + b*r + c = 0 + + >>> compute_characteristic_roots(1, -2, 1) + ((1+0j), (1+0j)) + >>> compute_characteristic_roots(1, 0, 1) + ((0+1j), (0-1j)) + """ + discriminant = coefficient_b**2 - 4 * coefficient_a * coefficient_c + sqrt_discriminant = cmath.sqrt(discriminant) + root_1 = (-coefficient_b + sqrt_discriminant) / (2 * coefficient_a) + root_2 = (-coefficient_b - sqrt_discriminant) / (2 * coefficient_a) + return root_1, root_2 + + +def construct_fundamental_solutions(root_1: complex, root_2: complex): + """ + Construct fundamental solutions (y1, y2) of a 2nd-order ODE. + + >>> from sympy import symbols, exp + >>> x = symbols('x') + >>> r1, r2 = 1, 1 + >>> construct_fundamental_solutions(r1, r2) + (exp(x), x*exp(x)) + """ + variable_x = symbols("x") + + # Case 1: Real and equal roots + if root_1 == root_2 and root_1.imag == 0: + solution_1 = exp(root_1.real * variable_x) + solution_2 = variable_x * exp(root_1.real * variable_x) + + # Case 2: Real and distinct roots + elif root_1.imag == 0 and root_2.imag == 0: + solution_1 = exp(root_1.real * variable_x) + solution_2 = exp(root_2.real * variable_x) + + # Case 3: Complex conjugate roots (α ± iβ) + else: + alpha = root_1.real + beta = abs(root_1.imag) + solution_1 = exp(alpha * variable_x) * cos(beta * variable_x) + solution_2 = exp(alpha * variable_x) * sin(beta * variable_x) + + return solution_1, solution_2 + + +def compute_wronskian(function_1, function_2): + """ + Compute the Wronskian determinant of two functions. + + >>> from sympy import symbols, exp + >>> x = symbols('x') + >>> f1, f2 = exp(x), x*exp(x) + >>> compute_wronskian(f1, f2) + exp(2*x) + """ + variable_x = symbols("x") + derivative_1 = diff(function_1, variable_x) + derivative_2 = diff(function_2, variable_x) + wronskian = simplify(function_1 * derivative_2 - function_2 * derivative_1) + return wronskian + + +def solve_first_order_equation(coefficient_b: float, coefficient_c: float) -> None: + """ + Solve the first-order ODE: b*y' + c*y = 0 + and display its general solution and Wronskian. + + >>> solve_first_order_equation(2, 4) + """ + variable_x = symbols("x") + if coefficient_b == 0: + print("Error: Both a and b cannot be zero. Not a valid differential equation.") + return + + # Simplified form: y' + (c/b)*y = 0 + constant_k = coefficient_c / coefficient_b + solution = exp(-constant_k * variable_x) + + derivative_solution = diff(solution, variable_x) + wronskian = simplify(solution * derivative_solution) + + print("\n--- First-Order Differential Equation ---") + print(f"Equation: {coefficient_b}*y' + {coefficient_c}*y = 0") + print(f"Solution: y = C * e^(-({coefficient_c}/{coefficient_b}) * x)") + print(f"y'(x) = {derivative_solution}") + print(f"Wronskian (single function): {wronskian}") + print("Linear independence: Trivial (only one solution).") + + +def analyze_differential_equation( + coefficient_a: float, coefficient_b: float, coefficient_c: float +) -> None: + """ + Determine the type of equation and analyze it accordingly. + """ + # Case 1: Not a valid DE + if coefficient_a == 0 and coefficient_b == 0: + print("Error: Both 'a' and 'b' cannot be zero. Not a valid differential equation.") + return + + # Case 2: First-order DE + if coefficient_a == 0: + solve_first_order_equation(coefficient_b, coefficient_c) + return + + # Case 3: Second-order DE + print("\n--- Second-Order Differential Equation ---") + root_1, root_2 = compute_characteristic_roots( + coefficient_a, coefficient_b, coefficient_c + ) + + print(f"Characteristic roots: r1 = {root_1}, r2 = {root_2}") + + function_1, function_2 = construct_fundamental_solutions(root_1, root_2) + + variable_x = symbols("x") + derivative_1 = diff(function_1, variable_x) + derivative_2 = diff(function_2, variable_x) + wronskian = compute_wronskian(function_1, function_2) + + print(f"y₁(x) = {function_1}") + print(f"y₂(x) = {function_2}") + print(f"y₁'(x) = {derivative_1}") + print(f"y₂'(x) = {derivative_2}") + print(f"Wronskian: {wronskian}") + + if wronskian == 0: + print("The functions are linearly dependent.") + else: + print("The functions are linearly independent.") + + +def main() -> None: + """ + Entry point of the program. + """ + print("Enter coefficients for the equation a*y'' + b*y' + c*y = 0") + try: + coefficient_a = float(input("a = ").strip()) + coefficient_b = float(input("b = ").strip()) + coefficient_c = float(input("c = ").strip()) + except ValueError: + print("Invalid input. Please enter numeric values for coefficients.") + return + + analyze_differential_equation(coefficient_a, coefficient_b, coefficient_c) + + +if __name__ == "__main__": + main() From 99753a22961f3764a029707336c3143a0f7fb501 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 15:47:30 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/wronskian_second_order_de.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index 8d9f13d7c357..1e01f409a13a 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -123,7 +123,9 @@ def analyze_differential_equation( """ # Case 1: Not a valid DE if coefficient_a == 0 and coefficient_b == 0: - print("Error: Both 'a' and 'b' cannot be zero. Not a valid differential equation.") + print( + "Error: Both 'a' and 'b' cannot be zero. Not a valid differential equation." + ) return # Case 2: First-order DE From c12ccbc84b0f2a436aaf2742e76c06a676b943bc Mon Sep 17 00:00:00 2001 From: Venkat Thadi Date: Thu, 9 Oct 2025 21:41:38 +0530 Subject: [PATCH 3/9] Update wronskian_second_order_de.py --- maths/wronskian_second_order_de.py | 240 ++++++++++++----------------- 1 file changed, 100 insertions(+), 140 deletions(-) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index 1e01f409a13a..121d7ed8b2a2 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -1,180 +1,140 @@ """ -Module to analyze homogeneous linear differential equations. +wronskian_second_order_de.py +A symbolic and numerical exploration of the Wronskian for second-order linear differential equations. -It supports: - - Second-order equations: a*y'' + b*y' + c*y = 0 - - First-order equations: b*y' + c*y = 0 (when a = 0) +This program: +1. Takes coefficients (a, b, c) for a*y'' + b*y' + c*y = 0. +2. Computes characteristic roots. +3. Classifies the solution type. +4. Constructs the general solution. +5. Demonstrates Wronskian computation. -Features: - - Computes characteristic roots (for second-order) - - Derives fundamental solutions - - Calculates first derivatives - - Evaluates the Wronskian determinant - - Tests for linear independence - -References: - https://en.wikipedia.org/wiki/Linear_differential_equation +Author: Venkat Thadi """ +import math import cmath -from sympy import symbols, exp, cos, sin, diff, simplify - - -def compute_characteristic_roots( - coefficient_a: float, coefficient_b: float, coefficient_c: float -) -> tuple[complex, complex]: - """ - Compute roots of the characteristic equation: - a*r^2 + b*r + c = 0 - >>> compute_characteristic_roots(1, -2, 1) - ((1+0j), (1+0j)) - >>> compute_characteristic_roots(1, 0, 1) - ((0+1j), (0-1j)) +def compute_characteristic_roots(a: float, b: float, c: float) -> tuple[complex, complex]: """ - discriminant = coefficient_b**2 - 4 * coefficient_a * coefficient_c - sqrt_discriminant = cmath.sqrt(discriminant) - root_1 = (-coefficient_b + sqrt_discriminant) / (2 * coefficient_a) - root_2 = (-coefficient_b - sqrt_discriminant) / (2 * coefficient_a) - return root_1, root_2 + Compute characteristic roots for a second-order homogeneous linear DE. - -def construct_fundamental_solutions(root_1: complex, root_2: complex): - """ - Construct fundamental solutions (y1, y2) of a 2nd-order ODE. - - >>> from sympy import symbols, exp - >>> x = symbols('x') - >>> r1, r2 = 1, 1 - >>> construct_fundamental_solutions(r1, r2) - (exp(x), x*exp(x)) + >>> compute_characteristic_roots(1, -3, 2) + (2.0, 1.0) + >>> compute_characteristic_roots(1, 2, 5) + ((-1+2j), (-1-2j)) """ - variable_x = symbols("x") + if a == 0: + raise ValueError("Coefficient 'a' cannot be zero for a second-order equation.") - # Case 1: Real and equal roots - if root_1 == root_2 and root_1.imag == 0: - solution_1 = exp(root_1.real * variable_x) - solution_2 = variable_x * exp(root_1.real * variable_x) + discriminant = b ** 2 - 4 * a * c + sqrt_disc = cmath.sqrt(discriminant) + root1 = (-b + sqrt_disc) / (2 * a) + root2 = (-b - sqrt_disc) / (2 * a) - # Case 2: Real and distinct roots - elif root_1.imag == 0 and root_2.imag == 0: - solution_1 = exp(root_1.real * variable_x) - solution_2 = exp(root_2.real * variable_x) + # Simplify if roots are purely real + if abs(root1.imag) < 1e-12: + root1 = float(root1.real) + if abs(root2.imag) < 1e-12: + root2 = float(root2.real) - # Case 3: Complex conjugate roots (α ± iβ) - else: - alpha = root_1.real - beta = abs(root_1.imag) - solution_1 = exp(alpha * variable_x) * cos(beta * variable_x) - solution_2 = exp(alpha * variable_x) * sin(beta * variable_x) + return root1, root2 - return solution_1, solution_2 - -def compute_wronskian(function_1, function_2): +def classify_solution_type(root1: complex, root2: complex) -> str: """ - Compute the Wronskian determinant of two functions. - - >>> from sympy import symbols, exp - >>> x = symbols('x') - >>> f1, f2 = exp(x), x*exp(x) - >>> compute_wronskian(f1, f2) - exp(2*x) + Classify the nature of the roots. + + >>> classify_solution_type(2, 1) + 'Distinct Real Roots' + >>> classify_solution_type(1+2j, 1-2j) + 'Complex Conjugate Roots' + >>> classify_solution_type(3, 3) + 'Repeated Real Roots' """ - variable_x = symbols("x") - derivative_1 = diff(function_1, variable_x) - derivative_2 = diff(function_2, variable_x) - wronskian = simplify(function_1 * derivative_2 - function_2 * derivative_1) - return wronskian + if isinstance(root1, complex) and isinstance(root2, complex) and root1.imag != 0: + return "Complex Conjugate Roots" + elif root1 == root2: + return "Repeated Real Roots" + else: + return "Distinct Real Roots" -def solve_first_order_equation(coefficient_b: float, coefficient_c: float) -> None: +def compute_wronskian(f, g, f_prime, g_prime, x: float) -> float: """ - Solve the first-order ODE: b*y' + c*y = 0 - and display its general solution and Wronskian. - - >>> solve_first_order_equation(2, 4) + Compute Wronskian determinant W(f, g) = f * g' - f' * g. + + >>> import math + >>> def f(x): return math.exp(x) + >>> def g(x): return x * math.exp(x) + >>> def f_prime(x): return math.exp(x) + >>> def g_prime(x): return math.exp(x) + x * math.exp(x) + >>> round(compute_wronskian(f, g, f_prime, g_prime, 0), 3) + 1.0 """ - variable_x = symbols("x") - if coefficient_b == 0: - print("Error: Both a and b cannot be zero. Not a valid differential equation.") - return - - # Simplified form: y' + (c/b)*y = 0 - constant_k = coefficient_c / coefficient_b - solution = exp(-constant_k * variable_x) - - derivative_solution = diff(solution, variable_x) - wronskian = simplify(solution * derivative_solution) + return f(x) * g_prime(x) - f_prime(x) * g(x) - print("\n--- First-Order Differential Equation ---") - print(f"Equation: {coefficient_b}*y' + {coefficient_c}*y = 0") - print(f"Solution: y = C * e^(-({coefficient_c}/{coefficient_b}) * x)") - print(f"y'(x) = {derivative_solution}") - print(f"Wronskian (single function): {wronskian}") - print("Linear independence: Trivial (only one solution).") - -def analyze_differential_equation( - coefficient_a: float, coefficient_b: float, coefficient_c: float -) -> None: +def construct_general_solution(root1: complex, root2: complex) -> str: """ - Determine the type of equation and analyze it accordingly. + Construct the general solution based on the roots. + + >>> construct_general_solution(2, 1) + 'y(x) = C1 * e^(2x) + C2 * e^(1x)' + >>> construct_general_solution(3, 3) + 'y(x) = (C1 + C2 * x) * e^(3x)' + >>> construct_general_solution(-1+2j, -1-2j) + 'y(x) = e^(-1x) * (C1 * cos(2x) + C2 * sin(2x))' """ - # Case 1: Not a valid DE - if coefficient_a == 0 and coefficient_b == 0: - print( - "Error: Both 'a' and 'b' cannot be zero. Not a valid differential equation." - ) - return - - # Case 2: First-order DE - if coefficient_a == 0: - solve_first_order_equation(coefficient_b, coefficient_c) - return - - # Case 3: Second-order DE - print("\n--- Second-Order Differential Equation ---") - root_1, root_2 = compute_characteristic_roots( - coefficient_a, coefficient_b, coefficient_c - ) - - print(f"Characteristic roots: r1 = {root_1}, r2 = {root_2}") + if isinstance(root1, complex) and root1.imag != 0: + alpha = round(root1.real, 10) + beta = round(abs(root1.imag), 10) + return f"y(x) = e^({alpha:g}x) * (C1 * cos({beta:g}x) + C2 * sin({beta:g}x))" + elif root1 == root2: + return f"y(x) = (C1 + C2 * x) * e^({root1:g}x)" + else: + return f"y(x) = C1 * e^({root1:g}x) + C2 * e^({root2:g}x)" - function_1, function_2 = construct_fundamental_solutions(root_1, root_2) - variable_x = symbols("x") - derivative_1 = diff(function_1, variable_x) - derivative_2 = diff(function_2, variable_x) - wronskian = compute_wronskian(function_1, function_2) +def analyze_differential_equation(a: float, b: float, c: float) -> None: + """ + Analyze the DE and print the roots, type, and general solution. - print(f"y₁(x) = {function_1}") - print(f"y₂(x) = {function_2}") - print(f"y₁'(x) = {derivative_1}") - print(f"y₂'(x) = {derivative_2}") - print(f"Wronskian: {wronskian}") + >>> analyze_differential_equation(1, -3, 2) # doctest: +ELLIPSIS + Characteristic Roots: (2.0, 1.0) + Solution Type: Distinct Real Roots + General Solution: y(x) = C1 * e^(2x) + C2 * e^(1x) + """ + roots = compute_characteristic_roots(a, b, c) + root1, root2 = roots + sol_type = classify_solution_type(root1, root2) + general_solution = construct_general_solution(root1, root2) - if wronskian == 0: - print("The functions are linearly dependent.") - else: - print("The functions are linearly independent.") + print(f"Characteristic Roots: ({root1:.1f}, {root2:.1f})") + print(f"Solution Type: {sol_type}") + print(f"General Solution: {general_solution}") def main() -> None: """ - Entry point of the program. + Main function to run the second-order differential equation Wronskian analysis. + + Interactive input is expected, so this function is skipped in doctests. """ print("Enter coefficients for the equation a*y'' + b*y' + c*y = 0") - try: - coefficient_a = float(input("a = ").strip()) - coefficient_b = float(input("b = ").strip()) - coefficient_c = float(input("c = ").strip()) - except ValueError: - print("Invalid input. Please enter numeric values for coefficients.") + + # Skipping main in doctests because input() cannot be tested directly + a = float(input("a = ").strip()) # doctest: +SKIP + b = float(input("b = ").strip()) # doctest: +SKIP + c = float(input("c = ").strip()) # doctest: +SKIP + + if a == 0: + print("Invalid input: coefficient 'a' cannot be zero.") return - analyze_differential_equation(coefficient_a, coefficient_b, coefficient_c) + analyze_differential_equation(a, b, c) + if __name__ == "__main__": - main() + main() # doctest: +SKIP From cecf335cdd37c95ea229ba7cddb2e19ce3291eab Mon Sep 17 00:00:00 2001 From: Venkat Thadi Date: Thu, 9 Oct 2025 21:45:15 +0530 Subject: [PATCH 4/9] Update wronskian_second_order_de.py --- maths/wronskian_second_order_de.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index 121d7ed8b2a2..077859b1bd8d 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -10,6 +10,8 @@ 5. Demonstrates Wronskian computation. Author: Venkat Thadi + +References: https://tutorial.math.lamar.edu/classes/de/wronskian.aspx """ import math @@ -138,3 +140,4 @@ def main() -> None: if __name__ == "__main__": main() # doctest: +SKIP + From 8e0db7cb8fafb867ac60fb670683c2134d33669a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 16:17:39 +0000 Subject: [PATCH 5/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/wronskian_second_order_de.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index 077859b1bd8d..3b6b15f91f21 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -17,7 +17,10 @@ import math import cmath -def compute_characteristic_roots(a: float, b: float, c: float) -> tuple[complex, complex]: + +def compute_characteristic_roots( + a: float, b: float, c: float +) -> tuple[complex, complex]: """ Compute characteristic roots for a second-order homogeneous linear DE. @@ -29,7 +32,7 @@ def compute_characteristic_roots(a: float, b: float, c: float) -> tuple[complex, if a == 0: raise ValueError("Coefficient 'a' cannot be zero for a second-order equation.") - discriminant = b ** 2 - 4 * a * c + discriminant = b**2 - 4 * a * c sqrt_disc = cmath.sqrt(discriminant) root1 = (-b + sqrt_disc) / (2 * a) root2 = (-b - sqrt_disc) / (2 * a) @@ -137,7 +140,5 @@ def main() -> None: analyze_differential_equation(a, b, c) - if __name__ == "__main__": - main() # doctest: +SKIP - + main() # doctest: +SKIP From 8249eeaf0267446d4eb336a7fc93718eba84a5c5 Mon Sep 17 00:00:00 2001 From: Venkat Thadi Date: Thu, 9 Oct 2025 22:01:27 +0530 Subject: [PATCH 6/9] Update wronskian_second_order_de.py --- maths/wronskian_second_order_de.py | 39 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index 3b6b15f91f21..4cf32890c0ac 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -14,16 +14,15 @@ References: https://tutorial.math.lamar.edu/classes/de/wronskian.aspx """ -import math import cmath - def compute_characteristic_roots( a: float, b: float, c: float ) -> tuple[complex, complex]: """ Compute characteristic roots for a second-order homogeneous linear DE. - + a, b, c -> coefficients + >>> compute_characteristic_roots(1, -3, 2) (2.0, 1.0) >>> compute_characteristic_roots(1, 2, 5) @@ -65,19 +64,27 @@ def classify_solution_type(root1: complex, root2: complex) -> str: return "Distinct Real Roots" -def compute_wronskian(f, g, f_prime, g_prime, x: float) -> float: +def compute_wronskian( + function_1: Callable[[float], float], + function_2: Callable[[float], float], + derivative_1: Callable[[float], float], + derivative_2: Callable[[float], float], + evaluation_point: float +) -> float: """ - Compute Wronskian determinant W(f, g) = f * g' - f' * g. - - >>> import math - >>> def f(x): return math.exp(x) - >>> def g(x): return x * math.exp(x) - >>> def f_prime(x): return math.exp(x) - >>> def g_prime(x): return math.exp(x) + x * math.exp(x) - >>> round(compute_wronskian(f, g, f_prime, g_prime, 0), 3) - 1.0 + Compute the Wronskian of two functions at a given point. + + Parameters: + function_1 (Callable[[float], float]): The first function f(x). + function_2 (Callable[[float], float]): The second function g(x). + derivative_1 (Callable[[float], float]): Derivative of the first function f'(x). + derivative_2 (Callable[[float], float]): Derivative of the second function g'(x). + evaluation_point (float): The point x at which to evaluate the Wronskian. + + Returns: + float: Value of the Wronskian at the given point. """ - return f(x) * g_prime(x) - f_prime(x) * g(x) + return function_1(evaluation_point) * derivative_2(evaluation_point) - function_2(evaluation_point) * derivative_1(evaluation_point) def construct_general_solution(root1: complex, root2: complex) -> str: @@ -104,7 +111,8 @@ def construct_general_solution(root1: complex, root2: complex) -> str: def analyze_differential_equation(a: float, b: float, c: float) -> None: """ Analyze the DE and print the roots, type, and general solution. - + a, b, c -> coefficients + >>> analyze_differential_equation(1, -3, 2) # doctest: +ELLIPSIS Characteristic Roots: (2.0, 1.0) Solution Type: Distinct Real Roots @@ -142,3 +150,4 @@ def main() -> None: if __name__ == "__main__": main() # doctest: +SKIP + From 4bbaafc2a90c1a3f1f7c58a756ab0bf810d2d19e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 16:31:47 +0000 Subject: [PATCH 7/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/wronskian_second_order_de.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index 4cf32890c0ac..ae89ed4b0922 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -16,13 +16,14 @@ import cmath + def compute_characteristic_roots( a: float, b: float, c: float ) -> tuple[complex, complex]: """ Compute characteristic roots for a second-order homogeneous linear DE. a, b, c -> coefficients - + >>> compute_characteristic_roots(1, -3, 2) (2.0, 1.0) >>> compute_characteristic_roots(1, 2, 5) @@ -69,7 +70,7 @@ def compute_wronskian( function_2: Callable[[float], float], derivative_1: Callable[[float], float], derivative_2: Callable[[float], float], - evaluation_point: float + evaluation_point: float, ) -> float: """ Compute the Wronskian of two functions at a given point. @@ -84,7 +85,9 @@ def compute_wronskian( Returns: float: Value of the Wronskian at the given point. """ - return function_1(evaluation_point) * derivative_2(evaluation_point) - function_2(evaluation_point) * derivative_1(evaluation_point) + return function_1(evaluation_point) * derivative_2(evaluation_point) - function_2( + evaluation_point + ) * derivative_1(evaluation_point) def construct_general_solution(root1: complex, root2: complex) -> str: @@ -112,7 +115,7 @@ def analyze_differential_equation(a: float, b: float, c: float) -> None: """ Analyze the DE and print the roots, type, and general solution. a, b, c -> coefficients - + >>> analyze_differential_equation(1, -3, 2) # doctest: +ELLIPSIS Characteristic Roots: (2.0, 1.0) Solution Type: Distinct Real Roots @@ -150,4 +153,3 @@ def main() -> None: if __name__ == "__main__": main() # doctest: +SKIP - From ee7d5cbf9ee63e4c93e7d7031ce2658d9af1263b Mon Sep 17 00:00:00 2001 From: Venkat Thadi Date: Thu, 9 Oct 2025 22:03:42 +0530 Subject: [PATCH 8/9] Update wronskian_second_order_de.py --- maths/wronskian_second_order_de.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index ae89ed4b0922..7fefa4d7181f 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -1,6 +1,7 @@ """ wronskian_second_order_de.py -A symbolic and numerical exploration of the Wronskian for second-order linear differential equations. +A symbolic and numerical exploration of the Wronskian +for second-order linear differential equations. This program: 1. Takes coefficients (a, b, c) for a*y'' + b*y' + c*y = 0. @@ -65,12 +66,14 @@ def classify_solution_type(root1: complex, root2: complex) -> str: return "Distinct Real Roots" +from typing import Callable + def compute_wronskian( function_1: Callable[[float], float], function_2: Callable[[float], float], derivative_1: Callable[[float], float], derivative_2: Callable[[float], float], - evaluation_point: float, + evaluation_point: float ) -> float: """ Compute the Wronskian of two functions at a given point. @@ -85,9 +88,8 @@ def compute_wronskian( Returns: float: Value of the Wronskian at the given point. """ - return function_1(evaluation_point) * derivative_2(evaluation_point) - function_2( - evaluation_point - ) * derivative_1(evaluation_point) + return function_1(evaluation_point) * derivative_2(evaluation_point) - \ + function_2(evaluation_point) * derivative_1(evaluation_point) def construct_general_solution(root1: complex, root2: complex) -> str: @@ -153,3 +155,4 @@ def main() -> None: if __name__ == "__main__": main() # doctest: +SKIP + From c639ca21fda95670d207ef62413548101c64cf92 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 16:34:03 +0000 Subject: [PATCH 9/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/wronskian_second_order_de.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/maths/wronskian_second_order_de.py b/maths/wronskian_second_order_de.py index 7fefa4d7181f..2577f8d09b6e 100644 --- a/maths/wronskian_second_order_de.py +++ b/maths/wronskian_second_order_de.py @@ -1,6 +1,6 @@ """ wronskian_second_order_de.py -A symbolic and numerical exploration of the Wronskian +A symbolic and numerical exploration of the Wronskian for second-order linear differential equations. This program: @@ -68,12 +68,13 @@ def classify_solution_type(root1: complex, root2: complex) -> str: from typing import Callable + def compute_wronskian( function_1: Callable[[float], float], function_2: Callable[[float], float], derivative_1: Callable[[float], float], derivative_2: Callable[[float], float], - evaluation_point: float + evaluation_point: float, ) -> float: """ Compute the Wronskian of two functions at a given point. @@ -88,8 +89,9 @@ def compute_wronskian( Returns: float: Value of the Wronskian at the given point. """ - return function_1(evaluation_point) * derivative_2(evaluation_point) - \ - function_2(evaluation_point) * derivative_1(evaluation_point) + return function_1(evaluation_point) * derivative_2(evaluation_point) - function_2( + evaluation_point + ) * derivative_1(evaluation_point) def construct_general_solution(root1: complex, root2: complex) -> str: @@ -155,4 +157,3 @@ def main() -> None: if __name__ == "__main__": main() # doctest: +SKIP -