MATLAB Answers

please help me, how do I make the code for the equation in the following picture?

2 views (last 30 days)
Muhammad Rohim
Muhammad Rohim on 17 Apr 2020
Commented: Ameer Hamza on 21 Apr 2020

  3 Comments

Tommy
Tommy on 17 Apr 2020
If you have the symbolic math toolbox:
syms n;
double(symsum(sin(2*n)/n^2,1,inf))

Sign in to comment.

Answers (1)

Peter
Peter on 17 Apr 2020
You can't code an infinite sum exactly, but fortunately, this one is bounded (x^2 on the denominator and the numerator is bounded between -1 and 1).
Pick a big n:
n_max=100;
ns = 1:n_max;
sum_n = cumsum( sin(2*ns)./ns.^2);
plot(ns, sum_n)
You will see it very quickly converges, after 20 terms or so.

  5 Comments

Show 2 older comments
Peter
Peter on 17 Apr 2020
Muhammed,
I'm not sure. I copied the code block directly from the response to check and it seemed to run in the command line without a problem. Generally you get that error if there is an unclosed parenthesis in an expression: each '(' gets a ')'. If you typed it manually, perhaps double-check your entry? The space between the opening parenthesis of the cumsum function and the sin function can also be removed, although that shouldn't make a difference.

Sign in to comment.

Tags

No tags entered yet.

Products


Release

R2013a

Translated by