# copy and paste this code into Python Fiddle editor # website: www.pythonfiddle.com from math import * # change the function and derivative to match # your function and its derivative def f(x): # the function return 48*x*pow(1+x,60) - pow(1+x,60) + 1 def df(x): # the derivative return pow(1+x,59)*(48*(1+x)+48*60*x-60) x = 0.1 # initial guess for i in range(20): # range(c) means c times y = f(x) # function dy = df(x) # derivative nextx = x - y/dy print nextx x = nextx
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