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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

polyroots + units = error?

ValeryOchkov
24-Ruby IV

polyroots + units = error?

See please the attach (Prime 3)

1 ACCEPTED SOLUTION

Accepted Solutions

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

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.7.png

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.

8.png

View solution in original post

9 REPLIES 9

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").

5.png

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

00.png

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

The obvious and most natural one is to strip all units

1.png

Another approach is to make all elements the very same unit

2.png

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.

000.png

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

3.png

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.

It is one more bug.

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.

The correct solution of this problem is:

river-boat.png

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

The polyroot is with a bug - for this collection http://communities.ptc.com/groups/mathcad-paradoxes

The polyroot is with a bug - for this collection http://communities.ptc.com/groups/mathcad-paradoxes

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.

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

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.

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

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.7.png

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.

8.png

Werner Exinger wrote:

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

Better is a nanotechnology!:

nt.png

or a supernanotechnology - not 1 nm but 0 nm :

Top Tags