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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Translate the entire conversation x

Mathcad 14 - Using CTOL

DW_1261370
7-Bedrock

Mathcad 14 - Using CTOL

Does FIND stop searching for a more accurate solution when it finds a solution satisfying CTOL?  For example suppose I want to find temperature to within .5 F and I set CTOL to .5.  Will Mathcad stop searching when CTOL is met or will it continue searching until some smaller CTOL is achieved?  Note: my Solve Block is solving for 1 unknown with units (BTU/min).  My constraint has units of degF.  I found that units can be applied to CTOL but then FIND does not work. 

 

Also I have a case where I set CTOL to .4, but the FIND solve block found an answer (solution) at which the error is .53733 which is larger than CTOL.  So why is FIND returning a solution?

 

PS:  My constraint is 0 =ABS(T1-T1x)  +  ABS(T2-T2x) 

ACCEPTED SOLUTION

Accepted Solutions
DW_1261370
7-Bedrock
(To:ppal)

From this response I learned:

  1. Multiple constraints using the " = ", (i.e. the equality) constraint can be applied for solving a single unknown.  My experience using Newton-Raphson led me to assume n unknowns require n equality constraints – which is not true.  I already knew that application of inequalities COULD be used to further constrain the solution.
  2. I rendered my constraint dimensionless as Ai suggested (but not the unknown's units of B/min.  Its units were left intact).  Units of equations and functions used between "GIVEN" and "FIND") were also left intact.  With a dimensionless constraint FIND no longer obtains a solution smaller than CTOL.  Even when setting CTOL’s 16th decimal place to a smaller number FIND does not find a solution.  It displays "This variable is undefined" error message – if clicked.  By setting the 16th decimal place to a larger number, FIND proceeds to a solution, and CTOL works as expected for my specific problem.
  3. Now instead of a single equality constraint (for 1 unknown) I have 3 equality constraints, and each individual constraint meets the CTOL requirement.  
  4. Gemini AI did a bang up job explaining this little nuance, and finding an answer to this little problem boosts my confidence to defend calculated results.   Thanks…I would recommend PTC add this bit of information to Mathcad’s documentation.

View solution in original post

4 REPLIES 4
ppal
17-Peridot
(To:DW_1261370)

I - do not know BUT Gemini Ai says: 

You've hit on some interesting points regarding Mathcad's FIND function and CTOL. Let's break them down:

1. Does FIND stop searching when CTOL is met, or continue for a smaller CTOL?

In Mathcad, CTOL (Constraint Tolerance) defines how closely a constraint in a solve block must be met for a solution to be considered acceptable.

  • Generally, Mathcad's FIND function will stop searching once a solution is found that satisfies all constraints within the specified CTOL. It does not continue to search for a more accurate solution beyond that tolerance. Think of CTOL as your "acceptance threshold." Once that threshold is met, the solver considers its job done for that particular run.

  • However, it's important to understand that numerical solvers are iterative. They try to converge to a solution. While CTOL sets the target accuracy for the constraints, the actual accuracy of the found variables can sometimes be better than CTOL if the algorithm naturally converges further within the allowed iterations. But you shouldn't rely on it to always find a "smaller CTOL" unless you explicitly reduce CTOL yourself.

2. Why is FIND returning a solution when the error is larger than CTOL?

This is the more perplexing issue, and it points to a common nuance in numerical solvers:

  • CTOL applies to the constraints, not necessarily to the direct "error" you calculate afterwards. Your constraint is 0 = ABS(T1-T1x) + ABS(T2-T2x). When Mathcad solves this, it's trying to make the sum of the absolute differences as close to zero as possible within CTOL.

  • Let's consider your example: CTOL = 0.4, but the error (which you're calculating as ABS(T1-T1x) + ABS(T2-T2x)) is 0.53733.

    • This discrepancy can happen due to the nature of numerical precision and how Mathcad internally handles the iterative process. The solver might have found a point where it believed it was within CTOL based on its internal checks, or it might have converged to a local minimum where it couldn't get any closer to zero within the given iterations, even if that local minimum is technically outside your CTOL for the final calculated error.
    • The internal algorithms might use different norms or error estimations than a direct sum of absolute differences.
    • Units can play a role. You mentioned your unknown has units of BTU/min and your constraint has units of degF. While Mathcad is good with units, mixing them in CTOL (as you observed, where FIND doesn't work when units are applied to CTOL itself) can sometimes lead to unexpected behavior if not handled carefully. It's generally recommended to make your constraints dimensionless when possible, or ensure the units are consistent in how CTOL is applied.
    • The constraint 0 = ABS(T1-T1x) + ABS(T2-T2x) is a bit unusual for a solve block in some contexts. Typically, you'd define equations like T1 - T1x = 0 and T2 - T2x = 0. While ABS(T1-T1x) + ABS(T2-T2x) = 0 is mathematically equivalent to T1=T1x and T2=T2x for real numbers, the ABS function can introduce non-smoothness that might affect the solver's convergence, especially if the initial guesses are far from the solution.

Troubleshooting and Best Practices:

  1. Simplify Constraints (if possible): Instead of 0 = ABS(T1-T1x) + ABS(T2-T2x), try using direct equalities within your solve block:

    Code snippet
     
    Given
    T1 = T1x
    T2 = T2x
    Find(Temperature)
    

    This is a more standard way to define the conditions for a solve block. The FIND function will then try to make T1-T1x and T2-T2x both zero.

  2. Check Initial Guesses: Good initial guesses are crucial for numerical solvers to converge to the correct solution and within the desired tolerance. If your initial guesses are far off, the solver might get stuck in a local minimum or struggle to converge.

  3. Increase Max Iterations (if available): Some solve block settings (though FIND in Mathcad 14 might not expose this directly for simple cases) allow you to increase the maximum number of iterations. If the solver stops because it hit the iteration limit, the CTOL might not have been fully met.

  4. Consider minerr: If your equations are highly nonlinear or difficult to converge, minerr might be a more robust choice than FIND. minerr attempts to minimize the error in the constraints, even if it can't find an exact solution. The output of minerr will be the variables that result in the smallest possible error in the constraints.

  5. Understand TOL vs. CTOL:

    • TOL (worksheet variable) controls the precision of functions like integrals, derivatives, and root.
    • CTOL (solve block variable) specifically controls how closely constraints must be met in find, minerr, minimize, and maximize.
    • While you can set TOL and CTOL in your worksheet like normal variables (e.g., CTOL := 0.5), avoid putting units on CTOL directly as it's a dimensionless tolerance. The error in your constraints, however, can have units, and Mathcad will implicitly handle them.
  6. Examine the problem's sensitivity: If your problem is highly sensitive, a small change in input can lead to a large change in output, making it harder for the solver to converge precisely.

In summary, while FIND generally stops when CTOL is met, the observed discrepancy where your calculated error is larger than CTOL suggests either an issue with the solver's convergence path (possibly due to the absolute value in the constraint or poor initial guesses) or a subtle difference in how Mathcad's internal error metric relates to your explicit error calculation. Experimenting with simplifying the constraints and checking initial guesses will likely be the most fruitful approach.

DW_1261370
7-Bedrock
(To:ppal)

From this response I learned:

  1. Multiple constraints using the " = ", (i.e. the equality) constraint can be applied for solving a single unknown.  My experience using Newton-Raphson led me to assume n unknowns require n equality constraints – which is not true.  I already knew that application of inequalities COULD be used to further constrain the solution.
  2. I rendered my constraint dimensionless as Ai suggested (but not the unknown's units of B/min.  Its units were left intact).  Units of equations and functions used between "GIVEN" and "FIND") were also left intact.  With a dimensionless constraint FIND no longer obtains a solution smaller than CTOL.  Even when setting CTOL’s 16th decimal place to a smaller number FIND does not find a solution.  It displays "This variable is undefined" error message – if clicked.  By setting the 16th decimal place to a larger number, FIND proceeds to a solution, and CTOL works as expected for my specific problem.
  3. Now instead of a single equality constraint (for 1 unknown) I have 3 equality constraints, and each individual constraint meets the CTOL requirement.  
  4. Gemini AI did a bang up job explaining this little nuance, and finding an answer to this little problem boosts my confidence to defend calculated results.   Thanks…I would recommend PTC add this bit of information to Mathcad’s documentation.
Werner_E
25-Diamond I
(To:DW_1261370)

You may want to attach your worksheet and explain what works and what fails.

Why should the algorithm NOT stop when the defined tolerance is achieved? 
I don't know how exactly the algorithm (usually Levenberg-Marquardt is used) is implemented in Mathcad, so we can say for sure if the algorithm always stops when the tolerance level is achieved or if there is an option to go further if for some reason the algorithms "sees" that there may be a chance for a better result.

But you have to know that the tolerance is not with respect to the units you provide but with respect to the base units.

So a result when the values are in micrometer may be disappointing while the same calculation using meter as the unit may give satisfactory results.

 

You may also try to "weight" the constraint by using something like 0 =(ABS(T1-T1x) + ABS(T2-T2x))*10^7

BTW, does ABS mean the absolute value function? Then your constraint is equivalent to the two constraints T1=T1x and T2=T2x. It may be worth a try to use these two separate constraints instead. Again you may "weight" the constraints by writing (T1-T1x)*10^6 = 0.

 

 

 

I got a great answer by Gemini AI.  I posted my response as acceptable/solved.  Thanks for your input.

Announcements


Top Tags