Array value seems to blow up to infinity possibly a memory overflow issue?

  • Ok, so this is a 2-D flat plate heat conduction finite difference code...or at least it will be when its finished. Right now everything runs great until the last do loop where you basically find an interior value by averaging the 4 values around it. For some reason this is coming up with average values that are much bigger than any of the 4 values being averaged. The error it gives me when almost through the first run of the outter do loop is "type missmatch". The only think can think of is that the U(2,4) is essentially blowing up to infinity since the trend is for the output of this loop to increase very very rapidly. If I take the U(x, y - 1) term out of this loop and replace it with a constand it works just fine. This value is of course the output from the previous loop which has blown up considerably. Here's the code, I underlined the equation at the bottom that is causing all the fuss.



    Any help you can offer is much appreciated...


    Thanks and Gig 'em
    -Rick

  • Re: Array value seems to blow up to infinity possibly a memory overflow issue?


    Rick,


    Is there any reason why U() is defined as a string?


    I am think thing that U(x, y) = (U(x, y + 1) + U(x, y - 1) + U(x - 1, y) + U(x + 1, y)) / 4# may never be true if there is a rounding difference.


    Try changing it to
    ABS(U(x, y) - (U(x, y + 1) + U(x, y - 1) + U(x - 1, y) + U(x + 1, y)) / 4#) = some arbitrary tolerance value

    Kieran

  • Re: Array value seems to blow up to infinity possibly a memory overflow issue?


    thanks for the suggestion but taking the absolute value didn't change anything. U() is a string because it needs to be an array, I'm relatively new to vb so its possible there's a better way of working with arrays that I'm not aware of. It just doesn't make sense, If I punch that equation in my calculator with the values that the debugger gives for that iteration I get a reasonable average. Adding the # after real number is a recent thing I did while trying to figure this problem out. I thought that I might be having a problem dividing a real number by an integer or something like that. This numeric scheme works by writing a new value of temperature for a point based on the temperature at the neighboring points. It is supposed to be assigning a new value of U(x,y) for every iteration, so U(x, y) = (U(x, y + 1) + U(x, y - 1) + U(x - 1, y) + U(x + 1, y)) / 4# will not necessarily be "true" in an algebraic sense. I might have a feedback loop somewhere in my sweeping scheme but I just can't find it.


    Thanks again,
    -Rick

  • Re: Array value seems to blow up to infinity possibly a memory overflow issue?


    U() defines an array, it can be of type Integer, or Long, or Double, or String or Variant.
    Defining it as a string may cause the formula to have problems. Try Long or Double or Variant. (Variant will accept anything, but is most expensive on memory in comparison).


    Try running the process with a debug statement like
    Debug.Print U(x, y); (U(x, y + 1) + U(x, y - 1) + U(x - 1, y) + U(x + 1, y)) / 4# ; x ; y


    You will see the values listed int the immediate pane in the VB editor.


    Hope it helps

    Kieran

  • Re: Array value seems to blow up to infinity possibly a memory overflow issue?


    You Rock!


    That was it. I chaged my strings to doubles and it worked beautifuly. Thanks a bunch, now I can get some sleep.


    -Rick

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!