Thread Subject: sum from 0 to inf?

Subject: sum from 0 to inf?

From: Erik Gadzinski

Date: 15 Nov, 2009 20:25:02

Message: 1 of 3

can I sum from 0 to infinity in matlab? For example sum(k=0 to k=inf) q^(k^b). How would I write that if I can do so?

Thanks!

Subject: sum from 0 to inf?

From: Matt Fig

Date: 15 Nov, 2009 21:57:01

Message: 2 of 3

"Erik Gadzinski" <ergadz@yahoo.com> wrote in message <hdpo2u$o49$1@fred.mathworks.com>...
> can I sum from 0 to infinity in matlab? For example sum(k=0 to k=inf) q^(k^b). How would I write that if I can do so?
>
> Thanks!

Not numerically. You will have to truncate the series either based on a pre-chosen number or some kind of conditional evaluation. Here are two real basic approaches.

b = 1.1;
q = .25;
t = 0; % Holds the sum
for ii = 0:20 % Stop at twenty
    t = t + q^(ii^b);
end

Or, some kind of stopping condition, here until the new term is smaller than machine precision:

r = 0; % Holds the sum
M = 10;
cnt = 0;
while M > (2*eps)
    M = q^(cnt^b);
    r = r + M;
    cnt = cnt + 1;
end

Subject: sum from 0 to inf?

From: Erik

Date: 16 Nov, 2009 03:06:01

Message: 3 of 3

"Matt Fig" <spamanon@yahoo.com> wrote in message <hdptfd$m23$1@fred.mathworks.com>...
> "Erik Gadzinski" <ergadz@yahoo.com> wrote in message <hdpo2u$o49$1@fred.mathworks.com>...
> > can I sum from 0 to infinity in matlab? For example sum(k=0 to k=inf) q^(k^b). How would I write that if I can do so?
> >
> > Thanks!
>
> Not numerically. You will have to truncate the series either based on a pre-chosen number or some kind of conditional evaluation. Here are two real basic approaches.
>
> b = 1.1;
> q = .25;
> t = 0; % Holds the sum
> for ii = 0:20 % Stop at twenty
> t = t + q^(ii^b);
> end
>
> Or, some kind of stopping condition, here until the new term is smaller than machine precision:
>
> r = 0; % Holds the sum
> M = 10;
> cnt = 0;
> while M > (2*eps)
> M = q^(cnt^b);
> r = r + M;
> cnt = cnt + 1;
> end



works well. thanks!

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com