cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are working to address an issue with subscription email notifications. In the meantime, be sure to check your favorite boards for new topics.

Floating Point Error

shammett-2
1-Newbie

Floating Point Error

I am getting a floating point error in a structural analysis routine I am writing in Mathcad 15.  Does anyone have experience correcting this type of error?  Any advice would be greatly appreciated.

I have attached the routine as it currently exists.  I will be glad to provide additional information, so just let me know if something further is needed.

Thanks!

Steve

8 REPLIES 8

> so just let me know if something further is needed.

First step would be to attach the worksheet, not just a pdf.

Werner,

Thanks for getting back to me.  Attached is the entire Mathcad file in v15.  There is a lot going on in the worksheet, but you will find the routine a little over half way down.

Thank you!

Steve

I inserted a trace command in your program and looked at some variables by toggling debugging (menu -> Tools -> Debug)

Just before the program fails Q.Total gets a value near the greatest possible number - guess that will throw the error.

It looks like your while-loop is running havoc  as ReactionError never gets smaller!

You collect all ReactionErrors in a matrix and then define the absolute maximum of the whole matrix as the value to compare with. So if just one value in the whoöle matrix is bigger than 0.001, your while loop will never end.

Why do you use a matrix for all the ReactionErrors?

I tried to get rid of the array and used a single ReactionError variable, but again the floating point error. Guess the error never gets small enough.

You can now explore your program yourself using the trace command to see whats going on and maybe also use the pause command for debugging.

First thing I would do is to look at the values of the max of ReactionError.

Werner,

Wow...  I guess that is the best response to what is actually happening the routine.  The largest correct Q.Total values should probably never exceed a couple of thousand or so.  I will go back through and try to correct the unbounded growth of Q.Total. 

The maximum absolute value of the whole matrix is used because I need all entries to meet the convergence criterion.  I simply look at the largest value to make sure it is small enough.  I could certainly use a larger value, say 1 or even 10 instead of 0.001, but at this point I do not think that is a problem.

I will let you know when I have made some progress!

Thank you very much for your help!

Steve

May be so is any help for you

1-3.png

Werner and Valery:

I went back through the routine carefully and found a few errors in the Reaction, ReactionError, QTotalNew and QPileFaceNew equations.  I believe those problems have now been corrected.  The routine converges for every situation I have run through it so far.  A couple of tweaks still need to be applied, but the big problem with floating point errors appears to be resolved.  I have attached a couple of files for you guys to review if interested.  I would love to hear any advice or comments you might have.

Werner:  Thanks for taking the time to trace the error.  Knowing the nature of the floating point error helped tremendously in my effort to correct the problem.

Thank you very much for your time and your help!

Steve

You are welcome!

Glad you found a solution for your problem.

Turning on debugging and using trace and pause commands is a powerful tool to find that kind of errors. Unfortunately thats another feature missing in Prime.

The matrix ReactionError is always overwritten by a single scalar after the i-for-loop is through, so there is no need to make it a 2-dimensional array (you simply can omit the index j).

Here is a way to avoid the creation of a matrix/vector altogether (at the cost of introducing a new variable and an additional if statement):

Attached is  the worksheet with a modified "NLA_WE.Method1" so you can compare the results (they are equal, of course).

You may apply the same changes to your "NLA.Method2" and "NLA.Method3".

If did not look closely at those routines  - are all those "NLA.Method...." supposed to yield the same results? They don't:

Werner,

All good points!

Methods 1, 2 and 3 are supposed to yield different results.  I would be terrified if they were the same!!!

Thanks for your help!

Steve

Top Tags