Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MathCAD 15 - strip variable's units? 1

Status
Not open for further replies.

justhumm

Structural
May 2, 2003
111
0
0
US
I've run into various situations where it would be useful to just simply strip the units off of a variable, so you are only left with the scalar value.

...or even just using a function to check the units of a variable that is already defined.

I've never been able to find anything, but is there a built-in function or a convention for stripping away the units?

units_zr538a.png
 
Replies continue below

Recommended for you

Could you define a Pscalar quantity after P and manually strip the units off.

P := 100lbf
Pscalar := P/lbf


...but I can't recall if I have ever solved that problem yet.
 
I'd like to come up with a more generic function that can work with any variable and any unit...

I just don't know if it's possible...

Code:
TruncU (P) := what units does variable "P" have?
[indent] If units = lbf
Then TruncU (P) = P / lbf
If units = psi
Then TruncU (P) = P / psi
...[/indent]

 
When I need a variable to be unitless, I've always found it easier to just divide out the units when I make the equation:
image_w1bdpg.png


You have to track it on your own, but you'd be doing that anyway with your unit stripping function.
 
The only safe way to "strip units" is to divide by the units manually.

As IRstuff says, you can use the "UnitsOf" function, but it divides by the base units. How would a fully automated solution that strips the units of any / all variables know whether you wanted the scalar answer for a 10 kilogram mass (say) to be given as 0.01 (tonnes), 10 (kg), 10000 (g), 22.046 (pounds) or 352.74 (ounces)?

 
Wow. I never knew "UnitsOf" was an actual function that existed. It's not exactly what I was hoping for, but it's at least a step in the right direction. Might be able to fudge a useful custom function with it. Neat!

Annotation_2019-08-27_155450_xn0mme.jpg
 
P:=2500*lbf

P/UnitsOf(P)returns 1.112 X 10^4 regardless of which Unit System is chosen. Seems to be identical with the SIUnitsOf function.
 
Status
Not open for further replies.
Back
Top