|
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
|
|
O aspecto mais triste da humanidade hoje
É que ela cresce mais em ciência do que em sabedoria.
Isaac Asimov
|
Atividade #1.3.01:
Crie um arquivo, Functions2.py, implementando as seguintes funções:
-
\(f_{1}(x)=x^2+x-6, \quad \varphi_1(x)= \sqrt{6-x}, \quad x_0=1.5;\)
-
\(f_{2}(x)=x^2+x-6, \quad \varphi_2(x)= \frac{6}{x}-1, \quad x_0=-2.5;\)
-
\(f_{2}(x)=x^3-9x+3, \quad \varphi_2(x)= \frac{1}{9} x^3+\frac{1}{3}, \quad x_0=0.5;\)
Crie um executavel, Run.Fixed_Point.py, executando o algoritmo Pointo Fixo, conforme indicado acima.
Python Listing: ../../Run.Fixed_Point.py.
from Fixed_Point import *
from Functions import *
from Functions2 import *
fs=[f1,f2,f3]
phis=[phi1,phi2,phi3]
x0s=[1.5,-2.5,0.5]
n=0
for f in fs:
phi=phis[n]
xs=Fixed_Point(f,phi,x0s[n],1.0E-6)
#print f
print "f"+str(n+1)+" phi"+str(n+1)
Print(f,xs)
n+=1
|
f1 phi1
N x_k |f(x_k)|
01 1.500000 2.250000e+00
02 2.121320 6.213203e-01
03 1.969436 1.518840e-01
04 2.007626 3.818998e-02
05 1.998092 9.533865e-03
06 2.000477 2.384319e-03
07 1.999881 5.960265e-04
08 2.000030 1.490100e-04
09 1.999993 3.725228e-05
10 2.000002 9.313083e-06
11 2.000000 2.328270e-06
12 2.000000 5.820675e-07
f2 phi2
N x_k |f(x_k)|
01 -2.500000 2.250000e+00
02 -3.400000 2.160000e+00
03 -2.764706 1.121107e+00
04 -3.170213 8.800362e-01
05 -2.892617 5.253817e-01
06 -3.074246 3.767422e-01
07 -2.951698 2.391764e-01
08 -3.032728 1.647121e-01
09 -2.978417 1.074509e-01
10 -3.014493 7.267587e-02
11 -2.990384 4.798582e-02
12 -3.006431 3.219661e-02
13 -2.995722 2.137267e-02
14 -3.002856 1.428918e-02
15 -2.998098 9.508004e-03
16 -3.001269 6.346716e-03
17 -2.999154 4.227566e-03
18 -3.000564 2.819967e-03
19 -2.999624 1.879272e-03
20 -3.000251 1.253162e-03
21 -2.999833 8.353016e-04
22 -3.000111 5.569297e-04
23 -2.999926 3.712589e-04
24 -3.000050 2.475182e-04
25 -2.999967 1.650067e-04
26 -3.000022 1.100069e-04
27 -2.999985 7.333684e-05
28 -3.000010 4.889171e-05
29 -2.999993 3.259426e-05
30 -3.000004 2.172960e-05
31 -2.999997 1.448636e-05
32 -3.000002 9.657591e-06
33 -2.999999 6.438386e-06
34 -3.000001 4.292261e-06
35 -2.999999 2.861506e-06
36 -3.000000 1.907671e-06
f3 phi3
N x_k |f(x_k)|
01 0.500000 1.375000e+00
02 0.347222 8.313775e-02
03 0.337985 3.253021e-03
04 0.337623 1.237357e-04
05 0.337609 4.701331e-06
06 0.337609 1.786192e-07
Output from: /usr/bin/python ../../Run.Fixed_Point.py
|
|
Messages:
0 secs.
|