0
import evaluar 
from pylab import * 
from numpy import *

def puntofijo(po,TOL, N): 
 vectorx = zeros (N, Float64)
 vectory = zeros (N, Float64)

i = 1 
while i<=N :
 vectorx[i-1] = po 
Evaluar.dicc_seguro['x']=po 
fp = eval(Evaluar.funcion, {"__builtins__":None}, Evaluar.dicc_seguro) 
vectory[i-1]=fp                                                                      
if fabs(po-fp):
 print "La raiz buscada es: ",po, "con", i-1, "iteraciones" 
 sys.exit()
i = i+1 
po = fp 
quit() [vectorx,vectory]

def dibujar(po,TOL, ): 
 x = arange(po-2,po+2,0.1) 
vectores=puntofijo(po, TOL, Y)

subplot(211) 
plot(x, eval(Evaluar.funcion), linewidth=1.0) 
xlabel('Abcisa') 
ylabel('Ordenada') 
title('Metodo Punto Fijo con f(x)= 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() 
3
Contributors
4
Replies
37
Views
2 Years
Discussion Span
Last Post by rubberman
1
def puntofijo(po,TOL, N): 
 vectorx = zeros (N, Float64)
 vectory = zeros (N, Float64)

i = 1 
while i<=N :
 vectorx[i-1] = po 
Evaluar.dicc_seguro['x']=po 
fp = eval(Evaluar.funcion, {"__builtins__":None}, Evaluar.dicc_seguro) 
vectory[i-1]=fp                                                                      
if fabs(po-fp):
 print "La raiz buscada es: ",po, "con", i-1, "iteraciones" 
 sys.exit()
i = i+1 
po = fp 
quit() [vectorx,vectory]

I assume that this is all supposed to be a single function, correct? If so, then the indentation is off, starting at line 9 (the i = 1 line). Try:

import evaluar 
from pylab import * 
from numpy import *

def puntofijo(po,TOL, N): 
    vectorx = zeros (N, Float64)
    vectory = zeros (N, Float64)

    i = 1 
    while i<=N :
        vectorx[i-1] = po 
    Evaluar.dicc_seguro['x']=po 
    fp = eval(Evaluar.funcion, {"__builtins__":None}, Evaluar.dicc_seguro)
    vectory[i-1]=fp     
    if fabs(po-fp):
        print "La raiz buscada es: ",po, "con", i-1, "iteraciones" 
        sys.exit()
    i = i+1 
    po = fp 
    quit() [vectorx,vectory]

def dibujar(po,TOL, ): 
    x = arange(po-2,po+2,0.1) 
    vectores=puntofijo(po, TOL, Y)

    subplot(211) 
    plot(x, eval(Evaluar.funcion), linewidth=1.0) 
    xlabel('Abcisa') 
    ylabel('Ordenada')
    title('Metodo Punto Fijo con f(x)= 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() 

Note that the convention in Python is to use four spaces for indentation, not two. Also, what is the line quit() [vectorx,vectory] meant to do? I am pretty sure that the list following the quit() call is likely to give you a syntax error. For that matter, where is the function quit() coming from? If you are intending to return the pair [vectorx, vectory] as the function return value, you would use return vectorx, vectory instead.

Edited by Schol-R-LEA

0

I copy your code but throw this error

File "C:\Users\manuela\Desktop\Metodos\PuntoFijo.py", line 20
    break 
    ^
IndentationError: unexpected indent

thanks

1

Interesting. There are no break statements in the code you posted, which leads me to think that this is from theevaluar module which you are importing, or else some other file that it in turn imports.

0

Stupid Python indentation rules! One of the many reasons I despise the language! Personally, I think the authors of the language took their Monty Python analogies way too far! Not to mention that they were too lazy to input a couple of squiggly braces to scope stuff. Who knows. Maybe their keyboard(s) were broken and the squiggly braces didn't work!

Ok. Done ranting now... :-)

Edited by rubberman

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.