Professional Documents
Culture Documents
Digital Assignment-1: Name: Havila Reddy Register No: 19BCT0211
Digital Assignment-1: Name: Havila Reddy Register No: 19BCT0211
Question 1:
1. Aim of the Experiment:
To evaluate and verify fourier series expansion of given functions.
2. Mathematical Procedure:
1. Take input function in terms of x
2. Take input of the interval for the function.
3. Find the values of L, a0/2
4. Using for loop, find the values of an and bn
5. Substitute these values to get fourier expansion
6. Using ezplot, graphs are displayed.
3. Matlab Code:
clear all
close all
clc
syms x
f =input('Enter the function : ');
I=input('Enter the interval of [a,b]: ');
m=input('Enter the number of Harmonics: ');
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]);
hold on
ezplot(f,[a,b]);
title(['Fourier Series with ',num2str( n ),'harmonics']);
legend('Fourier Series', 'Function Plot');
hold off
end
disp(strcat('Fourier series with', num2str(n),'harmonics is:',char(Fx)))
4. Input:
Enter the function of x:
(-1)*(heaviside(x+2)-heaviside(x))+(1)*(heaviside(x)-heaviside(x-2))
Enter the interval of [a,b]:
[-2,2]
Enter the number of Harmonics required:
3
Output:
Fourier series with3harmonics is:0.4244*sin(4.712*x) + 1.273*sin(1.571*x)
5. Graphs:
6. Conclusion:
Therefore, the fourier expansion of the given function is obtained.
Question 2:
2.Mathematical Procedure:
1.Take input function in terms of x
2.Take input of the interval for the function.
3.Find the values of L, a0/2
4.Using for loop, find the values of an and bn
5.Substitute these values to get fourier expansion
6.Using ezplot, graphs are displayed.
3.Matlab Code:
clear all
close all
clc
syms x
f =input('Enter the function : ');
I=input('Enter the interval of [a,b]: ');
m=input('Enter the number of Harmonics: ');
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]);
hold on
ezplot(f,[a,b]);
title(['Fourier Series with ',num2str( n ),'harmonics']);
legend('Fourier Series', 'Function Plot');
hold off
end
disp(strcat('Fourier series with', num2str(n),'harmonics is:',char(Fx)))
4.Input:
Enter the function of x:
(0)*(heaviside(x+0.5)-heaviside(x))+(5*sin(2*pi*x))*(heaviside(x)-heaviside(x-0.5))
Enter the interval of [a,b]:
[-0.5,0.5]
Enter the number of Harmonics required:
3
Output:
Fourier series with3harmonics is:2.5*sin(6.283*x) - 1.061*cos(12.57*x) + 1.592
5.Graphs:
6.Conclusion:
Therefore, the fourier expansion of the given function is obtained.
Question 3: