Last active
October 6, 2019 09:43
-
-
Save hamzaavvan/c53fa6031a2e17a27b5009faf5fb2ba4 to your computer and use it in GitHub Desktop.
Python Secant Method Code
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
x1=int(input("Enter x1: ")) | |
x2=int(input("Enter x2: ")) | |
def f(x): | |
return x**4 - x - 10 | |
def form(x1, x2): | |
return ((x1 * f(x2) - x2 * f(x1)) / | |
(f(x2) - f(x1))) | |
def secant(x1, x2, E): | |
xm = 0; xnew = 0 | |
while True: | |
xnew = form(x1, x2) | |
x1 = x2 | |
x2 = xnew | |
xm = form(x1, x2) | |
print(xnew) | |
if(abs(xm - xnew) < E): | |
break | |
secant(x1, x2, 1e-5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Numerical Computing