``````#!/usr/bin/python
import Evaluar
from pylab import *
from numpy import *

def biseccion(a, b, TOL, N):
Evaluar.dicc_seguro['x']=a
fa = eval(Evaluar.funcion, {"__builtins__":None}, Evaluar.dicc_seguro)

vectorx = zeros(N, Float64)
vectory = zeros(N, Float64)

i = 1
while i<=N :
p = (a+b)/2.0
vectorx[i-1] = p
Evaluar.dicc_seguro['x']=p
fp = eval(Evaluar.funcion, {"__builtins__":None}, Evaluar.dicc_seguro)
vectory[i-1]=fp
if (fp == 0.0) or ((b-a)/2.0)<tol:
print "La raiz buscada es: ",p, "con", i-1, "iteraciones"
break
i = i+1
if (fa*fp)>0 :
a = p
else :
b = p

return [vectorx, vectory]

def dibujar(a,b, TOL, N):
x = arange(a,b,0.1)
vectores=biseccion(a, b, TOL, N)

subplot(211)
plot(x, eval(Evaluar.funcion), linewidth=1.0)
xlabel('Abcisa')
ylabel('Ordenada')
title('Metodo Biseccion con f(x)=' + Evaluar.funcion)
grid(True)
axhline(linewidth=1, color='r')
axvline(linewidth=1, color='r')

subplot(212)
plot(vectores[0], vectores[1], 'k.')
xlabel('Abcisa')
ylabel('Ordenada')
grid(True)
axhline(linewidth=1, color='r')
axvline(linewidth=1, color='r')

show()

error

fa = eval(Evaluar.funcion, {"__builtins__":None}, Evaluar.dicc_seguro)
File "<string>", line 1, in <module>
TypeError: 'NoneType' object is not callable
``````

Edited by pritaeas: Moved to Python.

2
Contributors
1
Reply
47
Views
2 Years
Discussion Span
Last Post by Gribouillis

We don't know which string you are evaluating; can you add

``````raise RuntimeError(repr(Evaluar.funcion))
``````

immediately before `fa = eval(...` and post the error output ?

Edited by Gribouillis

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.