How to use matlab for plotting functions that contain summations?

$\begingroup$

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.

$\endgroup$ 3

1 Answer

$\begingroup$

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])
$\endgroup$ 10

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like