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

SOLVED
Ruby I

## polyroots + units = error?

See please the attach (Prime 3)

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: polyroots + units = error?

!!!!!!!!!!!!!!!!!!!!!!!!!!!

Shame on me, praise for PTC!

Forget (most) of what I had written above.

polyroots() is fully unit aware and works intuitiv as expected - you just have to take care and use the correct units all over. And as Prime has dynamic unit checking you also have to supply the correct unit for a zero value.

That was the failure in your sheet. In your first attempt you supplied no unit at all and in your second the wrong unit. The correct unit for the coefficient of the linear element is length. If you supply km (or m, it doesn't matter) you get the correct result.

Even the eror message makes sense (though it wasn't helpful in your case). Mathcad can't tell the desired unit of the resulting variable unless you provide units for the first two elements of the vector. You can provide ANY units for those first two values, but the third (and all following for polynomial of higher order) have to be consistent. So you will never get an error that element 0 or element 1 should have a different dimension.

9 REPLIES 9

## Re: polyroots + units = error?

So you found yet another function in Prime which still will not work as expected when used with units 😞

The error message itself is a confusing (not necessarily wrong. It will always tell you that "Element 2 of this vector must have units: ...." no matter which of the first three elelements has the wrong unit (and disregarding the setting of ORIGIN).

But if you use polyroot with a vector of more than three elements and the wrong unit is in the fourth or higher element it will give you the appropriate element count (no matter what ORIGIN is set to, the first element is always "Element 0").

polyroot(v) will always solve so that the scalar product of v with the vector of powers of x is dimensionless

So you have a couple of choices to get polyroot to work.

The obvious and most natural one is to strip all units

Another approach is to make all elements the very same unit

Both ways above of course will give you a dimensionless solution. If you want solutions with correct units, you will have to adapt the units in the vector accordingly (which does not feel natural on first sight). The rule is to make the second element (the coefficient of the linear element) show the reciproke of the unit you want to see for the result. If the dimensions of the rest are OK this will work. In your case the dimension of the coefficient of the linear element is length (the zero reults from L-L). So we have to divide the whole vector by length and multiply by 1/velocity. Chosing the correct units might be tricky.

Of course you always can get one numerical solution with correct units if you use either root or a solve block

P.S.: Using your pseudounits as you did at the end of the new sheet you attached is dangerous as you loose most of the benefits the usage of units in Mathcad has.

## Re: polyroots + units = error?

It is one more bug.

## Re: polyroots + units = error?

You did it again, but thats not the correct answer

Its not a bug, just a missing feature.

EDIT: Wrong! The feature is not missing, you just have to use it correctly. See my answer below.

## Re: polyroots + units = error?

The correct solution of this problem is:

but I would liki to show using for this root, find and... polyroots functions.

## Re: polyroots + units = error?

No, its not a bug. Once you understand how it works there is a perfect logic. But it sure would help if the help clearly states how polyroot works, what it needs and what kind of result you can expect.

And of course it would be nice if polyroot would be implented differently so we could use it more intuitive.

At the time being you simply have to divide the vector by the unit of the result.

## Re: polyroots + units = error?

The polyroots-function with units is without bugs but for this collection http://communities.ptc.com/groups/mathcad-paradoxes

## Re: polyroots + units = error?

 Valery Ochkov wrote:The polyroots-function with units is without bugs but for this collection http://communities.ptc.com/groups/mathcad-paradoxes

No, I won't say its a paradox (its doesn't imply a contradiction). Its just a liitle bit more difficult to understand when used with units. And Prime users sure would be happy if PTC decides to implement it in a more user/unit friendly way.

EDIT: Again - see my answer below. It IS already implemented the way it should be.

## Re: polyroots + units = error?

!!!!!!!!!!!!!!!!!!!!!!!!!!!

Shame on me, praise for PTC!

Forget (most) of what I had written above.

polyroots() is fully unit aware and works intuitiv as expected - you just have to take care and use the correct units all over. And as Prime has dynamic unit checking you also have to supply the correct unit for a zero value.

That was the failure in your sheet. In your first attempt you supplied no unit at all and in your second the wrong unit. The correct unit for the coefficient of the linear element is length. If you supply km (or m, it doesn't matter) you get the correct result.

Even the eror message makes sense (though it wasn't helpful in your case). Mathcad can't tell the desired unit of the resulting variable unless you provide units for the first two elements of the vector. You can provide ANY units for those first two values, but the third (and all following for polynomial of higher order) have to be consistent. So you will never get an error that element 0 or element 1 should have a different dimension.

## Re: polyroots + units = error?

 Werner Exinger wrote:.... If you supply km (or m, it doesn't matter) you get the correct result.

Better is a nanotechnology!:

or a supernanotechnology - not 1 nm but 0 nm :

Announcements
Check out the latest