Diferencia entre revisiones de «Series de Fourier (Grupo DMR)»

De MateWiki
Saltar a: navegación, buscar
(Código)
(Código)
Línea 181: Línea 181:
  
 
=Código=
 
=Código=
 +
Código generado junto con Chat GPT para aproximación y representación de gráficas.
 
{| class="wikitable" style="text-align:justify; width:200px; float:right; font-size:90%;"
 
{| class="wikitable" style="text-align:justify; width:200px; float:right; font-size:90%;"
 
|+ Aproximaciones mediante base trigonométrica compleja.
 
|+ Aproximaciones mediante base trigonométrica compleja.
Línea 193: Línea 194:
 
[[Archivo:Figura6RefDMR.jpg|300px|thumb|right|Representando esta función real de variable real en las mismas referencias que con <math> f^* </math>, puede comprobarse que es precisamente su proyección ortogonal en el plano horizontal, claramente con parte imaginaria nula por estar definida como parte real de una función de valores complejos.]]
 
[[Archivo:Figura6RefDMR.jpg|300px|thumb|right|Representando esta función real de variable real en las mismas referencias que con <math> f^* </math>, puede comprobarse que es precisamente su proyección ortogonal en el plano horizontal, claramente con parte imaginaria nula por estar definida como parte real de una función de valores complejos.]]
  
{{matlab|codigo=
+
<source lang="matlab">
close all
+
clc
 
clear all
 
clear all
%Trapecio
+
close all
f=@(x)x.*(1-x);
+
xx=0:0.001:1;
+
Y=zeros(10,length(xx));
+
for i = 1:10
+
    g=@(x) f(x).*sin(i.*pi.*x);
+
    a=2*trapz(xx,g(xx));
+
    h=@(x)a.*sin(i.*pi.*x);
+
    Y(i,:)=h(xx);
+
end
+
F=zeros(10,length(xx));
+
F(1,:)=Y(1,:);
+
for i= 2:10
+
    F(i,:)=sum(Y(1:i,:));
+
end
+
  
%Gráficas
+
%%% Planteamiento
Ns=[1,5,10];
+
xx = 0:10^(-3):1;
for i=1:length(Ns)
+
xy = -1:10^(-3):0;
    subplot(1,3,i)
+
haux = @(x)(4*x.*(1/2 - x).^2 + 1i*x);
    hold on
+
hauximp = @(x)-(4*x.*(1/2 - x).^2 + 1i*x);
    plot(xx,F(Ns(i),:), 'b--', "LineWidth",1)
+
yy=[hauximp(xx(end:-1:1)),haux(xx)];
    plot(xx,f(xx))
+
 
    hold off
+
%%% Comprobacion de la extension impar
    ylim([0,0.35])
+
figure(1)
    legend("f_{"+num2str(Ns(i))+"}(x)", 'f(x)')
+
plot3([xy,xx], real(yy), imag(yy), 'r', 'LineWidth', 1.75)
end
+
xline(0);
 +
yline(0);
 +
axis equal
 +
xlim([-1, 1])
 +
ylim([-1, 1])
 +
xlabel('x');
 +
ylabel('Re(f(x))');
 +
zlabel('Im(f(x))');
 +
view(3)
 +
grid on
 +
hold off
  
%Errores
 
ErrorNorma=zeros(1,10);
 
ErrorUnif=zeros(1,10);
 
for i=1:10
 
    Resta=abs(f(xx)-F(i,:));
 
    %Error norma
 
    Integral=trapz(xx,Resta.^2);
 
    ErrorNorma(i)=Integral^(1/2);
 
    %Error uniforme
 
    ErrorUnif(i)=max(Resta);
 
end
 
 
figure(2)
 
figure(2)
 
subplot(1,2,1)
 
subplot(1,2,1)
semilogy(1:10,ErrorNorma)
+
hold on
ylim([0,0.009])
+
xlabel('x');
legend('Error Norma')
+
ylabel('R');
 +
plot(xx, real(haux(xx)), 'r', 'LineWidth', 1.5)
 +
plot(xy, real(hauximp(xx(end:-1:1))), ...
 +
    'r', 'LineWidth', 1.5)
 +
title('\rm Extensión impar de la función f(x)', 'Interpreter', 'tex')
 +
grid on
 
subplot(1,2,2)
 
subplot(1,2,2)
semilogy(1:10,ErrorUnif)
+
hold on
ylim([0,0.013])
+
xlabel('x');
legend('Error Uniforme')
+
ylabel('iR');
}}
+
plot(xx, imag(haux(xx)), 'r', 'LineWidth', 1.5)
 +
plot(xy, imag(hauximp(xx(end:-1:1))), ...
 +
    'r', 'LineWidth', 1.5)
 +
title('\rm Extensión impar de la función f(x)', 'Interpreter', 'tex')
 +
grid on
  
  
 +
 +
xx=[xy,xx];
 +
N = [5,10,20]; 
 +
 +
%%% Inicializacion los vectores de errores
 +
L2_errors = zeros(length(N), 1);
 +
uniform_errors = zeros(length(N), 1);
 +
 +
aux = 1;
 +
for n = N %%% Aproximacion la funcion por la regla del trapecio
 +
    a = zeros(1, n); 
 +
    b = zeros(1, n); 
 +
    fn = trapz(xx, yy/sqrt(2)) * ones(1, length(xx));
 +
   
 +
    for k = 1:n
 +
        a(k) = trapz(xx, yy .* ...
 +
            conj(exp(1i*k*pi*xx)/sqrt(2)));
 +
        b(k) = trapz(xx, yy .* ...
 +
            conj(exp(1i*(-k)*pi*xx)/sqrt(2)));
 +
       
 +
        fn = fn + a(k) * exp(1i*k*pi*xx)/sqrt(2) + ...
 +
            b(k) * exp(1i*(-k)*pi*xx)/sqrt(2);
 +
    end
 +
   
 +
    %%% Visualizacion de los resultados
 +
    figure(3)
 +
    subplot(1, length(N), aux)
 +
    plot3(xx, real(yy), imag(yy), 'r', 'LineWidth', 1.75) 
 +
    hold on
 +
    plot3(xx, real(fn), imag(fn), 'b', 'LineWidth', 1.75) 
 +
    xline(0);
 +
    yline(0);
 +
    axis equal
 +
    xlim([-1, 1])
 +
    ylim([-1, 1])
 +
    legend({'$f(x)$', '$f_n(x)$'}, ...
 +
        'Interpreter', 'latex', 'Location', 'northwest')
 +
    xlabel('x');
 +
    ylabel('Re(f(x))');
 +
    zlabel('Im(f(x))');
 +
    title(['n = ', num2str(n)], 'Interpreter', 'latex')
 +
    view(3)
 +
    grid on
 +
    hold off
 +
 +
    % Parte real
 +
    figure(4)
 +
    subplot(1, length(N), aux)
 +
    plot3(xx, real(yy), imag(yy), 'r', 'LineWidth', 1.75) 
 +
    hold on
 +
    plot3(xx, real(fn), imag(fn), 'b', 'LineWidth', 1.75) 
 +
    xline(0);
 +
    yline(0);
 +
    axis equal
 +
    xlim([-1, 1])
 +
    ylim([-1, 1])
 +
    legend({'$f(x)$', '$f_n(x)$'}, ...
 +
        'Interpreter', 'latex', 'Location', 'northwest')
 +
    xlabel('x');
 +
    ylabel('Re(f(x))');
 +
    zlabel('Im(f(x))');
 +
    title(['n = ', num2str(n)], 'Interpreter', 'latex')
 +
    view(2)
 +
    grid on
 +
    hold off
 +
 +
    %%% Parte imaginaria
 +
    figure(5)
 +
    subplot(1, length(N), aux)
 +
    plot3(xx, imag(yy), real(yy), 'r', 'LineWidth', 1.75) 
 +
    hold on
 +
    plot3(xx, imag(fn), real(fn), 'b', 'LineWidth', 1.75) 
 +
    xline(0);
 +
    yline(0);
 +
    axis equal
 +
    xlim([-1, 1])
 +
    ylim([-1, 1])
 +
    legend({'$f(x)$', '$f_n(x)$'}, ...
 +
        'Interpreter', 'latex', 'Location', 'northwest')
 +
    xlabel('x');
 +
    ylabel('Im(f(x))');
 +
    zlabel('Re(f(x))');
 +
    title(['n = ', num2str(n)], 'Interpreter', 'latex')
 +
    view(2)
 +
    grid on
 +
    hold off
 +
   
 +
    %%% Guardamos los errores
 +
    L2_errors(aux) = sqrt(trapz(xx, abs(yy - fn).^2));
 +
    uniform_errors(aux) = max(abs(yy - fn));
 +
    aux = aux + 1;
 +
end
 +
sgtitle('Aproximación de la función por la regla del trapecio', ...
 +
    'Interpreter', 'latex');
 +
 +
%%% Visualizacion de los errores
 +
figure(6);
 +
hold on;
 +
plot(N, L2_errors, 'b-', 'LineWidth', 2);
 +
plot(N, uniform_errors, 'r--', 'LineWidth', 2); 
 +
grid on
 +
xlabel('n');
 +
ylabel('Error');
 +
legend('Error L2', 'Error uniforme');
 +
sgtitle('Errores en normas L2 y uniforme en función de n', ...
 +
    'Interpreter', 'latex');
 +
hold off;
 +
</source>
  
 
[[Categoría:EDP]]
 
[[Categoría:EDP]]
 
[[Categoría:EDP24/25]]
 
[[Categoría:EDP24/25]]

Revisión del 21:20 12 feb 2025

Trabajo realizado por estudiantes
Título Series de Fourier (Grupo DMR).
Asignatura EDP
Curso 2024-25
Autores Daniel Rodríguez Calderón, Marcos Cabellos Hernández, Rafael Pascual Ortega.
Este artículo ha sido escrito por estudiantes como parte de su evaluación en la asignatura


1 Introducción

En un espacio de Hilbert [math]L_2(a,b)[/math], una serie de Fourier converge en norma [math]L_2[/math] a una función real de variable real, [math]f[/math], que se puede representar mediante la base trigonométrica de Fourier como


[math] \quad f(x) \sim \frac{a_0}{2} + \sum_{n=1}^\infty\left[a_n\cos \left( nx \right) + b_n\sin \left( nx \right) \right] [/math].


Esta representación nos permite, tomando una suma parcial de la serie, aproximar a [math] f [/math]. Sin embargo, la base trigonométrica no se presta a la aproximación de funciones de variable real y valores complejos. Esta carencia nos lleva a la base trigonométrica compleja: considerando seno y coseno complejos, somos capaces de aproximar funciones de variable real y valores complejos o reales indistintamente. Esta base, con dominio [math] [-\pi,\pi] [/math]


[math] \quad \{e^{inx}\}_{n \in \mathbb{Z}} , [/math]


será nuestro foco de atención. La obtendremos formalmente a partir de la base trigonométrica original, para luego visualizarla y comprobar su capacidad para aproximar.

2 Base trigonométrica compleja

Para obtener la base compleja, partamos de la trigonométrica. Por la fórmula de Euler, podemos reescribir coseno y seno de la forma


[math]\quad \cos\theta = \frac{1}{2} (e^{i\theta} + e^{-i\theta}) [/math] [math]\quad[/math] y [math]\quad[/math] [math] \sin\theta = \frac{1}{2i} (e^{i\theta} - e^{-i\theta}) [/math].


Así, en [math] [-\pi,\pi] [/math], [math]f[/math] puede representarse formalmente como

Representación gráfica de la base trigonométrica compleja.
Base(DMR).gif
(Pinchar) Términos de la base [math] \{e_n := e^{ inx }\}_{n} [/math] para [math]n \in \{-1,0,1,2\}[/math] en referencia tridimensional con eje real y plano complejo.

[math]\quad f(x) \sim \frac{a_0}{2} + \sum_{n=1}^\infty\left[a_n\cos \left( nx \right) + b_n\sin \left( nx \right) \right] = \frac{a_0}{2} + \sum_{n=1}^\infty\left[\frac{a_n}{2}(e^{inx}+e^{-inx}) + \frac{b_n}{2i}(e^{inx}-e^{-inx}) \right] = [/math] [math] =c_0 + \sum_{n=1}^\infty\left[c_n e^{inx} +c_{-n} e^{-inx} \right]=[/math][math] \sum_{n=0}^\infty c_n e^{inx} + \sum_{n=-\infty}^{-1} c_n e^{inx} =\sum_{n=-\infty}^\infty c_n e^{inx}, [/math]


donde [math] c_0:=\frac{a_0}{2}[/math], [math] c_n:=\frac{a_n-ib_n}{2} [/math] y [math] c_{-n}:=\frac{a_n+ib_n}{2} [/math]. Decimos que este desarrollo es formal por el penúltimo paso:

Notemos que estamos reordenando sumandos.


De esta forma hemos obtenido la base trigonométrica compleja

[math]\quad \{e_n := e^{ inx }\}_{n \in \mathbb{Z}} [/math].


Usando el producto escalar, comprobemos que es una base ortogonal

[math]\quad (e_n,e_m)_{L^2} = \int_{-\pi}^{\pi} e_n \overline{e_m} \,dx = \int_{-\pi}^{\pi} e^{inx} e^{-imx} \,dx = \int_{-\pi}^{\pi} e^{(n-m)ix} \,dx = \frac{-i}{n-m} e^{(n-m)ix} \Big|_{-\pi}^{\pi} = 0 \quad \text{si } n \neq m, \\ [/math] [math]\quad (e_n,e_n)_{L^2} = \int_{-\pi}^{\pi} e^{(n-n)ix} \,dx = 2\pi. [/math]


Aquí fijémonos en que hemos usado el producto escalar en [math]L^2(-\pi,\pi)[/math] dado por


[math]\quad (f,g)_{L^2} = \int_{-\pi}^{\pi} f(x) \hspace{0.2cm} \overline{g(x)} \,dx [/math].


Una observación relevante es que como la norma de cada elemento de la base es siempre [math] \sqrt{2\pi} [/math], podemos ortonormalizar dividiendo precisamente por esta constante a cada elemento de la base trigonométrica compleja.

3 Extensión impar

Nos podemos plantear cómo aproximar la siguiente función [math] f [/math]

Representación gráfica de [math] f^*(x)[/math].
Figura6DMR.jpg
ImparfDMR V2.jpg
Representación de [math]f^*[/math] con eje [math]x[/math] y el plano complejo en la parte superior, mientras que representamos abajo parte real (izquierda) e imaginaria (derecha).


[math]\quad \begin{align} f: [0,1] \subseteq \mathbb{R} &\longrightarrow \mathbb{C} \\ x &\mapsto 4x(\frac{1}{2} − x)^2 + ix \end{align} [/math]

Notemos que el intervalo de definición no es simétrico. Extendamos [math] f [/math] de forma impar

[math]\quad \begin{align} f^*: [-1,1] \subseteq \mathbb{R} &\longrightarrow \mathbb{C} \\ x &\mapsto \begin{cases} 4x(\frac{1}{2} + x)^2 + ix \text{ , si } x\in [-1,0]\\ 4x(\frac{1}{2} - x)^2 + ix \text{ , si } x\in [0,1] \end{cases} \end{align} [/math]

Tras representar esta función en las imágenes adjuntas, sólo nos falta adaptar la base al nuevo intervalo. Comprobemos que como verifica


[math]\quad \{e^{\pi n ix }\}_{n \in \mathbb{Z}} : (E_n,E_m)_{L^2} = \int_{-1}^1 E_n\overline{E_m} \,dx = \int_{-1}^1 e^{\pi (n-m)i} \,dx = \begin{cases} \int_{-1}^1 1 dx = 2 \text{ , si } n = m, \\ 0 \text{ , si } n \neq m, \end{cases} [/math]


entonces es una base ortogonal, habiéndonos basado fuertemente en la periodicidad en el intervalo para el segundo caso. Además, podríamos ortonormalizar dividiendo por la norma común a todos los elementos, [math] \sqrt{2} [/math], por lo que podemos definir la base ortonormal


[math]\quad \{E_n\}_{n \in \mathbb{Z}} := \{\frac{\sqrt{2}e^{\pi n ix }}{2}\}_{n \in \mathbb{Z}}. [/math]


Para realizar las aproximaciones, necesitamos los coeficientes de cada elemento que consideremos, que pueden obtenerse por ortonormalidad de la base mediante el producto escalar ya que


[math]\quad f^*(x) \sim \sum_{n=-\infty}^{\infty} C_nE_n = \sum_{n=-\infty}^{\infty} C_ne^{\pi n i} \quad , [/math] [math] \quad C_n = (f^*,E_n)_{L^2} = \int_{-1}^1 f^*(x) \overline{E}_n(x) \,dx \in \mathbb{C}. [/math]

Aproximaciones mediante base trigonométrica compleja.
Figure2fDMR.jpg Erroresf.jpg
Figure3fDMR.jpg TrapeciofDMR.jpg
Representación de aproximaciones con elementos hasta [math] n = 5,10,20 [/math] en tres dimensiones, parte real de las aproximaciones y parte imaginaria respectivamente en esquinas superior izquierda y ambas de abajo. Mejora visiblemente, aunque difieran los extremos, reflejado en los errores representados en la esquina superior derecha.

Podemos estimar estos coeficientes [math] C_n [/math] numéricamente por fórmula del trapecio, y así aproximar la función para un número dado de [math] E_n [/math]. La aproximación con los elementos de la base de [math]-n[/math] a [math]n[/math] será entonces


[math] \quad f(x) \approx \sum_{i=-n}^{n} C_iE_{i|[0,1]} [/math]

Vemos que la aproximación mejora el error en norma [math]L_2[/math], algo que esperábamos por continuidad de [math]f[/math] y su extensión impar. Además, como


[math] f(1) \neq \frac{f^*(-1)+f^*(1)}{2} = 0 [/math]


por ser impar, las aproximaciones convergerán puntualmente a [math] 0 [/math] en el valor [math] x=1 [/math]. No hay convergencia uniforme porque es necesario que la convergencia puntual de las aproximaciones sucesivas fuese [math] f [/math] en todo punto de [math][0,1][/math]. De hecho, el mayor error se obtiene aquí como [math]|f(1)-f_n(1)|=|1+i|=\sqrt{2}. [/math]


Podemos verificar que esta base también es útil con funciones reales aproximando [math]\text{Re}f [/math] con una extensión impar (representado gráficamente a continuación), precisamente [math]\text{Re}f^* [/math]. Por el mismo procedimiento, base y código, logramos de nuevo aproximaciones que convergen en norma del espacio de funciones pero no uniformemente, una vez más por el problema que causa [math] x=1 [/math], donde de nuevo se halla el mayor error con [math]|f(1)-f_n(1)|=|1|=1. [/math]

4 Código

Código generado junto con Chat GPT para aproximación y representación de gráficas.

Aproximaciones mediante base trigonométrica compleja.
Figure2RefDMR.jpg ErroresRef.jpg
Figure3RefDMR.jpg TrapecioRefDMR.jpg
Análogamente a [math] f^* [/math], las aproximaciones revelan ser capaces de tomar valores reales a pesar de partir de elementos con parte imaginaria no trivial. La aproximación vuelve a ser por norma del espacio de funciones pero no uniforme por el valor en [math] x=1 [/math].
Representando esta función real de variable real en las mismas referencias que con [math] f^* [/math], puede comprobarse que es precisamente su proyección ortogonal en el plano horizontal, claramente con parte imaginaria nula por estar definida como parte real de una función de valores complejos.
clc
clear all
close all

%%% Planteamiento
xx = 0:10^(-3):1;
xy = -1:10^(-3):0;
haux = @(x)(4*x.*(1/2 - x).^2 + 1i*x);
hauximp = @(x)-(4*x.*(1/2 - x).^2 + 1i*x);
yy=[hauximp(xx(end:-1:1)),haux(xx)];

%%% Comprobacion de la extension impar
figure(1)
plot3([xy,xx], real(yy), imag(yy), 'r', 'LineWidth', 1.75)  
xline(0);
yline(0);
axis equal
xlim([-1, 1])
ylim([-1, 1])
xlabel('x');
ylabel('Re(f(x))');
zlabel('Im(f(x))');
view(3)
grid on
hold off

figure(2)
subplot(1,2,1)
hold on
xlabel('x');
ylabel('R');
plot(xx, real(haux(xx)), 'r', 'LineWidth', 1.5)
plot(xy, real(hauximp(xx(end:-1:1))), ...
    'r', 'LineWidth', 1.5)
title('\rm Extensión impar de la función f(x)', 'Interpreter', 'tex')
grid on
subplot(1,2,2)
hold on
xlabel('x');
ylabel('iR');
plot(xx, imag(haux(xx)), 'r', 'LineWidth', 1.5)
plot(xy, imag(hauximp(xx(end:-1:1))), ...
    'r', 'LineWidth', 1.5)
title('\rm Extensión impar de la función f(x)', 'Interpreter', 'tex')
grid on



xx=[xy,xx];
N = [5,10,20];  

%%% Inicializacion los vectores de errores
L2_errors = zeros(length(N), 1);
uniform_errors = zeros(length(N), 1);

aux = 1;
for n = N %%% Aproximacion la funcion por la regla del trapecio
    a = zeros(1, n);  
    b = zeros(1, n);  
    fn = trapz(xx, yy/sqrt(2)) * ones(1, length(xx)); 
    
    for k = 1:n
        a(k) = trapz(xx, yy .* ...
            conj(exp(1i*k*pi*xx)/sqrt(2)));
        b(k) = trapz(xx, yy .* ...
            conj(exp(1i*(-k)*pi*xx)/sqrt(2)));
        
        fn = fn + a(k) * exp(1i*k*pi*xx)/sqrt(2) + ...
            b(k) * exp(1i*(-k)*pi*xx)/sqrt(2);
    end
    
    %%% Visualizacion de los resultados
    figure(3)
    subplot(1, length(N), aux)
    plot3(xx, real(yy), imag(yy), 'r', 'LineWidth', 1.75)  
    hold on
    plot3(xx, real(fn), imag(fn), 'b', 'LineWidth', 1.75)  
    xline(0);
    yline(0);
    axis equal
    xlim([-1, 1])
    ylim([-1, 1])
    legend({'$f(x)$', '$f_n(x)$'}, ...
        'Interpreter', 'latex', 'Location', 'northwest')
    xlabel('x');
    ylabel('Re(f(x))');
    zlabel('Im(f(x))');
    title(['n = ', num2str(n)], 'Interpreter', 'latex')
    view(3)
    grid on
    hold off

    % Parte real
    figure(4)
    subplot(1, length(N), aux)
    plot3(xx, real(yy), imag(yy), 'r', 'LineWidth', 1.75)  
    hold on
    plot3(xx, real(fn), imag(fn), 'b', 'LineWidth', 1.75)  
    xline(0);
    yline(0);
    axis equal
    xlim([-1, 1])
    ylim([-1, 1])
    legend({'$f(x)$', '$f_n(x)$'}, ...
        'Interpreter', 'latex', 'Location', 'northwest')
    xlabel('x');
    ylabel('Re(f(x))');
    zlabel('Im(f(x))');
    title(['n = ', num2str(n)], 'Interpreter', 'latex')
    view(2)
    grid on
    hold off

    %%% Parte imaginaria
    figure(5)
    subplot(1, length(N), aux)
    plot3(xx, imag(yy), real(yy), 'r', 'LineWidth', 1.75)  
    hold on
    plot3(xx, imag(fn), real(fn), 'b', 'LineWidth', 1.75)  
    xline(0);
    yline(0);
    axis equal
    xlim([-1, 1])
    ylim([-1, 1])
    legend({'$f(x)$', '$f_n(x)$'}, ...
        'Interpreter', 'latex', 'Location', 'northwest')
    xlabel('x');
    ylabel('Im(f(x))');
    zlabel('Re(f(x))');
    title(['n = ', num2str(n)], 'Interpreter', 'latex')
    view(2)
    grid on
    hold off
    
    %%% Guardamos los errores
    L2_errors(aux) = sqrt(trapz(xx, abs(yy - fn).^2));
    uniform_errors(aux) = max(abs(yy - fn)); 
    aux = aux + 1;
end
sgtitle('Aproximación de la función por la regla del trapecio', ...
    'Interpreter', 'latex');

%%% Visualizacion de los errores
figure(6);
hold on;
plot(N, L2_errors, 'b-', 'LineWidth', 2); 
plot(N, uniform_errors, 'r--', 'LineWidth', 2);  
grid on
xlabel('n');
ylabel('Error');
legend('Error L2', 'Error uniforme');
sgtitle('Errores en normas L2 y uniforme en función de n', ...
    'Interpreter', 'latex');
hold off;