



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Matlab code for solving problems related to fourier series. The problems involve plotting functions and computing partial fourier series. The code is for math 3150, a university-level mathematics course.
Typology: Assignments
1 / 7
This page cannot be seen from the preview
Don't miss anything!




F a l l^2008 % Problem
t h i c k L i n e s ( 3 ) ;
% remove
i f^ you^ don โ t
have^ t h i s
i n
your^ system f i g u r e^ ( 1 ) ;^ c l f
x =^ linspace
(โpi^ , 3^ โ^ pi
%^ p l o t^ t r u e
f u n c t i o n
f o r^ r e f e r n c e hold^ on ; plot^ ( x ,^ sin
( x ). ห 2 ) ; axis^ ([^ โ^ pi
, 3^ โ^ pi^ , 0 , 1 ] ) ; %^ l o o p^ o v e r
number^ o f
terms plot^ ( x , 1 / 2
โ^ o n e s (^ s i z e
( x ) ) , โ r โ ) ; plot^ ( x ,1/
โ(1^ โ^ cos^ ( 2
โ^ x ) ) , โ g โ ) ; f i l e n a m e^
=^ โ p 2^2 1 1. e p s โ ; xlabel^ ( โ x โ ) ; print^ ( โโd e p s c 2 โ , f i l e n a m e ) ;system ( [ โ e p s t o p d f
โ , f i l e n a m e ] ) ;
F a l l^2008 % Problem
t h i c k L i n e s ( 3 ) ;
% remove
i f^ you^ don โ t
have^ i t^
i n
your^ system f i g u r e^ ( 1 ) ;^ c l f
x =^ linspace
(โpi^ , 3^ โ^ pi
%^ p l o t^ t r u e
f u n c t i o n
f o r^ r e f e r n c e hold^ on ; %^ t r i c k^ t o
make^2 โ^ p i
p e r i o d i c
f u n c t i o n
from^ f n
d e f^ on^ [ 0 , 2
โ^ p i ] plot^ ( x , ( mod( x+
pi^ , 2^ โ^ pi^ )โ
pi^ ) ) ; axis^ ([^ โ^ pi^
, 3^ โ^ pi^ ,โ^ pi
โ^ 1. 2 ,^ pi^ โ^ 1. 2 ] ) ; %^ l o o p^ o v e r
number^ o f
terms Ns =^ [ 1 , 2 , 5 , 1 0 , 1 5 ] ;c o l s ={^ โ g โ , โmโ , โ c โ , โ r โ , โ k โ
for^ iN =^
1 :^ length^ ( Ns ) ,N=Ns ( iN ) ; % compute^ p a r t i a l^
F o u r i e r^ s e r i e s s=zeros^ (^ s i z e
( x ) ) ; for^ n=1:N,an =^ โ^2 โ
(โ1)หn/n ;s=s+anโ sin^ ( nโx ) ; end^ ; %^ c o m p a r a t i v e
p l o t plot^ ( x , s , c o l s
{^ iN^ }^ ) ; end^ ;%N hold^ o f f ;^ xlabel^ ( โ x โ ) ;f i l e n a m e= โ p 2
2 1 3. e p s โ ; print^ ( โโd e p s c 2 โ , f i l e n a m e ) ;system ( [ โ e p s t o p d f
โ^ f i l e n a m e ] ) ;