Chapter 4: Programming in Matlab - College of the Redwoods
Chapter 4: Programming in Matlab - College of the Redwoods
Chapter 4: Programming in Matlab - College of the Redwoods
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
326 <strong>Chapter</strong> 4 <strong>Programm<strong>in</strong>g</strong> <strong>in</strong> <strong>Matlab</strong><br />
Enter <strong>the</strong> follow<strong>in</strong>g to plot <strong>the</strong> piecewise<br />
function f.<br />
N=500;<br />
x=l<strong>in</strong>space(-pi,pi,N);<br />
y=0*(x=0);<br />
plot(x,y,’.’)<br />
A Fourier series representation <strong>of</strong> <strong>the</strong><br />
function f is given by<br />
a 0<br />
2 + ∞ ∑<br />
n=1<br />
where a 0 = π/2, and<br />
a n =<br />
[a n cos nx + b n s<strong>in</strong> nx] ,<br />
1 − cos nπ<br />
n 2 π<br />
and b n = 1 n .<br />
Hold <strong>the</strong> plot <strong>of</strong> f, <strong>the</strong>n superimpose<br />
<strong>the</strong> Fourier series sum for n = 1 to<br />
n = 5. H<strong>in</strong>t: This is a nice place<br />
for anonymous functions, for example,<br />
set:<br />
b = @(n) 1/n;