Skip to main content
1-Visitor
April 26, 2017
Question

Floating Point Error

  • April 26, 2017
  • 3 replies
  • 4880 views

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

3 replies

25-Diamond I
April 26, 2017

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

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

1-Visitor
April 26, 2017

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

1-Visitor
April 26, 2017

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

24-Ruby IV
April 27, 2017

May be so is any help for you

1-3.png

1-Visitor
April 28, 2017

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

25-Diamond I
April 29, 2017

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:

1-Visitor
April 29, 2017

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