Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: "not a number" message
Date: Sat, 3 Jan 2009 07:09:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 37
Message-ID: <gjn2uj$cb9$1@fred.mathworks.com>
References: <gjmk9m$5ke$1@fred.mathworks.com> <gjmogm$evm$1@fred.mathworks.com> <gjmpvh$6hd$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1230966547 12649 172.30.248.38 (3 Jan 2009 07:09:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 3 Jan 2009 07:09:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:509614

"Nick Stucky-Mack" <njstucky@fas.harvard.edu> wrote in message <gjmpvh$6hd$1@fred.mathworks.com>...
> Alright, thanks Roger!  I've included the entirety of the code here.  
> .......

A few comments, Nick:

  I notice that in your first trip on each run through the

 while(time<topTime)

loop, every column except one in 'abundance' is initially all zeros, and yet you divide by the sum of one of these columns in

 relAbundTwo = ....
  relAbundRow(:,chosenMutantN)/sum(abundance(:,chosenMutantN));

If 'chosenMutantN' is anything but 1 at this point you could be in for trouble from the resultant infinity.  One of the ways a NaN is produced is by dividing an infinity by another infinity or by subtracting two infinities.  Another way is zero divided by zero.

  There is a division by 'total' which could be zero that first trip since it comes from an element of 'abundance'

 total = abundance(chosenMutantA,chosenMutantN)*...
          bplusdeaths(chosenMutantA,1);

and when you then calculate 'birth' you have a sure-fire NaN from the zero divided by zero situation there.

  It would be wise to make use of your debugger facilities to catch stuff like this yourself as it happens so you can analyze it for errors or unwise coding.  After all, if you are going to be an effective programmer, it is absolutely essential to know how to debug your own code.  No-one else can do as good a job as you yourself.  I speak from long experience.

  You need much more robust code that is protected against certain kinds of unplanned consequences.  For example in 

 while(relAbundOne(j)<=handOfGodCol)
  chosenMutantN = j + 1;
  j = j + 1;
 end

you have no guard against j going beyond the end of the 'relAbundOne' array limit in case all its values are too small.

Roger Stafford