Pesquisar este blog

terça-feira, 14 de março de 2017

Séries de Fourier no Matlab

Para gerar uma série de fourier no matlab.

syms x k L n
evalin(symengine,'assume(k,Type::Integer)');
a = @(f,x,k,L) int(f*cos(k*pi*x/L)/L,x,-L,L);
b = @(f,x,k,L) int(f*sin(k*pi*x/L)/L,x,-L,L);
fs = @(f,x,n,L) a(f,x,0,L)/2 + ...
    symsum(a(f,x,k,L)*cos(k*pi*x/L) + b(f,x,k,L)*sin(k*pi*x/L),k,1,n);

%exemplo -  Escreva a função f(x) = x%
f = x
pretty(fs(f,x,10,1))


figure
subplot(3,1,1);
ezplot(fs(f,x,5,1),-1,1)
hold on
ezplot(f,-1,1)
hold off
title('Série de Fourier com n=5')

% Plotar gráfico para n=10

subplot(3,1,2);
ezplot(fs(f,x,10,1),-1,1)
hold on
ezplot(f,-1,1)
hold off
title('Série de Fourier com n=10')

subplot(3,1,3);
ezplot(fs(f,x,15,1),-1,1)
hold on
ezplot(f,-1,1)
hold off
title('Série de Fourier com n=15')

_________________________________________________________________________________

O resultado será:


função f(x)=|x|