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

Bisecção
O dia que bosta valesse ouro.
Os pobres todos nascerão sem c*.
Grafitti.

Testar

Python Listing: ../Run.Bisection.py.
from Bisection import *
from Functions import *

fs=[f1,f2]
n=1
for f in fs:
    xs=Bisection(f,-3.0,3.0,1.0E-6)
    print "f_"+str(n)+":"
    Print(f,xs)
    n+=1

Output:

f_1:
N    x_k    |f(x_k)|
01    -1.500000    1.250000e+00
02    -0.750000    4.375000e-01
03    -1.125000    2.656250e-01
04    -0.937500    1.210938e-01
05    -1.031250    6.347656e-02
06    -0.984375    3.100586e-02
07    -1.007812    1.568604e-02
08    -0.996094    7.797241e-03
09    -1.001953    3.910065e-03
10    -0.999023    1.952171e-03
11    -1.000488    9.768009e-04
12    -0.999756    4.882216e-04
13    -1.000122    2.441555e-04
14    -0.999939    1.220666e-04
15    -1.000031    6.103609e-05
16    -0.999985    3.051735e-05
17    -1.000008    1.525885e-05
18    -0.999996    7.629380e-06
19    -1.000002    3.814701e-06
20    -0.999999    1.907348e-06
21    -1.000000    9.536745e-07
f_2:
N    x_k    |f(x_k)|
01    -1.500000    4.375000e-01
02    -2.250000    1.450391e+01
03    -1.875000    4.328369e+00
04    -1.687500    1.413834e+00
05    -1.593750    3.717203e-01
06    -1.546875    6.004614e-02
07    -1.570312    1.488081e-01
08    -1.558594    4.265402e-02
09    -1.552734    9.124041e-03
10    -1.555664    1.665753e-02
11    -1.554199    3.739935e-03
12    -1.553467    2.698747e-03
13    -1.553833    5.189193e-04
14    -1.553650    1.090333e-03
15    -1.553741    2.858112e-04
16    -1.553787    1.165279e-04
17    -1.553764    8.464822e-05
18    -1.553776    1.593820e-05
19    -1.553770    3.435542e-05
20    -1.553773    9.208712e-06
21    -1.553774    3.364718e-06
22    -1.553774    2.922004e-06
23    -1.553774    2.213553e-07

Output from: /usr/bin/python ../Run.Bisection.py
Messages:
0 secs.