#program starts here from math import * def f(x): #Make function for formula f(x) return exp(x)*sin(x) def g(x):# Make function for formula g(x) return (x**3)/10. def h(x):#Combine f(x) and g(x) into h(x) return f(x) - g(x) def seeker(): a = 2. #initial values b = 5. while 1: #while 1 means that this while loop goes on forever until break c = 0.5 * (a+b) ha = h(a) #calculate values of h hb = h(b) hc = h(c) if abs(h(c)) <= 1*10**(-4): #check if c matches interval return c elif hc * hb > 0: #if h(c) and h(b) have same sign, b=c b = c else: a = c print seeker() #line 32 is for measuring runtime
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question