Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Why can I not use variables in math expressions?
Best Answer
-
Right, an operation like sqrt(1 meter) isn't well-defined: Does it mean 1 meter? 10 centimeters? Or nothing at all? Onshape says the latter

If #X has length units, you can use an expression like sqrt(#X / inch) * inch, which is well-defined.
3
Answers
-
it may be because of the units of #x, linear operations keep units the same but power of the value with units doesnt
3 -
Right, an operation like sqrt(1 meter) isn't well-defined: Does it mean 1 meter? 10 centimeters? Or nothing at all? Onshape says the latter

If #X has length units, you can use an expression like sqrt(#X / inch) * inch, which is well-defined.
3 -
I get around this by using unitless variables.1
-
I also use unitless until the bitter end0
-
I don't see what is unclear about the definition. For example (10 mm)^2 = 100 mm², and onshape knows how to handle this just fine. Taking a square root is no different, except the power is 1/2. The units then would be mm^(1/2). In your example, (1 m)^0.5 = 1 m^0.5; if the value were given e.g. in cm: sqrt(100 cm) = 10 sqrt(cm) = 10 sqrt(1/100 m) = 10 * 1/10 * sqrt(m) = 1 m^0.5. This is all perfectly consistent, there is nothing vague about it, and I don't see why using this would not be allowed.
Sure, units like these don't make much physical sense, but that doesn't matter. As e.g. an intermediate result, it could be perfectly valid.Having to convert my variables to be unitless before performing an operation, and then manually adding in the correct dimension at the end is very cumbersome, it makes writing an expression take minutes instead of seconds. What makes it worse is the inconsistency: some operations, like positive integer powers of values with units seem to be allowed, but others aren't. I often find myself having to break down expressions into their smallest parts, checking each element to make sure it evaluates properly, and then slowly building it back up again with the necessary hacks like dividing by units before doing some operations.
she/her
0





