From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Summing numbers in an M file in MATLAB
Date: Fri, 13 May 2011 02:42:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <iqi5pt$f47$>
References: <iqh4s8$em7$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1305254525 15495 (13 May 2011 02:42:05 GMT)
NNTP-Posting-Date: Fri, 13 May 2011 02:42:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:726516

"J.C.  Martinez" wrote in message <iqh4s8$em7$>...
> here's my code. I'm wondering what else I need to add to sum up all the numbers at the end. 
> a = input('Enter number of days you would like to know the total of');
> f(1) = .01;
> for i = 2:a
>     f(i) = (2*f(i-1));
> end
> Would sum(sum(2:a)) work right before the "end"?
- - - - - - - - - -
  In this particular problem there is no need to do summation of any kind.  The sum of all the terms can be expressed as


which is a special case of taking sums of geometric series.

  Your problem sounds like the famous tale of a king trying to award a subject for supposedly devising the game of chess.  The subject made what seemed like a modest request.  One penny on the first square, two on the next, four on the third, and doubling on each successive square.  Presumably the king would have had to file for bankruptcy if he had attempted to pay for all sixty-four squares.

Roger Stafford