Professional Documents
Culture Documents
NAME : KAVIYA K
REG.NO : 20BEC0643
SUBJECT CODE : MAT2002
SUBJECT TITLE : APPLICATIONS OF DIFFERENTIAL AND
DIFFERENCE EQUATIONS
LAB SLOT : L1+L2
GUIDED BY : UDHAYAKUMAR R
NAME: KAVIYA K
REGISTER NUMBER: 20BEC0643
AIM:
KEY WORDS:
Harmonics:
QUESTION:
NAME: KAVIYA K
REGISTER NUMBER: 20BEC0643
MATLAB CODE:
clc
clear
close all
syms t n
f=input('Enter the function f(t)= ');
L=input('Enter Lower limit: ');
U=input('Enter upper limit: ');
l=(U-L)/2;
disp('Fourier Coefficients:')
a0=int(f,t,L,U)/l
a(n)=int(f*cos((n*pi*t)/l),t,L,U)/l
b(n)=int(f*sin((n*pi*t)/l),t,L,U)/l
disp('Harmonics:')
fs1=a(1)*cos(pi*t/l)+b(1)*sin(pi*t/l)
fs2=a(2)*cos(2*pi*t/l)+b(2)*sin(2*pi*t/l)
disp('Fourier Series upto second harmonic:')
fs(t)=a0/2+fs1+fs2
ezplot(f,[L,U])
hold on
grid on
ezplot(fs,[L,U])
legend('f(t)','fs(t)')
title('Fourier Series of f(t)')
INPUT:
OUTPUT:
Fourier Coefficients:
a0 =
-(2*pi^2)/3
a(n) =
b(n) =
(2*(sin(pi*n) - n*pi*cos(pi*n)))/(n^2*pi)
Harmonics:
fs1 =
4*cos(t) + 2*sin(t)
fs2 =
- cos(2*t) - sin(2*t)
fs(t) =
GRAPHS:
NAME: KAVIYA K
REGISTER NUMBER:20BEC0643
AIM:
To obtain and visualize the first few harmonics of the Fourier
series of a given function f(x) using Matlab.
KEYWORDS:
NAME: KAVIYA K
REGISTER NUMBER:20BEC0643
QUESTION:
MATLAB CODE:
clc
clear
close all
syms x
X= input ( ' Enter X = ' ) ;
Y= input ( ' Enter Y = ' ) ;
n= length (X ) ;
c = (X(n)-X( 1 ) ) / 2 ;
a0 =2*sum(Y( 1 : n-1) )/(n-1)
a1 =2*sum(Y( 1 : n-1).*cos(1*pi*X( 1 : n-1)/c ) ) / (n-1)
b1 =2*sum(Y( 1 : n-1).*sin(1*pi*X( 1 : n-1)/c ) ) / (n-1)
a2 =2*sum(Y( 1 : n-1).*cos(2*pi*X( 1 : n-1)/c ) ) / (n-1)
b2 =2*sum(Y( 1 : n-1).*sin(2*pi*X( 1 : n-1)/c ) ) / (n-1)
fs ( x ) = a0/2+ a1*cos(1*pi*x/c) + b1*sin(1*pi*x/c )
+ a2*cos (2*pi*x/c) + b2*sin (2*pi*x/c ) ;
stem(X, Y)
hold on
grid on
ezplot ( fs , [ X(1) X(n) ] )
title ( ' Fourier Series fs ( x ) upto 2nd harmonic' )
legend ( ' Data ' , ' fs( x )' )
INPUT:
Enter X =
[0 pi/6 2*pi/6 3*pi/6 4*pi/6 5*pi/6 pi]
Enter Y =
[0 9.2 14.4 17.8 17.3 11.7 0]
NAME: KAVIYA K
REGISTER NUMBER:20BEC0643
OUTPUT:
a0 =
23.4667
a1 =
-7.7333
b1 =
-1.5588
a2 =
-2.8333
b2 =
0.1155
NAME: KAVIYA K
REGISTER NUMBER:20BEC0643
GRAPHS: