Mathalb 1 Fourier
Mathalb 1 Fourier
In the Fourier series the term (a1 cos x b1 sin x ) is called the Fundamental Harmonic/First
Harmonic, (a2 cos 2 x b2 sin 2 x) is called the Second Harmonic and so on.
MATLAB Code:
clear all
close all
clc
syms x
f =input('Enter the function of x: ');
I=input('Enter the interval of [a,b]: ');
m=input('Enter the number of Harmonics required: ');
a=I(1);b=I(2);
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]);
Input:
Enter the function of x: x-x^2
Enter the interval of [a,b]: [-pi,pi]
Enter the number of Harmonics required: 3
Output:
Fourier series with3harmonics is:0.4444*cos(3.0*x) - 1.0*sin(2.0*x)
- 1.0*cos(2.0*x) + 0.6667*sin(3.0*x)
Example: To find the Fourier series expansion up to 5 harmonics for the function
2x
1 ; x 0
f ( x)
2x
1 ; 0 x
Output: