Word Taken
Word Taken
MATLAB Code:
a)
clear all
close all
clc
syms t
f = input('Enter the function of t : ');
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);
Ft=a0/2;
for n=1:m
figure;
an(n)=(1/L)*int(f*cos(n*pi*t/L),a,b);
bn(n)=(1/L)*int(f*sin(n*pi*t/L),a,b);
Ft=Ft+an(n)*cos(n*pi*t/L)+bn(n)*sin(n*pi*t/L);
Ft=vpa(Ft,4);
ezplot(Ft,[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(Ft)))
INPUT
Enter the function of t : exp(-t)
OUTPUT
3.676
GRAPHS
b)
MATLAB Code:
clear all
close all
clc
syms t
f = input('Enter the function of t : ');
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);
Ft=a0/2;
for n=1:m
figure;
an(n)=(1/L)*int(f*cos(n*pi*t/L),a,b);
bn(n)=(1/L)*int(f*sin(n*pi*t/L),a,b);
Ft=Ft+an(n)*cos(n*pi*t/L)+bn(n)*sin(n*pi*t/L);
Ft=vpa(Ft,4);
ezplot(Ft,[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(Ft)))
INPUT
OUTPUT
GRAPHS:
Question 2
CORRECTED CODE
syms x
l=5;
N=5;
p=0;
for n=1:2:2*N+1 p=p+
(l/n*2)*sin(n*pi/2)*cos(n*pi*x/l)*sin(n*pi*x/l);
end
y=(4*l/pi^2)*p
OUTPUT
P=
2*cos(pi*x)*sin(pi*x) + 10*cos((pi*x)/5)*sin((pi*x)/5) -
(10*cos((3*pi*x)/5)*sin((3*pi*x)/5))/3 -
(10*cos((7*pi*x)/5)*sin((7*pi*x)/5))/7 +
(10*cos((9*pi*x)/5)*sin((9*pi*x)/5))/9 -
(10*cos((11*pi*x)/5)*sin((11*pi*x)/5))/11
Question 3
MATLAB Code:
clear all
clc
syms t
x=input('Enter the equally spaced values of x: ');
y=input('Enter the values of y=f(x): ');
m=input('Enter the number of harmonics required: ');
n=length(x);a=x(1);b=x(n);
h=x(2)-x(1);
L=(b-a+h)/2;
theta=pi*x/L;
a0=(2/n)*sum(y);
Fx=a0/2; x1=linspace(a,b,100);
for i=1:m
figure
an=(2/n)*sum(y.*cos(i*theta));
bn=(2/n)*sum(y.*sin(i*theta));
Fx=Fx+an*cos(i*pi*t/L)+bn*sin(i*pi*t/L) ;
Fx=vpa(Fx,4);
Fx1=subs(Fx,t,x1);
plot(x1,Fx1);
hold on
plot(x,y);
title(['Fourier Series with ',num2str( i ),'harmonics'])
legend('Fourier Series', 'Function Plot')
hold off;
end
disp(strcat('Fourier series with', num2str(i),'harmonics is:',char(Fx)));
INPUT
Enter the equally spaced values of x: [0 1/6 1/3 1/2 2/3 5/6 1]
Enter the values of y=f(x): [1.98 1.30 1.05 1.30 -0.88 -0.25 1.98]
GRAPHS:
QUESTION 3b
OUTPUT
Fourier series with1harmonics is:1.155*sin(1.047*t) -
6.667*cos(1.047*t) + 15.0