Diferencia entre revisiones de «Series de Fourier ABE»
De MateWiki
| (No se muestra una edición intermedia del mismo usuario) | |||
| Línea 5: | Línea 5: | ||
Ernestine Huge}} | Ernestine Huge}} | ||
| − | [[Archivo: | + | [[Archivo:Poster_ABE.png||900px]] |
| − | + | ||
<syntaxhighlight lang="python" line> | <syntaxhighlight lang="python" line> | ||
| Línea 138: | Línea 137: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | [[Categoría:EDP]] | ||
| + | [[Categoría:EDP25/26]] | ||
Revisión actual del 23:22 18 feb 2026
| Trabajo realizado por estudiantes | |
|---|---|
| Título | Series de Fourier. Grupo 6-A |
| Asignatura | EDP |
| Curso | 2025-26 |
| Autores | Andrew Fan
Bruno Aragón Ernestine Huge |
| Este artículo ha sido escrito por estudiantes como parte de su evaluación en la asignatura | |
# Plotear base trigonometrica (-pi,pi)
import numpy as np
import matplotlib.pyplot as plt
N = 4 # n hasta el que representar, el numero de terminos es 2N+1
x = np.linspace(-np.pi, np.pi, 1000)
plt.figure(figsize=(10, 6))
plt.plot(x, np.ones_like(x) / np.sqrt(2 * np.pi), label=r"$\frac{1}{\sqrt{2\pi}}$")
for n in range(1, N + 1):
plt.plot(x, (1 / np.sqrt(np.pi)) * np.cos(n * x), label=rf"$\frac{{1}}{{\sqrt{{\pi}}}}\cos({n}x)$")
plt.plot(x, (1 / np.sqrt(np.pi)) * np.sin(n * x), label=rf"$\frac{{1}}{{\sqrt{{\pi}}}}\sin({n}x)$")
plt.xlabel("x")
plt.ylabel('Valor')
plt.title(f"Representacion de los ${2*N+1}$ primeros términos de la base trigonométrica")
plt.grid(True)
plt.legend(bbox_to_anchor=(1.05, 1), loc="upper left")
plt.show()import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
def CoeficienteFourierPI2(f,N):
c0 = 1/(2*np.pi)**(1/2) * quad(lambda t: f(t),-np.pi,np.pi)[0]
c = np.zeros(N+1)
d = np.zeros(N+1)
for n in range(1,N+1):
c[n] = 1/(np.pi)**(1/2) * quad(lambda t: f(t)*np.cos(n*t),-np.pi,np.pi)[0]
d[n] = 1/(np.pi)**(1/2) * quad(lambda t: f(t)*np.sin(n*t),-np.pi,np.pi)[0]
return c0,c,d
def SerieFourierPI2(x,c0,c,d):
N = len(d)-1
S = 1/(2*np.pi)**(1/2)*c0
for n in range(1,N+1):
S += c[n]*1/(np.pi)**(1/2)*np.cos(n*x)+d[n]*1/(np.pi)**(1/2)*np.sin(n*x)
return S
#f es la función a aproximar, Nin es el mínimo n a usar, Nmax es el maximo n a usar, Nav es la
#cantidad que le suma al n mínimo en cada aproximación
def PLOTEARE2(f,Nin,Nav,Nmax,M):
n = Nin
Lista = []
Lind = []
while n<Nmax:
Lind += [n]
c0,c,d=CoeficienteFourierPI2(f,n)
Lista += [[c0,c,d]]
n+=Nav
x = np.linspace(-np.pi,np.pi,M)
fx=f(x)
plt.figure(figsize=(8,5))
plt.plot(x, fx, label="f(x)", linewidth=2)
for i in range(len(Lista)):
plt.plot(x, SerieFourierPI2(x,Lista[i][0],Lista[i][1],Lista[i][2]), label= f"Serie de Fourier $S_{{{Lind[i]}}}(x)$", linewidth="1")
plt.xlabel("x")
plt.ylabel("y")
plt.title("Aproximación de Fourier en $(-\pi,\pi)$")
plt.legend()
plt.grid(True)
plt.show()
def j(x):
return x*np.exp(-x)
def gesc(x):
if x<=0:
return 1
else:
return 0
g = np.vectorize(gesc)
PLOTEARE2(j,5,10,40,1000)
PLOTEARE2(g,5,5,25,1000)import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
def ERROR(f,N):
c0,c,d=CoeficienteFourierPI2(f,N)
error = (quad(lambda t: (f(t)-SerieFourierPI2(t,c0,c,d))**(2),-np.pi,np.pi)[0])**(1/2)
return error
def PlotearERROR(f,ninicial,nvar,Nmax):
N=Nmax
n=ninicial
s=nvar
Error=[]
Ind = []
while n<N:
Error += [ERROR(f,n)]
Ind += [n]
n+=s
plt.figure(figsize=(8,5))
plt.plot(Ind, Error, 'o-', linewidth=2)
plt.xlabel("N")
plt.ylabel(r"$\|f - S_N\|_{L^2}$")
plt.title("Error en norma $L^2$")
plt.grid(True)
plt.show()
def j(x):
return x*np.exp(-x)
def gesc(x):
if x<=0:
return 1
else:
return 0
g = np.vectorize(gesc)
PlotearERROR(j,5,5,55)
PlotearERROR(g,2,2,50)