1
+ #Feito por Hevenicio Silva
2
+
3
+ # Importação de biblitecas
4
+ from IPython .display import display , Markdown , Latex
5
+ import matplotlib .pyplot as plt
6
+ import pandas as pd
7
+ import sympy as sym
8
+ import numpy as np
9
+
10
+ # Entrada de dados
11
+ dados = pd .read_csv ("dados.csv" )
12
+ df = pd .DataFrame (dados )
13
+
14
+ # Função Fatorial
15
+ def fatorial (n ):
16
+ if (n == 0 ):
17
+ return 1
18
+ else :
19
+ return n * fatorial (n - 1 )
20
+
21
+
22
+ # Formatação dos dados impressos - Latex
23
+ def printmd (string ):
24
+ display (Markdown (string ))
25
+ #display(Latex(string))
26
+
27
+ f = sym .symbols ('$_{0}$' )
28
+ g = sym .symbols ('$_{1}$' )
29
+ h = sym .symbols ('$_{2}$' )
30
+
31
+
32
+ # Definindo as Funções de Bessel
33
+ def J0 (x ):
34
+ k = 0
35
+ soma = 0
36
+ termo = 1
37
+ while (1.0e-4 <= termo ):
38
+ termo = pow (x / 2 , (2 * k ))/ (fatorial (k )* fatorial (k ))
39
+ soma += pow (- 1 , k )* termo
40
+ k += 1
41
+ return soma
42
+
43
+ def J1 (x ):
44
+ k = 0
45
+ soma = 0
46
+ termo = 1
47
+ while (1.0e-4 <= termo ):
48
+ termo = pow (x / 2 , (2 * k + 1 ))/ (fatorial (k )* fatorial (k + 1 ))
49
+ soma += pow (- 1 , k )* termo
50
+ k += 1
51
+ return soma
52
+
53
+ def J2 (x ):
54
+ k = 0
55
+ soma = 0
56
+ termo = 1
57
+ while (1.0e-4 <= termo ):
58
+ termo = pow (x / 2 , (2 * k + 2 ))/ (fatorial (k )* fatorial (k + 2 ))
59
+ soma += pow (- 1 , k )* termo
60
+ k += 1
61
+ return soma
62
+
63
+ # Amplitude da função de Bessel
64
+ y = np .sqrt (2 / (np .pi * df ['entrada' ]))
65
+
66
+ z = - np .sqrt (2 / (np .pi * df ['entrada' ]))
67
+
68
+ # Resultados obtidos
69
+ l = []
70
+ m = []
71
+ n = []
72
+ o = []
73
+ p = [l , m , n , o ]
74
+ for i in df ['entrada' ]:
75
+ l .append (i )
76
+ m .append (J0 (i ))
77
+ n .append (J1 (i ))
78
+ o .append (J2 (i ))
79
+ #printmd('**$J${}({}): {: 0.5f} $|$ $J${}({}): {: 0.5f} $|$ $J${}({}): {: 0.5f}**'.format(f, i, J0(i), g, i, J1(i), h, i, J2(i)))
80
+ a = pd .DataFrame (p )
81
+ a = a .rename (index = {0 :"x" , 1 :"J0(x)" , 2 : "J1(x)" , 3 :"J2(x)" }).T
82
+ print (a )
83
+
84
+ # Plotando os resultados obtidos
85
+ plt .title ('Funções de Bessel - J$_{0}(x)$, J$_{1}(x)$ e J$_{2}(x)$' )
86
+ plt .plot (df ['entrada' ], m , 'g' , label = 'J$_{0}(x)$' )
87
+ plt .plot (df ['entrada' ], n , 'limegreen' , label = 'J$_{1}(x)$' )
88
+ plt .plot (df ['entrada' ], o , 'lawngreen' , label = 'J$_{2}(x)$' )
89
+ plt .plot (df ['entrada' ], y , 'c--' , label = '$\sqrt{2 / \pi x}$' )
90
+ plt .plot (df ['entrada' ], z , 'b--' , label = '$ - \sqrt{2 / \pi x}$' )
91
+ plt .legend (framealpha = 1 , frameon = True )
92
+ plt .grid (color = 'black' )
93
+ plt .style .use ('seaborn' )
94
+ plt .xlabel ('$x$' )
95
+ plt .ylabel ('$y$' )
96
+ plt .show ()
0 commit comments