|
"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
|