Skip to main content
1-Visitor
November 25, 2014
Solved

Random unit assigned to 0

  • November 25, 2014
  • 11 replies
  • 4082 views

Hi,

I have tried to do some fixed-step equation solving for power converters, and I have encountered a very weird phenomenon : a unit assigned to "0" without being asked.

here is a file that reproduces the problem. The "physical" model is a boundary-mode buck converter. The switch is on (PWM=1) for a fixed duration (ton), then off (PWM=0) until the current in the inductor reaches 0.

When the PWM is set to 1, no problem, but when it is set to 0, Mathcad strangely sets it to 0s. If I specify a unit, this units "overrides" the s. If a unit is set to the "1" condition, it applies automatically to the "0" condition too (???). The only way I have found to get rid of this is to do PWM:=PWM/SIUnitsOf(PWM), but it would be much better if it didn't force some unwanted unit in the first place.

Any idea where that comes from, and how to prevent that from happening ?

Thanks

Best answer by Werner_E

Thats a strange effect, indeed and I have no explanation why Prime's dynamic unit checking thinks that the 0 seconds would be correct (sometimes).

You can get rid of it by dividing the 0 by UnitsOf(0) which is yet another miracle because UnitsOf(0) should simply yield 1 in every case but obviously sometimes yields 1 second and sometimes 1 ???

BTW, you don't even need an if statement for the calculation of PWM, as a boolean expression will yield exactly the 0 or 1 you need.

1.png

11 replies

Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I
November 25, 2014

Thats a strange effect, indeed and I have no explanation why Prime's dynamic unit checking thinks that the 0 seconds would be correct (sometimes).

You can get rid of it by dividing the 0 by UnitsOf(0) which is yet another miracle because UnitsOf(0) should simply yield 1 in every case but obviously sometimes yields 1 second and sometimes 1 ???

BTW, you don't even need an if statement for the calculation of PWM, as a boolean expression will yield exactly the 0 or 1 you need.

1.png

athurin1-VisitorAuthor
1-Visitor
November 25, 2014

Thank you very much. Good to see that I am not the only one to find this strange !

Strangely, UnitsOf(0) only returns 1s when the conditions returns 0, otherwise the other condition would return 1Hz. This is quite unbelievable !

If the PWM works, it allows to do fun stuff like Iin.k:=Il.k*PWM.k, and keep the units it should, which is much better than using ifs...

That being said, it is good news that there is a workaround, but it makes me worry about the whole unit management system. Can I really trust it ?

Werner_E
25-Diamond I
November 25, 2014

I would call the change from static unit checking (Mathcad 15) to dynamic unit checking (Prime) an improvement (one of the very few vs. the many drawbacks Prime has). And I guess it wasn't an easy task. So there still seem to be some quirks. As you have active maintainance you may consider turning in a bug report to PTC support staff.