1
2
3 from __future__ import division, absolute_import
4
5 __author__ = "Eduardo dos Santos Pereira"
6 __email__ = "pereira.somoza@gmail.com"
7 __credits__ = ["Eduardo dos Santos Pereira"]
8 __license__ = "GPLV3"
9 __version__ = "1.0.1"
10 __maintainer__ = "Eduardo dos Santos Pereira"
11 __status__ = "Stable"
12 """
13
14 This file is part of pystar.
15 copyright : Eduardo dos Santos Pereira
16 31 mar. 2011.
17
18 pystar is free software: you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation, either version 3 of the License.
21 pystar is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
28
29 Fornce as funcoes locate(xx,n,x), dfridr(func,x,h,err) e
30 int_simples(func,a,b,dx =0.001)
31 """
32
33 from numpy.numarray import zeros, Float64
34 from numpy import abs
35
36
38 """Localiza a posicao de dado ponto a partir de dois adjacentes.
39
40 argumentos: func --- funcao ou tabela de entrada
41 xx --- tabela de entrada
42 n --- numero de pontos da tabela
43 x --- valor de x que se deseja determinar y
44 j --- posicao de saida
45 """
46 jl = 0
47 ju = n + 1
48 while(ju - jl > 1):
49 jm = int((ju + jl) / 2)
50 if(xx[n] > xx[1] and x > xx[jm]):
51 jl = jm
52 else:
53 ju = jm
54 return jl
55
56
58 '''Fornece a derivada de y em relacao a x.
59 argumentos: func --- funcao a ser integrada
60 x --- dlog10 m ou z
61 h --- passo para a diferencicao
62 err --- parametro interno de erro da function
63 '''
64 CON = 1.4
65 CON2 = CON * CON
66
67 NTAB = 10
68
69 dfit = 0.0
70 a = zeros((NTAB, NTAB), type=Float64)
71 if(h == 0):
72 print('h tem que ser diferente de zero')
73 return
74 hh = h
75 a[0, 0] = (func(x + hh) - func(x - hh)) / (2.0 * hh)
76 for i in range(1, NTAB):
77 hh = hh / CON
78 a[0, i] = (func(x + hh) - func(x - hh)) / (2.0 * hh)
79 fac = CON2
80 for j in range(1, i):
81 a[j, i] = (a[j - 1, i] * fac - a[j - 1, i - 1]) / (fac - 1.0)
82 fac = CON2 * fac
83 a1 = a[j, i] - a[j - 1, i]
84 a2 = a[j, i] - a[j - 1, i - 1]
85 errt = max(abs(a1), abs(a2))
86 if (errt >= err):
87 err = errt
88 dfit = a[j, i]
89 return dfit
90 return None
91