How to use matlab for plotting functions that contain summations?

4.7k Views Asked by At

I am having a terrible time trying to figure out how to plot this function in matlab:

$$\frac{1}{\pi} + \frac{1}{2}\sin(4t) - \frac{2}{\pi} \sum\limits_{k=2,4,6,8}\frac{\cos(4kt)}{k^2-1}$$

I am not sure how to incorporate the summation.

1

There are 1 best solutions below

10
On BEST ANSWER

You should really read the manuals and online tutorials. Since I'm in a mellow mood:

I did this in Octave so YMMV...

function y = f(t)
    y = 1/pi+1/2*sin(4*t);
    for k = 2:2:8
        y = y-2/pi*cos(4*k*t)/(k^2-1);
    endfor
endfunction

Then do something like:

t = 0:.1:10;
plot(t, f(t))
# or Conrad's suggestion...
fplot(@f,[0,10])