Corrected typo in function name and doctests. rkf45.py (#10518)

* Corrected typo in function name and doctests. rkf45.py

There was a mistake in name of function (runge_futta_fehlberg instead of runge_kutta_fehlberg) . I have corrected this in function name and  also doctest.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename rkf45.py to runge_kutta_fehlberg_45.py

* Update runge_kutta_fehlberg_45.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
Ravi Kumar 2023-10-15 16:25:56 +05:30 committed by GitHub
parent 85cdb93a0d
commit 777eca813a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ from collections.abc import Callable
import numpy as np import numpy as np
def runge_futta_fehlberg_45( def runge_kutta_fehlberg_45(
func: Callable, func: Callable,
x_initial: float, x_initial: float,
y_initial: float, y_initial: float,
@ -33,33 +33,35 @@ def runge_futta_fehlberg_45(
# exact value of y[1] is tan(0.2) = 0.2027100937470787 # exact value of y[1] is tan(0.2) = 0.2027100937470787
>>> def f(x, y): >>> def f(x, y):
... return 1 + y**2 ... return 1 + y**2
>>> y = runge_futta_fehlberg_45(f, 0, 0, 0.2, 1) >>> y = runge_kutta_fehlberg_45(f, 0, 0, 0.2, 1)
>>> y[1] >>> y[1]
0.2027100937470787 0.2027100937470787
>>> def f(x,y): >>> def f(x,y):
... return x ... return x
>>> y = runge_futta_fehlberg_45(f, -1, 0, 0.2, 0) >>> y = runge_kutta_fehlberg_45(f, -1, 0, 0.2, 0)
>>> y[1] >>> y[1]
-0.18000000000000002 -0.18000000000000002
>>> y = runge_futta_fehlberg_45(5, 0, 0, 0.1, 1) >>> y = runge_kutta_fehlberg_45(5, 0, 0, 0.1, 1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: 'int' object is not callable TypeError: 'int' object is not callable
>>> def f(x, y): >>> def f(x, y):
... return x + y ... return x + y
>>> y = runge_futta_fehlberg_45(f, 0, 0, 0.2, -1) >>> y = runge_kutta_fehlberg_45(f, 0, 0, 0.2, -1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: The final value x must be greater than initial value of x. ValueError: The final value of x must be greater than initial value of x.
>>> def f(x, y): >>> def f(x, y):
... return x ... return x
>>> y = runge_futta_fehlberg_45(f, -1, 0, -0.2, 0) >>> y = runge_kutta_fehlberg_45(f, -1, 0, -0.2, 0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Step size must be positive. ValueError: Step size must be positive.
""" """
if x_initial >= x_final: if x_initial >= x_final:
raise ValueError("The final value x must be greater than initial value of x.") raise ValueError(
"The final value of x must be greater than initial value of x."
)
if step_size <= 0: if step_size <= 0:
raise ValueError("Step size must be positive.") raise ValueError("Step size must be positive.")