You are on page 1of 5

EXPERIMENT 1A

TITLE: FOURIER SERIES

AIM: TO FIND THE FOURIER SERIES


clc;
clear all;
syms x;
f=input('enter the function f(x):');
I=input('enter the interval [a,b]:');
a=I(1);b=I(2);
m=input('enter number of harmonics:')
L=(b-a)/2;
a0=(1/L)*int(f,a,b);
Fx=a0/2;
for n=1:m
figure;
an(n)=(1/L)*int(f*cos(n*pi*x/L),a,b);
bn(n)=(1/L)*int(f*sin(n*pi*x/L),a,b);
Fx=Fx+an(n)*cos(n*pi*x/L)+bn(n)*sin(n*pi*x/L);
Fx=vpa(Fx,4);
ezplot(Fx,[a,b])
hold on
ezplot(f,[a,b])
end
title('Fourier series',num2str(n),'Hormonics')
legend('Fourier series','given function')

INPUT:

enter the function f(x):x-x^2

enter the interval [a,b]:[-pi,pi]

enter number of harmonics:3

m=

3
FIGURE 1:

FIGURE 2:
ANALYTIC SOLUTION

enter the function f(x):x-x^2

enter the interval [a,b]:[-pi,pi]

enter number of harmonics:3

m=

Fx =

(5734161139222659*pi*cos(x))/4503599627370496 +
(5734161139222659*pi*sin(x))/9007199254740992 - (1911387046407553*pi^3)/18014398509481984

Fx =

4.0*cos(x) + 2.0*sin(x) - (5734161139222659*pi*cos(2*x))/18014398509481984 -


(5734161139222659*pi*sin(2*x))/18014398509481984 - 3.289868133710115216672420501709

Fx =
4.0*cos(x) - 1.0*sin(2.0*x) - 1.0*cos(2.0*x) + 2.0*sin(x) +
(1911387046407553*pi*cos(3*x))/13510798882111488 +
(1911387046407553*pi*sin(3*x))/9007199254740992 - 3.289868133710115216672420501709

You might also like