Overflow in Mathematical model

# Thread: Overflow in Mathematical model

1. Senior Member
Join Date
Dec 1969
Posts
105

## Overflow in Mathematical model

I keep getting an overflow error with this one. Sourcecode below.<BR>Bill Wilkinson, if you&#039;re out there, you helped me a lot yesterday, but I can&#039;t see why I&#039;m still getting an overflow error! At first, there was an memory problem, but by making a sample size, this would be no trouble at all isn&#039;t it?<BR><BR>Thanks for any help,<BR><BR>Erwin.<BR><BR>_______________________ _________________<BR>&#060;% <BR><BR>&#039; Start changing numbers. Also change the Array numbers but devided by the sample size<BR>Dim times <BR>times = 10000 &#039; how many loops this thing will make. Change this to 100,000 for overflow along with the sample size below.<BR><BR>Dim sample<BR>Sample = 100 &#039; Set the sample size, change this to 1,000 for overflow<BR> &#039; Overflow will come now.<BR>Dim N_one(100) <BR>Dim N_two (100) <BR>Dim N (100)<BR>Dim P_one(100) <BR>Dim P_two (100) <BR>Dim N_devide_N (100)<BR>Dim time (100) <BR>Dim counter <BR><BR>&#039; Stop changing numbers, overflow will come now.<BR><BR>counter = 0<BR>dim i <BR>dim pi <BR>dim mi <BR>dim fi <BR>Dim temp1<BR>Dim temp2<BR><BR><BR>dim n1 <BR>dim n2 <BR><BR>Dim strValue <BR><BR><BR><BR>&#039; Variables which can be altered from user input at later stage<BR>i = Array(0,1,2) <BR>Pi = Array(0.1,0.2,0) <BR>Mi = Array(0,5,30) <BR>Fi = Array(0.5,3)<BR><BR>NN1 = 10<BR>NN2 = 10<BR><BR>&#039;/ End variabels <BR><BR> &#039; Begin first row<BR> <BR> time0 = 0 <BR><BR> <BR> N_one0 = NN1 <BR><BR> <BR> N_two0 = NN2 <BR><BR> <BR> <BR> N0 = N_one0 + N_two0 <BR><BR> <BR> P_one0 = N_one0/N0 <BR><BR> <BR> P_one0 = N_two0/N0 <BR><BR> <BR> &#039; End first row<BR><BR>&#039; Putting the first calculation into zero Area<BR>N_one(0) = N_one0<BR>N_two(0) = N_two0<BR>N(0) = N0<BR>N_oneiM1 = N_one0<BR>N_twoiM1 = N_two0<BR>NiM1 = N0 <BR><BR>&#039;Begin massive looping<BR>For i = 1 To times <BR><BR> Timei = i <BR> <BR><BR><BR> N_onei = N_oneiM1 * Fi(0) + N_twoiM1 * Fi(1) <BR><BR><BR><BR> N_twoi = N_oneiM1 * Pi(1) <BR><BR><BR> Ni = N_onei + N_twoi <BR><BR> <BR> P_onei = N_onei/ Ni <BR><BR><BR> P_twoi = N_twoi/ Ni <BR><BR><BR> N_devide_Ni = Ni/ NiM1 <BR><BR> &#039;Begin sampling every xth element<BR> If i MOD sample = 0 Then <BR> counter = i sample &#039; integer division <BR> N_one(counter) = N_onei <BR> N_two(counter) = N_twoi<BR> N(counter) = Ni<BR> End If <BR> &#039;Set labels for X-axis <BR><BR><BR>&#039; Putting the values in the beginning values for the next loop, discarting values that will not be plotted<BR> N_oneiM1 = N_onei<BR> N_twoiM1 = N_twoi<BR> NiM1 = Ni <BR>Next <BR>response.write ("100th value: " & N_one(10) )<BR>%&#062;<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## I'm not psychic...

