SmtC: Show me the Code
Ole Peter Smith
Instituto de Matemática e Estatística
Universidade Federal de Goiás
http://www.olesmith.com.br

Secante
Quando Pedro me fala sobre Paulo
Sei mais do Pedro do que do Paulo
Sigmund Freud
< Newton-Raphson | Implementação | Atividades 1.5: >

Implementação

Python Listing: ../Secant.py.
def Secant(f,x0,x1,eps=1.0E-6,maxiteration=100):
    #List of x-values

    xk0=x0
    xk1=x1
    xs=[xk0,xk1]
    
    stop=False
    iteration=0
    while (not stop):
        dfk=(   f(xk1)-f(xk0)   )/(  xk1-xk0  )
        
        xk=xk1-f(xk1)/dfk
        
        if ( abs(f(xk))<eps   ): stop=True
        if ( abs(xk1-xk)<eps   ): stop=True
        if ( iteration>maxiteration ): stop=True
        
        xk1=xk0
        xk0=xk
        xs.append(xk)
        iteration+=1

    return xs
< Newton-Raphson | Implementação | Atividades 1.5: >
Messages:
0 secs.