Skip to main content
4-Participant
February 20, 2025
Solved

Mathcad Prime 10: Error when using Root() function on Linfit() polynomial

  • February 20, 2025
  • 1 reply
  • 1060 views

Hello Mathcad community,

 

I ran into an error while using the root() function on a linfit() polynomial in Prime 10.0.1.0.

I approximated a function by using the linfit() function on two vectors for the x- and y-coordinates respectively. The resulting coefficient vector for a cubic polynomial approximation is shown below.

JL_9025368_0-1740071821226.png

The approximating function can now be written as below (as a dot-product):

 

JL_9025368_1-1740071868496.png

 

I need to find the z-coordinate for a given value of s(z), so I want to use the root() function to do this. When entering the function as specified above, the root() function gives me the error "these matrices must have compatible units".

 

JL_9025368_2-1740072010231.png

 

However, when I use the individual polynomial coefficients from c_cub to specify the s(z) function directly by expanding the dot-product, everything works fine.

 

JL_9025368_3-1740072117072.png

 

Any idea why this behaves differently? What am I missing?

 

Thanks for any insights on this.

Joost

 

 

 

Best answer by Werner_E

In my opinion it should work exactly the way you had written it.

 

So it seems to me that you found a bug which may be worth reporting to official PTC support.

 

As a workaround you could use the root function by providing a guess value (which interestingly works OK)

Werner_E_0-1740075462227.png

 

Or you could evaluate the function definition symbolically which basically results in what you did by using the individual coefficients manually.

Werner_E_2-1740080678613.png

You have to turn on "Units/Constants in symbolics" in the calculation options first as otherwise some of the "m" will not be labelled as being units.

 

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
February 20, 2025

In my opinion it should work exactly the way you had written it.

 

So it seems to me that you found a bug which may be worth reporting to official PTC support.

 

As a workaround you could use the root function by providing a guess value (which interestingly works OK)

Werner_E_0-1740075462227.png

 

Or you could evaluate the function definition symbolically which basically results in what you did by using the individual coefficients manually.

Werner_E_2-1740080678613.png

You have to turn on "Units/Constants in symbolics" in the calculation options first as otherwise some of the "m" will not be labelled as being units.

 

JoostL4-ParticipantAuthor
4-Participant
February 20, 2025

Thanks for the response.

I had also noticed in other parts of the worksheet that the dot-product version of the function behaves differently than the expanded version. I have to sometimes vectorize the dot-product version when using it in chart components.

I like your suggestion to use the guess value. It keeps the formulas short; I think I will incorporate that as a work-around.

 

Funny enough, I only found out recently while digging through the documentation that you could use the dot-product. I was using the expanded notation up to now, but they get long sometimes when using descriptive variable names. So I came across the error very recently.

Anyway, thanks for your help!

 

I will reach out to PTC support for a bug report.

 

Cheers,

JL

25-Diamond I
February 20, 2025

@JoostL 

Here is an even more compact definition of your function without the need of defining the vector function vf(x).

And as luck would have it, the bug you found does not occur with this definition (don't ask me why) 😉

Werner_E_0-1740090226060.png

The degree of the function is determined by the number of elements in the coefficient vector.
If the entries are entered there in reverse order, the function could be formulated a little shorter (simply z^k instead of z^(last(c)-k) )

 

BTW, instead of using the dot product you could again use a sum and that way you also can avoid the bug

Werner_E_0-1740091375491.png