Please help me write this summation in MATLAB

I am trying to write this double summation in MATLAB. However, I am not getting the correct. Please help me write this.
Please note that the upper limit in the second summation is the floor function.

7 Comments

What have you tried yet? Please show your code.
Hi Dyuman Joshi, I have now done it using symsum in MATLAB. Earlier I was using for loop. However I observed that there is 'symsum' available in MATLAB, which can easily handle such summation notation. For this case, I have written the code as follows and it's now working well!
syms k x n
n_term=50;
f=symsum(((((-1)^(k-1))*(x)^k)/(factorial(k)*2^(k-1)))*symsum(1/(1+(2*n)),n,0,floor((k-1)/2)),k,1,n_term)
f = 
Sorry. That was a typo. It should be (x^k). I will edit it.
When I tested the inner symsum early this morning, I found that it gave the wrong results when the upper bound uses floor. I will write this up later today.
So the floor function cannot be used in symbolic summation ?
False alarm. I was working on my phone in MATLAB Mobile in the early hours of the morning, and did not notice that in one case I was using 1/(2*k+1) but in another case I was using 1/(2*k-1)

Sign in to comment.

 Accepted Answer

n_term = 50/2;
syms n N k integer
syms x
inner = symsum(1/(2*k+1), k, 0, floor((n-1)/2))
inner = 
outer = (-1)^(n-1)*x^n/factorial(n)/2^(n-1) * inner
outer = 
outer_even = simplify(subs(outer, n, 2*N))
outer_even = 
outer_odd = simplify(subs(outer, n, 2*N+1))
outer_odd = 
sum_even = symsum(outer_even, N, 1, n_term)
sum_even = 
sum_odd = symsum(outer_odd, N, 1, n_term)
sum_odd = 
result = simplify(sum_even + sum_odd)
result = 
result_unsplit = symsum(outer, n, 1, n_term*2)
result_unsplit = 
Hmmm... the difference between the two is that the split version has one extra term, the x^51 term. I am not going to bother to chase that down.
result_unsplit = symsum(outer, n, 1, inf)
result_unsplit = 

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!