Skip to content

Commit 9d14f54

Browse files
author
Venn
committed
Função de Bessel em Python - Dados completos
1 parent 7dd43eb commit 9d14f54

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

Bessel.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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()

dados.csv

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
entrada
2+
0.0
3+
0.5
4+
1.0
5+
1.5
6+
2.0
7+
2.5
8+
3.0
9+
3.5
10+
4.0
11+
4.5
12+
5.0
13+
5.5
14+
6.0
15+
6.5
16+
7.0
17+
7.5
18+
8.0
19+
8.5
20+
9.0
21+
9.5
22+
10.0
23+
10.5
24+
11.0
25+
11.5
26+
12.0
27+
12.5
28+
13.0
29+
13.5
30+
14.0
31+
14.5
32+
15.0
33+
15.5
34+
16.0
35+
16.5
36+
17.0
37+
17.5
38+
18.0
39+
18.5
40+
19.0
41+
19.5
42+
20.0
43+
20.5
44+
21.0
45+
21.5
46+
22.0
47+
22.5
48+
23.0
49+
23.5
50+
24.0
51+
24.5
52+
25.0
53+
25.5
54+
26.0
55+
26.5
56+
27.0
57+
27.5
58+
28.0
59+
28.5
60+
29.0
61+
29.5
62+
30.0

0 commit comments

Comments
 (0)