NaN error when converting vba to java

Hi,

Im finally running the project that was converted from vba to java unfortunately i'm not receiving the proper output. This is because vba seems alot more tolerant of using '0's in equations than java does. eg

vba:
dcr = 1 / (1 + dcrp1 * Exp(dcrp2 * Exp(0.5 * (MAsy(1) - MAsy(0)) / MAsy(0)) _
    * diff * mom(s0, s1, g0, g1, 0, 0, serv, l1, l2)))

java:
CONSTANTS.setDcr(1 / (1 + CONSTANTS.getDcrp1() * Math.exp(CONSTANTS.getDcrp2() * Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])
                * CONSTANTS.getDiff() * ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2])));

in both sitautions the array 'mom' for the given indexs is 0, however the vba version assigns a value to dcr whereas the java versions makes dcr 'NaN'

I understand what the problem is but cant (in my situation) think of a solution (except rewriting the whole code which is pretty much a nono because its not my logic and i dont really understand it and there's thousands of lines)

Any suggestions much appreciated
billyleoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RishadanPortCommented:
Are you sure there isn't a problem in one of the function calls to retreive certain variables? Unlike in your VBA code where you reference the variable directly, in your Java code, you are making function calls to retreives the data.

-->CONSTANTS.setDcr(..)

-->CONSTANTS.getDcrp1()

-->CONSTANTS.getDcrp2()

-->CONSTANTS.getDiff()

Also another difference is this part:

ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2]

here it is treating momArray directly as a 9 dimensional array, while the VBA code is a function call.
0
RishadanPortCommented:
>Im finally running the project that was converted from vba to java unfortunately i'm not receiving the >proper output. This is because vba seems alot more tolerant of using '0's in equations than java does.

I highly doubt that this is the case. I am quite sure that your conversation that has been translated into java has some errors in it
0
Peter KwanAnalyst ProgrammerCommented:
Please check for each of the components return correct values and data type:

CONSTANTS.getDcrp1()
CONSTANTS.getDcrp2()
ARRAYS.MAsy[1]
ARRAYS.MAsy[0]
CONSTANTS.getDiff()
ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2]

Especially the following:
ARRAYS.MAsy[0] = 0 ?
ARRAYS.MAsy[1]-ARRAYS.MAsy[0] = 0?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Peter KwanAnalyst ProgrammerCommented:
Since one of the way that would cause your value of dcr is NaN is this expression:
Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])

when
ARRAYS.MAsy[1] = ARRAYS.MAsy[0] = 0
0
billyleoAuthor Commented:
CONSTANTS.getDcrp1() returns correct value - in the current case - 0.074881

CONSTANTS.getDcrp2() - 3.830579999999994

CONSTANTS.getDiff()  - 0.1

ARRAYS.MAsy[1] - 2
ARRAYS.MAsy[0] - 2

ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2]  is usually 0 but i changed it to 1^-9

but these are the same values in the vba version and a definite value is produced!
0
Peter KwanAnalyst ProgrammerCommented:
I have tested your values, it should be outputting a value (0.93...).

Since your expression is quite complex, you may try to print out the values of :

Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])
 Math.exp(CONSTANTS.getDcrp2() * Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])
                * CONSTANTS.getDiff() * ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2])

to debug yourself. If you still have problems, please post your complete code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
billyleoAuthor Commented:
Thanks for the help - you were right the Nan reference is coming from some other part of the code - now to trawl through 6000+ lines and 3000 + iterations to find it.

Yippee
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.