Skip to main content
5-Regular Member
December 25, 2025
Question

LeastSquaresFit with Unit of Measure (Mathcad Prime 11.0)

  • December 25, 2025
  • 6 replies
  • 635 views

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

6 replies

21-Topaz II
December 25, 2025

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

Cheers

Terry

23-Emerald V
December 25, 2025

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

25-Diamond I
December 25, 2025

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

 

23-Emerald I
December 27, 2025

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.

 

23-Emerald I
December 28, 2025

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.

23-Emerald I
December 28, 2025

Add the file, dummy!

23-Emerald I
December 28, 2025

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

Fred_Kohlhepp_0-1766898074144.png

 

5-Regular Member
December 28, 2025

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

 

 

 

 

 

 

 

5-Regular Member
December 28, 2025

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