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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Translate the entire conversation x

LeastSquaresFit with Unit of Measure (Mathcad Prime 11.0)

ptc-1681201
5-Regular Member

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 17

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

Cheers

Terry

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

Werner_E
25-Diamond I
(To:ptc-1681201)

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

 

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.

 

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.

Add the file, dummy!

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

Fred_Kohlhepp_0-1766898074144.png

 

Hi Fred, 

There's a problem with the forum (again).

You need to zip the file before attachment.

 

Success!

Luc

Thanks, @LucMeekes ,

 

You always seem to be mailing me out!

ptc-1681201
5-Regular Member
(To:Fred_Kohlhepp)

Your example is dimensionless. In this case everything works even for me! See my reply.

ptc-1681201
5-Regular Member
(To:ptc-1681201)

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

 

 

 

 

 

 

 

ptc-1681201
5-Regular Member
(To:ptc-1681201)

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

The top of your expression has units and the bottom doesn't.

Fred_Kohlhepp_0-1767014907580.png

This triggers that error!  Investigate Topen


@Fred_Kohlhepp wrote:

The top of your expression has units and the bottom doesn't.

Fred_Kohlhepp_0-1767014907580.png

This triggers that error!  Investigate Topen


Wouldn't this just mean that Zopen is of unit Rayl/m²  = kg/(m4*s) ?

From that screenshot we don't even see which version it stems from, if sigma is unit-less 350 or if its 315 Rayl.
We still don't see the definition of Topen, Zout or aL and how Zopen is related to Zo (which obviously is of unit Ohm).
I guess we will have to wait until @ptc-1681201  finally sends the sheet along with the data before we can make any assumptions about the error.

I believe that there's a clue: 

Fred_Kohlhepp_0-1767187703021.png

The top expression has units, the bottom doesn't,  The only difference between the top and the bottom is the terms of T_open(1,1) and T_open(1,2).

 

 

@Fred_Kohlhepp wrote:

I believe that there's a clue: 

Fred_Kohlhepp_0-1767187703021.png

The top expression has units, the bottom doesn't,  The only difference between the top and the bottom is the terms of T_open(1,1) and T_open(1,2).

 


Yes, it might look odd, and I also would have expected the unit ohms for a variable Z.... But after all we're not seeing the "big picture."
I think we can only make a reliable statement once @ptc-1681201  finally posts the worksheet, because with the snippets shown so far, I'm afraid we're only getting as far as reading tea leaves and crystal balls.
ptc-1681201
5-Regular Member
(To:Werner_E)

Just a moment, please..
Announcements

Top Tags