Numerical Methods i Fourier Series Applicatios Recall that the basic relatios i usig the Trigoometric Fourier Series represetatio were give by f ( x) a o ( a x cos b x si ) () where the Fourier coefficiets were give by a b x f ( x)cos dx, 0,,, x f ( x)si dx,,,3, () For some complicated situatios, the itegrals appearig i relatios () may ot be able to be evaluated usig stadard had calculatio. For such cases the itegrals may have to be determied usig umerical methods. Fortuately, may such methods have bee developed ad are readily available i various computer software packages. MATAB has several such optios, ad oe particular commad that will determie the itegral I f ( x) dx is called the quad commad with format b a I = quad(fuctio,a,b). This scheme uses a adaptive Simpso method of umerical itegratio ad has reasoable accuracy with a default error of 0-6 which ca be chaged (see Help). Obviously the fuctio to be itegrated must be cotiuous ad well-behaved over the iterval (a,b). Cosider the test problem I 0 0 x dx. For this simple case, oly the sigle commad is eeded ad the aswer matches the kow aalytical evaluatio as show >> quad('x.^',0,0) as = 333.3333
It should be oted that MATAB has may other umerical itegrators that ca hadle more complicated situatios ad yield better accuracy tha quad. Next let us put this umerical scheme to work o a simple Fourier series problem with kow solutio. The problem is take from Kreyszig, exercise.., where f ( x) x over the iterval x. Note that this problem reduces to a Fourier Cosie Series, with the Fourier coefficiet give by a / 3 ad a ( ) 4/( ). The followig code uses aoymous fuctio commad to pass the idex through, ad plots are made of the fuctio, aalytical evaluatio ad umerical evaluatio retaiig 0 terms i the series. o % Exercise.. Solutio: Aalytical & Numerical clc;clear all ;clf; % Plot Fuctio x=-:0.0:; y=x.^; plot(x,y,'r','liewih',) grid o hold o % Evaluate ad Plot Aalytical Series X=-:0.:; ao=/3;f=ao; for =:0 a=((-)^)*4/(pi*)^; f=f+a*cos(pi**x); ed plot(x,f, 'k*', 'liewih',.5) % Evaluate ad Plot Numerical Series x=-0.95:0.:0.95; ao=quad('x.^',0,);f=ao; for =:0 F=@(x)(x.^).*cos(*pi*x); a=*quad(f,0,); f=f+a*cos(pi**x); ed plot(x,f, 'bo', 'liewih',.5) leged('fuctio','aalytical FS - 0 Terms','Numerical FS - 0 Terms') title('compariso of Aalytical vs Numerical Fourier Series: f = x^') xlabel('x'),ylabel('f')
f Results of the code are show i the followig figure. 0.9 0.8 Compariso of Aalytical vs Numerical Fourier Series: f = x Fuctio Aalytical FS - 0 Terms Numerical FS - 0 Terms 0.7 0.6 0.5 0.4 0.3 0. 0. 0 - -0.8-0.6-0.4-0. 0 0. 0.4 0.6 0.8 x Forced Oscillatio Example Cosider the forced oscillatio example from Kyeszig pp. 49-494. The applicatio ivolves the vibratioal time-depedet behavior of a mechaical mass-sprigdashpot system subjected to a exteral forcig fuctio as show i the adjacet figure.
Usig Newto s law, the goverig equatio of motio is give by the secod order differetial equatio that we have see earlier i the course (Sectio.4) d y m dy c ky r( t) (3) where y is the vertical displacemet from the static equilibrium positio, m is the mass, k is the sprig stiffess, c is the dampig costat, ad r is the exteral forcig fuctio. As show i the text, this equatio also describes the behavior of particular electrical circuits as well. If r(t) is harmoic (si(t) or cos(t) time behavior), the steady-state solutio ca be easily foud ad will also be harmoic of the same frequecy,. However, if r(t) is periodic but ot harmoic, the more complicated behavior will result. We ow wish to explore such a case usig Fourier Series methods. Followig the text s example i this sectio, we explore the particular case govered by the equatio d y dy 0.05 5y r( t) (4) with the followig forcig fuctio (5)
I order to fid the solutio to the differetial equatio we first represet the periodic forcig fuctio i terms of its Fourier Cosie Series 4 4 r( t) cost cos3t cos5t cost 3 5,3,5,... The differetial equatio the ca be writte as d y dy 4 0.05 5y cost (6) where we are lookig at oly a sigle -term of the series. From our previous studies, we kow that the steady state solutio must be of the form y ( t) A cost B si t (7) ad substitutig this ito equatio (6) gives A D 4(5 ) 0., B D D (8) (5 ) (0.05) Sice the differetial equatio is liear, the solutio is the give by A,3,5,... y ( t) cost B si t (9) Numerical evaluatio of this solutio is accomplished by the followig MATAB code, ad the solutio is plotted i the followig figure.
y - Output % MCE 37 Egieerig Aalysis Example Code - Prof. Sadd % Force Oscillatio Example, pp. 49-494 % Numerical Evaluatio of Fourier Series Solutio % ************************************** clc;clear all;clf; t=lispace(-pi,pi,00); y=0; for =:: D=(5-^)^+(0.05*)^; A=4*(5-^)/(^*pi*D); B=0./(*pi*D); y=y+b*si(*t)+a*cos(*t); if == plot(t,y,'k','liewih',) hold o ed if ==3 plot(t,y,'b','liewih',) ed if ==5 plot(t,y,'r','liewih',) ed ed grid o xlabel('time');ylabel('y - Output') title('vibratio Output - Example, pp 49-494') leged('-term','-terms','3-or more terms',4) 0.3 Vibratio Output - Example, pp 49-494 0. 0. 0-0. -0. -0.3 -term -terms 3-or more terms -0.4-4 -3 - - 0 3 4 time
The plot illustrates that the solutio coverges quickly, ad thus oly 3 terms are eeded i the Fourier series. The displacemet output is almost a harmoic oscillatio of five times the frequecy of the iput drivig force. Discrete Data Example Aother useful MATAB umerical itegrator is the trapz commad, ad this is used for itegratig a fuctio that is oly defied as data at discrete poits. This situatio could come from a experimetal data acquisitio system that captures say the drivig force o a mechaical system but oly at discrete times. As i the previous example, we may wat to represet this drivig force usig a Fourier series. For this case, cosider a example where the discrete drivig force data has bee collected over a time iterval 0 < t < 5 as show i the followig table. Time 0 0.500 0.5000.0000.5000.0000.5000 3.0000 3.5000 4.0000 4.5000 5.0000 Force 0.6000 3.000 4.000 4.5000 4.000 3.000.000.5000.000.000.0500 The data idicates a force history that first icreases to a maximum ad the decreases to a smaller costat value. Usig this data set we ca use trapz commad to first determie the Fourier coefficiets of the drivig force ad the to use these to calculate the Fourier series. To make thigs a little simpler, we will assume that the fuctio has a eve half-rage expasio, ad thus will determie a Fourier Cosie series represetatio of the discrete data. The results are show i the figure below ad the MATAB code is give the text box. Notice that the umerical results have some iaccuracies ear t = 0, probably comig from the simple method (trapezoid techique) used i the trapz method.
Drivig Force 4.5 4 Discrete Drivig Force Example Discrete Data Fourier Series Represetatio 3.5 3.5.5 0.5 0 0 0.5.5.5 3 3.5 4 4.5 5 time % MCE 37 Egieerig Aalysis Example Code - Prof. Sadd % Fourier Series Represetatio of a Drivig Force % Prescribed at Discrete Times % ************************************** clc;clear all;clf; % Iput Discrete Fuctio Data =5; t=[0,0.5,0.5,,.5,,.5,3,3.5,4,4.5,5] F=[0,.6,3.,4.,4.5,4.0,3.,.,.5,.,.,.05] % Plot Data plot(t,f,'ro','liewih',) grid o xlabel('time');ylabel('drivig Force') title('discrete Drivig Force Example') hold o % Calculate Fourier Coefficiets; Assume Eve Fuctio of Time ao=trapz(t,f)/ for =:9 FF=F.*cos(*pi*t/) a()=*trapz(t,ff)/ ed % Determie Fourier Series T=0:0.:5; f=ao; for =:9 A=a(); f=f+a*cos(*pi*t/); ed % Plot Fourier Series plot(t,f,'liewih',) leged('discrete Data','Fourier Series Represetatio')