import math def funcion (x): return ((x**2) + (math.e**(-2*x))-(2*(math.e**(-1*x))*x))/1.0 def derivadaDeLaFuncion (x): return (2*(math.e**(-2*x))*((math.e**x)+1)*(((math.e**x)*x)-1))/1.0 i=1 p0=4 TOL=10**-8 print "tol es" print TOL iteraciones=100 while i < iteraciones: p=(p0-(funcion(p0)/derivadaDeLaFuncion(p0)))/1.0 if abs(p-p0)<TOL: print "La raiz esta en p= :" print p print "Encontrado en la iteracion numero: " print i break i=i+1 p0=p print "Se agotaron las iteraciones"
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