*WHERE* are you getting the overflow???<BR><BR>What line???<BR><BR>You also need to do a little rewriting:<BR><BR>********************<BR>&#060;%< BR>...<BR>Dim times, sampleEvery, sampleSize <BR>Dim N_one() <BR>Dim N_two() <BR>Dim N()<BR>Dim P_one() <BR>Dim P_two() <BR>Dim N_devide_N()<BR>Dim time() <BR>Dim counter <BR><BR>&#039; ****************************<BR>&#039; You need *THREE* controlling numbers! You only had two...<BR>&#039;<BR>&#039; Example: If you loop 100,000 times and want 50 samples,<BR>&#039; then you must take a sample every 2,000 times through the loop, yes?<BR>&#039; But you had no provision for all three of those numbers!<BR>&#039;<BR>times = 2560000 &#039; how many loops this thing will make. <BR><BR>sampleSize = 256 &#039; Set the sample size<BR><BR>sampleEvery = times / sampleSize &#039; for use with the MOD operator!<BR><BR>&#039; Then do this to avoid having to recode every time you make a change:<BR>ReDim N_one(sampleSize) <BR>ReDim N_two (sampleSize) <BR>ReDim N (sampleSize)<BR>ReDim P_one(sampleSize) <BR>ReDim P_two (sampleSize) <BR>ReDim N_devide_N (sampleSize)<BR>ReDim time (sampleSize) <BR><BR>.......... and then, in the code .......<BR><BR>&#039; See the point??? If you did this MOD sampleSize, it would<BR>&#039; be WRONG unless the sampleSize was the square root of the "times"<BR>&#039; value [which it happened to be for 10,000 times and 100 sample,<BR>&#039; but that was just a numerical coincidence!]<BR>&#039;<BR>&nbsp; &nbsp; If i MOD sampleEvery = 0 Then <BR>&nbsp; &nbsp; &nbsp; &nbsp; counter = i sampleEvery &#039; integer division <BR>&nbsp; &nbsp; &nbsp; &nbsp; N_one(counter) = N_onei <BR>&nbsp; &nbsp; &nbsp; &nbsp; N_two(counter) = N_twoi<BR>&nbsp; &nbsp; &nbsp; &nbsp; N(counter) = Ni<BR>&nbsp; &nbsp; End If <BR>...<BR>%&#062;<BR><BR>************************ *<BR><BR>No idea if all that will fix your overflow problem.<BR><BR>If it doesn&#039;t, then next time COPY AND PASTE the *entire* error message *AND* indicate which line it is referring to!<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## By the way...

It&#039;s "divide." There&#039;s no such word as "devide."<BR><BR>I know, I&#039;m as pedantic about spelling as I am about programming. What can I say?<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
105

## RE: I'm not psychic...

Thanks for the corrections!! :) Even the spelling one... (I&#039;m dutch, so a few spelling errors are allowed isn&#039; it?)<BR><BR>I did found the error for the overflow. It&#039;s not a programming bug, or that the computer is having too much to do. It&#039;s that &#039;N_one&#039; is getting so big that the error like you get on normal pocket-calculators, is giving the trouble here.<BR>So it&#039;s a flaw in the model, not the program. I only thought about it today. <BR>If only the compiler could give a more meaningfull error message...<BR><BR>Thanks again for your corrections,<BR><BR>Erwin.

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## You can make ALL ...

...the spelling mistakes you want! I *never* guessed you are Dutch. Your English and spelling are way above average for this message board! Congratulations....and my apologies for saying a thing!<BR><BR>Glad you figured out the overflow problem. I wouldn&#039;t have caught, more than likely, since I still haven&#039;t tried to figure out what the model is doing...if I could.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
105

## What the model is about

Thanks for the compliment :)))<BR><BR>In case you were getting curious about the model:<BR>I&#039;m a student at the University of Groningen and I&#039;m helping out a workgroup with putting there results on the internet.<BR>The model on the ASP page where I (well, *we*) worked on to get it running, is actually just an example model which is ages old. It&#039;s about genetic drift of genes in an isolated population (Gene N, N1 and N2). <BR>The model which they want to publish on the net is a bit more complicated, put by coding the mainframe for them they can adjust it to calculate what they want.<BR><BR>You will likely see a question from me again in the future, this messageboard had become my favourite because of you!<BR><BR>Erwin.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•