How do I put a summation equation in matlab?

Hi people, I need to plot the graph of f(x)= -4*(pi)^2 + the summation from n=1 (sin(n*x)*(-1)^n) / n for different values of n. I am fine plotting the graphs but I cant get the summation to work. Can anyone help?

Answers (3)

I’m not certain about the summation you want to do, but the cumsum function is likely worth considering.
One possibility:
x = 0.5; % Scalar ‘x’
n = 1:10;
f = -4*(pi)^2 + cumsum( (sin(n*x).*(-1).^n) ./ n);
figure(1)
plot(n, f)
grid
SSEQ = (symsum(((deflectiontest)-(yq.^(2))) .^ (1 ./ 2),x,1,n)) ./ (n);

2 Comments

The first parameter of the symsum is the expression to be summed. The second parameter is the variable of summation. The expression looks to be independent of the variable of summation, so it looks like the result would be the first parameter times the span of the third to fourth parameter, so (n-1)+1 = n

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 11 Feb 2016

Commented:

on 18 Feb 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!