MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / intersection

Function intersection

arithmetic_analysis/intersection.py:3–11  ·  view source on GitHub ↗
(function,x0,x1)

Source from the content-addressed store, hash-verified

1import math
2
3def intersection(function,x0,x1): #function is the f we want to find its root and x0 and x1 are two random starting points
4 x_n = x0
5 x_n1 = x1
6 while True:
7 x_n2 = x_n1-(function(x_n1)/((function(x_n1)-function(x_n))/(x_n1-x_n)))
8 if abs(x_n2 - x_n1) < 10**-5:
9 return x_n2
10 x_n=x_n1
11 x_n1=x_n2
12
13def f(x):
14 return math.pow(x , 3) - (2 * x) -5

Callers 1

intersection.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected