mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Added Whitespace and Docstring (#924)
* Added Whitespace and Docstring I modified the file to make Pylint happier and make the code more readable. * Beautified Code and Added Docstring I modified the file to make Pylint happier and make the code more readable. * Added DOCSTRINGS, Wikipedia link, and whitespace I added DOCSTRINGS and whitespace to make the code more readable and understandable. * Improved Formatting * Wrapped comments * Fixed spelling error for `movement` variable * Added DOCSTRINGs * Improved Formatting * Corrected whitespace to improve readability. * Added docstrings. * Made comments fit inside an 80 column layout.
This commit is contained in:
@ -1,18 +1,25 @@
|
||||
"""Newton's Method."""
|
||||
|
||||
# Newton's Method - https://en.wikipedia.org/wiki/Newton%27s_method
|
||||
|
||||
def newton(function,function1,startingInt): #function is the f(x) and function1 is the f'(x)
|
||||
x_n=startingInt
|
||||
while True:
|
||||
x_n1=x_n-function(x_n)/function1(x_n)
|
||||
if abs(x_n-x_n1) < 10**-5:
|
||||
return x_n1
|
||||
x_n=x_n1
|
||||
|
||||
|
||||
# function is the f(x) and function1 is the f'(x)
|
||||
def newton(function, function1, startingInt):
|
||||
x_n = startingInt
|
||||
while True:
|
||||
x_n1 = x_n - function(x_n) / function1(x_n)
|
||||
if abs(x_n - x_n1) < 10**-5:
|
||||
return x_n1
|
||||
x_n = x_n1
|
||||
|
||||
|
||||
def f(x):
|
||||
return (x**3) - (2 * x) -5
|
||||
return (x**3) - (2 * x) - 5
|
||||
|
||||
|
||||
def f1(x):
|
||||
return 3 * (x**2) -2
|
||||
return 3 * (x**2) - 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(newton(f,f1,3))
|
||||
print(newton(f, f1, 3))
|
||||
|
Reference in New Issue
Block a user