how do I compute this infinite sum in matlab?

匿名 (未验证) 提交于 2019-12-03 09:58:14

问题:

I want to compute the following infinite sum in Matlab, for a given x and tau:

infsum http://i47.tinypic.com/16ih3m1.jpg

I tried the following code, given x=0.5 and tau=1:

symsum((8/pi/pi)*sin(n*pi*0.5)*sin(n*pi*0.5)*exp(-n*n*pi*pi)/n/n,1,inf) 

But I get this:

(228155022448185*sum((exp(-pi^2*n^2)*((exp(-(pi*n*i)/2)*i)/2 - (exp((pi*n*i)/2)*i)/2)^2)/n^2, n == 1..Inf))/281474976710656 

I want an explicit value, assuming the sum converges. What am I doing wrong? It seems like Matlab doesn't compute exp() when returning symsum results. How do I tell Matlab to compute evaluate the exponentials?

回答1:

Convert to double

double(symsum(...)) 


回答2:

Just to show you a different way, one that does not require the symbolic toolbox,

summ  = 0; summP = inf; n = 1; while abs(summP-summ) > 1e-16     summP = summ;         summ = summ + sin(n*pi*0.5)*sin(n*pi*0.5)*exp(-n*n*pi*pi)/n/n;     n = n + 1; end  8/pi/pi * summ 

which converges after just 1 iteration (pretty obvious, since exp(-4*6.28..)/n/n is so tiny, and sin(..) is always somewhere in [-1 1]). So given tau==1 and x==0.5, the infinite sum is essentially the value for n==1.



回答3:

You should first define your variable "n" using syms. Then, you can include this variable in your symsum code.

Here's what I did:

syms n; AA = symsum((8/pi/pi)*sin(n*pi*0.5)*sin(n*pi*0.5)*exp(-n*n*pi*pi)/n/n,n,1,inf); BB = double(AA) BB = 4.1925e-05 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!