You are on page 1of 6

# Matlab Problem Set #8 Matlab Commands for checking the answers on Problem 6.1-1(a).

M-file used to generate the Fourier Series Coefficients. % MP8p1.m % Matlab Problem Set 8 % Number 1. % M-script to execute the commands to generate trigonometric coefficients % for Problem 6.1-1 (a). % T=4; % Define the fundamental period for x(t). n=input('Enter the harmonic number >') syms t; % Define 't' to be a symbolic variable. an1=int((2/T)*cos(0.5*pi*n*t),t,-1,1); % Create the 1st half of the coef. an2=int((-2/T)*cos(0.5*pi*n*t),t,1,3); % Second half of coefficient. an=an1+an2, % Display the coefficient for the n-th harmonic. digits(5); % Reduce the number of significant figures in the displayed ans. an_number=vpa(an) % Use the variable precision arithmetic to diplay value. % % % Execute the M-script file MP8p1.m for several harmonics. % These commands will compute the coefficients for the Fourier Series % expansion. MP8p1 Enter the harmonic number >1 n = 1

an = 4/pi

an_number = 1.2732 MP8p1, % Run the script and use n=2. Enter the harmonic number >2 n = 2

an = 0

an_number = 0.0 MP8p1, % Run the script with n=3. Enter the harmonic number >3 n = 3

an = -4/(3*pi)

an_number = -0.42441 MP8p1, % Run the script with n=4. Enter the harmonic number >4 n = 4

an = 0

an_number = 0.0 MP8p1, % Run the script with n=5. Enter the harmonic number >5 n = 5

an = 4/(5*pi)

an_number = 0.25465 MP8p1, % Run the script with n=6. Enter the harmonic number >6 n = 6

an = 0

an_number = 0.0 MP8p1, % Run the script with n=7. Enter the harmonic number >7 n = 7

an = -4/(7*pi)

an_number = -0.18189 % These expressions and numerical values are consistent with the Trigonometric % Fourier Series coefficients derived by hand in Problem 6.1-1. diary off

Matlab Commands for checking the answers for Problem 6.1-1(c). M-file used to compute the Trigonometric Fourier Series Coefficients. % MP8p2.m % Matlab Problem Set 8 % Number 2. % M-script to execute the commands to generate trigonometric coefficients % for Problem 6.1-1 (c). % % Only the non-DC terms will be computed with this M-file. % T=2*pi; % Define the fundamental period for x(t). n=input('Enter the harmonic number >') syms t; % Define 't' to be a symbolic variable. bn=int((2/T)*(1/(2*pi))*t*sin(n*t),t,0,2*pi); % Create the sine coefficient. % Will only worry about displaying the numerical value of the coefficient. digits(5); % Reduce the number of significant figures in the displayed ans. bn_number=vpa(bn) % Use the variable precision arithmetic to diplay value. % % % The above M-file does not compute the average value of the periodic % waveform. % % I will execute some Matlab commands to compute the average value of x(t) % prior to running the M-file MP8p2.m to compute the F.S. coefficients. % % Execute the commands to find the Trigonometric Fourier Series coefficients. % These commands are meant for Problem 6.1-1(c). % The M-file MP8p2.m will be used to compute most of the coefficients. % % First, I will compute the average value of the periodic waveform. % This computation is not a part of the M-file. % I am assuming that ‘t’ has already been defined as a symbolic variable. T=2*pi; % Enter the period of the waveform. ao=(1/T)*int((1/(2*pi))*t,t,0,2*pi), % Average value of x(t) in part (c). ao = (32880603970571302491146779030281*pi^2)/649037107316853453566312041152512 digits(5); % Set the display digits to 5 significant figures. vpa(ao), % Display a more reasonable value for the average value of x(t). ans = 0.5 % Begin using the M-file script to compute the "b" coefficients. MP8p2, % Run the script with n=1. Enter the harmonic number >1 n = 1

bn_number = -0.31831 MP8p2, % Run the script with n=2. Enter the harmonic number >2 n = 2

bn_number = -0.15915 MP8p2, % Run the script with n=3. Enter the harmonic number >3 n = 3

bn_number = -0.1061 MP8p2, % Run the script with n=4. Enter the harmonic number >4 n = 4

bn_number = -0.079577 MP8p2, % Run the script with n=5. Enter the harmonic number >5 n = 5

bn_number =

-0.063662 MP8p2, % Run the script with n=6. Enter the harmonic number >6 n = 6

bn_number = -0.053052 % The above numerical values for the "b" coefficients are consistent % with the hand-calculated values. diary off