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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Random unit assigned to 0

athurin
4-Participant

Random unit assigned to 0

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

11 REPLIES 11

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

athurin
4-Participant
(To:Werner_E)

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 ?

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.

athurin
4-Participant
(To:Werner_E)

Until today, I had no doubt that it works great (I can't compare with Mathcad 15, I never used it), and using units is, in my opinion, one of the best (and easiest!) way of checking your equations are right. But seeing this kind of things make me wonder if something went wrong with units somewhere else, and made an equation look right when it actually isn't. False positive like here are not too much an issue (as long as there is a workaround), false negative have much bigger consequences.

I will report the bug to PTC, thanks for your suggestion.

I guess the problem only occurs when zero is in play. Prime (probably for our convience) tries to add the "proper" (?) unit to a value of zero and that seems to fail sometimes and leads to some strange effects.

1.png

Its nice that in the first example Prime adds unit Ohm to R1 and calculates the serial connection with the intended unit. The parallel circuit is left unitless !??

The alternative would be that Prime yields an error in the first example and forces its users to use consequently units even with zero values. less convenient but maybe the better approach.

athurin
4-Participant
(To:Werner_E)

Personally, I would prefer the alternative, but I guess there is no universal answer to that. Since I use units a lot for consitency / error / scaling checking, I am very rigourous (or at least, try to be) in my inputs. but I know it is not the case of some of my colleagues who can't be bothered with putting units in their sheets (I will never understand why).

Either way, it is good to know how it works. This particular problem is not unmanageable, once you know about it. Putting "0 / UnitsOf(0)" everywhere isn't very esthetic, but as long as it does the trick ... And as long as non-zero values are fine ...

Adrien Thurin wrote:

Personally, I would prefer the alternative,

So do I.

Either way, it is good to know how it works. This particular problem is not unmanageable, once you know about it. Putting "0 / UnitsOf(0)" everywhere isn't very esthetic, but as long as it does the trick ... And as long as non-zero values are fine ...

I hope the problem ony occurs when zero is in play. But the effect you experienced sure applies for a bug.

RichardJ
19-Tanzanite
(To:Werner_E)

Werner Exinger wrote:

Adrien Thurin wrote:

Personally, I would prefer the alternative,

So do I.

Me too. It's the way Mathcad 11 worked. 0+10*Ohms would give an error. Mathsoft spent years getting dynamic unit checking right, but I guess PTC decided it was better to reinvent the wheel.

From the Prime Migration Guide:

To provide more control over how numeral 0 should behave, PTC Mathcad Prime

provides two built-in constants:

• zero (lowercase) — Represents dimension less 0. For example, zero + 1m

yields an error whereas 0 + 1m = 1m

Use variable zero to ensure that the quantity is always checked for correct

dimension, even when it has a magnitude of 0.

• Zero (uppercase) — Represents 0 of any quantity. It assumes whatever unit is

required by the computation. For example, Zero*m + Zero*s = 0

Use variable Zero to simulate compatibility with legacy Mathcad treatment.

So, this is, as Werner stated above, a result of Prime's dynamic unit checking. It can, at times, make the use of "zero" somewhat less than obvious. Yours is an interesting situation, in which the zero takes on the units of the variable used in the conditional statement. However, another option is to use lowercase "zero" in the "else" statement. No, it isn't necessarily obvious, but this constant was added to Prime for just such a case. It isn't always necessary to use "zero" or "Zero", but in this case it is perhaps a slightly more aesthetically pleasing solution to your dilemma.

zero.jpg

athurin
4-Participant
(To:lwestbrook)

Thank you very much. This is a very interesting way to solve the problem.

Thank you very much !!

Thanks for the info about zero and Zero, Jonathan. Its never to late to learn something new.

Top Tags