From 61e1dd27b0db00302cec75fca5365d08e81ab707 Mon Sep 17 00:00:00 2001 From: poloso Date: Thu, 28 Oct 2021 15:31:32 -0500 Subject: [PATCH] [mypy] Fix type annotation in euler_method.py (#5649) * [mypy] Fix type annotation in euler_method.py In line with issue #4052. * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> --- DIRECTORY.md | 1 + maths/euler_method.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index a8986f195..434cddbfd 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -186,6 +186,7 @@ * [Swap Nodes](https://github.com/TheAlgorithms/Python/blob/master/data_structures/linked_list/swap_nodes.py) * Queue * [Circular Queue](https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/circular_queue.py) + * [Circular Queue Linked List](https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/circular_queue_linked_list.py) * [Double Ended Queue](https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/double_ended_queue.py) * [Linked Queue](https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/linked_queue.py) * [Priority Queue Using List](https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/priority_queue_using_list.py) diff --git a/maths/euler_method.py b/maths/euler_method.py index 7c7801986..155ef28d1 100644 --- a/maths/euler_method.py +++ b/maths/euler_method.py @@ -1,18 +1,25 @@ +from typing import Callable + import numpy as np -def explicit_euler(ode_func, y0, x0, step_size, x_end): - """ - Calculate numeric solution at each step to an ODE using Euler's Method +def explicit_euler( + ode_func: Callable, y0: float, x0: float, step_size: float, x_end: float +) -> np.ndarray: + """Calculate numeric solution at each step to an ODE using Euler's Method - https://en.wikipedia.org/wiki/Euler_method + For reference to Euler's method refer to https://en.wikipedia.org/wiki/Euler_method. - Arguments: - ode_func -- The ode as a function of x and y - y0 -- the initial value for y - x0 -- the initial value for x - stepsize -- the increment value for x - x_end -- the end value for x + Args: + ode_func (Callable): The ordinary differential equation + as a function of x and y. + y0 (float): The initial value for y. + x0 (float): The initial value for x. + step_size (float): The increment value for x. + x_end (float): The final value of x to be calculated. + + Returns: + np.ndarray: Solution of y for every step in x. >>> # the exact solution is math.exp(x) >>> def f(x, y):