Skip to main content
5-Regular Member
Dec 25, 2025 9:08 PM UTC
Question

LeastSquaresFit with Unit of Measure (Mathcad Prime 11.0)

Hi, and Merry Xmas

I' trying to work with LeastSquaresFit and functions and variables NOT unitless, and I'm having problems.

I have a variable ptc1681201_1-1766695724670.pngand some data obtained by interpolation

ptc1681201_0-1766695618199.png

I want to find a value for ptc1681201_3-1766696045778.png such that the function ptc1681201_2-1766695984035.png fits the y values.

I have defined

ptc1681201_4-1766696195563.png

Dimensionally everything seems correct:

ptc1681201_5-1766696374090.png

But, when I try to use 

ptc1681201_6-1766696462298.png

I get: "These units are not compatible".

Which units? Everything now is unitless!

Thanks

17 replies

terryhendicott
21-Topaz II
Dec 25, 2025 9:14 PM UTC

Please include your worksheet, you may need to put it in a zip file.

Cheers

Terry

Translate
23-Emerald V
Dec 25, 2025 9:31 PM UTC

If you click on your LeastSquaresFit expression, go to the Calculations tab, and click on the Error Tracing arrows, where does the calculation trail lead back to?  Which expression does it point to?

 

Stuart

Translate
Werner_E
25-Diamond I
Dec 25, 2025 11:42 PM UTC

From what you show it looks like it should work OK, so the error may be in the parts you don't show. That's the values in Matrix M and most importantly the definition of your function Z0. It may be that in some cases this function returns a dimensionless zero, while in other cases it returns a quantity with units. This can often work well, but in some cases it can lead to problems.
And then - error messages in Prime are not always accurate. The error does not necessarily have to do directly with the units.

 

I would therefore also recommend that you post your Prime sheet here. Either together with the data CSV file or with the data in a Matrix M that is already integrated in the Prime sheet (although this would be difficult to do in Prime).
Without the sheet, we can only grope in the dark and helplessly suggest one thing or another.
Apart from error tracing (which may refer to the Z0 function) as suggested by Stuart, you could also try omitting the optional arguments in the LeastSquareFit function (i.e., the last two) and see if the problem persists (I guess it will).
Or you could try your luck with the genfit function.
genfit(x,y, ß, GW)=   should also give you a suitable value for ß.

 

Translate
23-Emerald I
Dec 27, 2025 12:23 PM UTC

It's only a guess, but your expression 

Fred_Kohlhepp_0-1766837982707.png

is looking for a set of values, one for each set of values of x and y.

 

Often with this error vectorizing the RHS will allow computation to succeed; an alternative would be to create a function and solve for each point.

 

Translate
23-Emerald I
Dec 28, 2025 4:44 AM UTC

The attached program demonstrates a least squared fit of data to a polynomial function.  It works without the LeastSquaresFit function and runs in Prime Express, (built in version 4).  

 

Since you haven't shared What your expression should look like you can try this on your data to get curves that fit polynomial functions of sigma.

 

Smarter people than I might be able to adapt this scheme to other function types.

 

Good luck.

Translate
23-Emerald I
Dec 28, 2025 4:57 AM UTC

Add the file, dummy!

Translate
23-Emerald I
Dec 28, 2025 5:02 AM UTC

For some reason I can't attach the file.  But it's not large.

Fred_Kohlhepp_0-1766898074144.png

 

Translate
5-Regular Member
Dec 28, 2025 11:01 PM UTC

Hi, working with dimensionless variables in all the worksheet, since the beginning, everything works:

ptc1681201_0-1766962231132.png

However

ptc1681201_1-1766962375285.png

and

ptc1681201_2-1766962446115.png

Those errors lead back to

ptc1681201_3-1766962553763.png

However

ptc1681201_4-1766962609912.png

ptc1681201_5-1766962669526.png

So I don't understand why "Those units are not compatible".

To provide the source code I need some time to clean it up.

Thanks

 

 

 

 

 

 

 

Translate
5-Regular Member
Dec 28, 2025 11:48 PM UTC

Please don't mind the slight numerical difference: I know where it comes from and it's unimportant!

Translate