Skip to main content
8-Gravel
July 18, 2022
Question

Loop program

  • July 18, 2022
  • 2 replies
  • 3249 views

The problem is the R loop solve 2 instead of 1 and the Vx loop solve 2 instead of 3. What’s the problem?

 

2 replies

18-Opal
July 18, 2022

 

Don't know why the units cause problems.

 

See if this helps https://community.ptc.com/t5/Mathcad/Using-Units-in-a-for-loop/m-p/84351

 

ppal_0-1658184186869.png

 

25-Diamond I
July 19, 2022

When you learn programming than one of the first things you learn is that you should never compare float values for equality but rather ask if the absolut value of their difference is smaller than a certain small value like 10^-10.

The use of the units results in very small floating point rounding/conversion errors and so (l-b) is not exactly equal to x.

Werner_E_0-1658193125530.png

You may do it that way:

Werner_E_1-1658193371023.png

 

Or define a function

Werner_E_2-1658193589971.png

 

BTW, your programs don't contain any loops (no "if" and no "while").

8-Gravel
July 19, 2022

Thank you for your input. Is it possible to use different calculation formulae depending on x value 

              If x = (l-b); Matcad use formulae 1 to solve R

              If 0 ≤ x < (l-b); Matcad use formulae 2 to solve R

              If (l-b) < x ≤ l; Matcad use formulae 3 to solve R

              For any other values of x, Matcad use 0 to solve R

 

              If 0 ≤ x ≤ a; Matcad use formulae 1 to solve Vx

              If a < x < (l-b); Matcad use formulae 2 to solve Vx

              If (l-b) ≤ x ≤ l; Matcad use formulae 3 to solve Vx

              For any other values of x, Matcad use 0 to solve Vx

25-Diamond I
July 19, 2022

@AS_9781967 wrote:

Thank you for your input. Is it possible to use different calculation formulae depending on x value   

Sure. Simply replace "Result <-- 1" by "Result <-- <formulae 1>" etc.