Skip to content

Instantly share code, notes, and snippets.

@hamzaavvan
Last active October 6, 2019 09:43
Show Gist options
  • Save hamzaavvan/c53fa6031a2e17a27b5009faf5fb2ba4 to your computer and use it in GitHub Desktop.
Save hamzaavvan/c53fa6031a2e17a27b5009faf5fb2ba4 to your computer and use it in GitHub Desktop.
Python Secant Method Code
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);
@hamzaavvan
Copy link
Author

Numerical Computing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment