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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

MathCAD 14 giving erroneous results with eval function

dsochor
5-Regular Member

MathCAD 14 giving erroneous results with eval function

In the attached MathCAD 14 worksheet, I am using the eval function to find solutions to 3 separate equations that determine an embedment depth "E" for a particular projected area. This forum so kindly helped me in the past while determining a way to return a zero if the equation result is complex. However, in the attached worksheet the eval function is returning a real value for the interior column equation when the actual answer is complex as can be seen in the attached spreadsheet. Is there a reason why it is returning a real value when the answer is actually complex and the eval function should be returning a zero?

1 REPLY 1

What you have done with the for loop in eval could better be done with vectorization.

The eval routine does NOT avoid complex numbers as a result for E (I added that "feature" in the attached sheet but I am not sure if it would be necessary). The onerror part only avoid an error in case the solve block fails to converge.

The problem yoiu encounter is simply precison. Solve block do numeric approximations up to a certain precision. The value for E.int given by the solve block yields a value for A which is close to the desired but complex. The realpart is close to the given A but there is a small imaginary part. For Mathcad its close/precise enough. You can change convergence tolerance by the system variable CTOL. Setting CTOL lower gives you the result you expected - see attached sheet. I replaced the 0 for a NaN is this seems to me more appropriate and because a zero would throw an error (division by zero) in the control calculations below.

Top Tags