Created
October 29, 2022 22:53
-
-
Save arskiy/7aee8ad2f7cfac5ff7a5bf0c0a27301c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
x = var('x') | |
f(x) = (x-80)*(x-52.2)*(x-4.4)*(x+3)*(x+70.2)*(x+7.4) | |
fp = diff(f,x) | |
NewtonIteration(x) = x - f(x)/fp(x) | |
roots = [] | |
for i in np.arange(-100.0, 100.0, 0.2): | |
xn = i | |
# avoid possible infinite cycle | |
for j in range(100): | |
xn_1 = N(NewtonIteration(xn),digits=20); | |
if xn == xn_1: | |
if xn not in roots: | |
roots.append(xn) | |
break | |
xn = xn_1 | |
print(roots) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment