1 Pages (16 items)
Is there a way to determine the units of an arbitrary variable - Messages
#1 Posted: 3/10/2016 2:16:37 PM
Is there a way to determine the unit attached to an arbitrary variable? I would like to be able to do this in a user defined function.
I tried the most obvious thing x/abs(x) but this gives a dimensionless answer.
Anybody got any ideas?
example for clarification
if x=100V I would like to create a function Units(X) to return V or 1.V
I tried the most obvious thing x/abs(x) but this gives a dimensionless answer.
Anybody got any ideas?
example for clarification
if x=100V I would like to create a function Units(X) to return V or 1.V
#2 Posted: 3/10/2016 2:43:30 PM
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
kevnol 3/10/2016 6:54:00 PM
#3 Posted: 3/10/2016 3:06:12 PM
#4 Posted: 3/10/2016 5:15:09 PM
I am not 100% sure what you are doing Jean but I guess you have abandoned the default unit system and instead you are using your own units which are just unique numbers. Interesting idea but think this system will break down once you introduce compound units (unless you can somehow use prime numbers for basic units). Haven't fully thought it through though.
#5 Posted: 3/10/2016 5:23:24 PM
Davide
When I try to use UoM() in one of my own user defined functions it doesn't seem to work., Any ideas?
I am trying to use UoM to strip the units off a figure
eg StripUnit(x):=x/UoM(x)
x=50V
StripUnit(x)=50V
Or even more simply
Unit(x):=UoM(x)
Unit(50V)=1
When I try to use UoM() in one of my own user defined functions it doesn't seem to work., Any ideas?
I am trying to use UoM to strip the units off a figure
eg StripUnit(x):=x/UoM(x)
x=50V
StripUnit(x)=50V
Or even more simply
Unit(x):=UoM(x)
Unit(50V)=1
1 users liked this post
Davide Carpi 3/10/2016 7:36:00 PM
#6 Posted: 3/10/2016 6:17:35 PM
Try this:

I'm not sure why this is needed.
Brian

I'm not sure why this is needed.
Brian
2 users liked this post
#7 Posted: 3/10/2016 6:40:58 PM
Brian
How do I create a multi line function like that? This looks very useful.
Ahh .. Found it in the programming reference. Fun to be had.
How do I create a multi line function like that? This looks very useful.
Ahh .. Found it in the programming reference. Fun to be had.
#8 Posted: 3/10/2016 7:34:38 PM
Strange behavior, I have to investigate it...
BTW in the Extensions Manager, section Snippets, there is a Snippet called "Operations with units"; if you download it, you can insert the snippet in the canvas typing "Units" and then pressing the TAB key. In this snippet there is a version of UoM made with built-in functions (only for scalars).

BTW in the Extensions Manager, section Snippets, there is a Snippet called "Operations with units"; if you download it, you can insert the snippet in the canvas typing "Units" and then pressing the TAB key. In this snippet there is a version of UoM made with built-in functions (only for scalars).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#10 Posted: 3/10/2016 7:43:28 PM
Ok ok, I was lost in a glass of water...
UoM was designed to act in a generic way both with symbolic and numeric data... when you use it in a inline function, since x is unknown, his unit is 1 (dimensionless - hold the mouse over the definition); if you want to use it in a inline function you have to use Units(x):UoM(eval(x)). In programming functions (when you use line), eval in the argument is not needed, because the evaluation of UoM(x) is made when you call your function.
![2016-03-11 00_18_01-SMath Studio Desktop - [Page1_].png](/en-US/file/XXxbrA/2016-03-11-00_18_01-SMath-Studio-Desktop---_Page1___png)
Obviously if you know the dimensions the best approach is the one suggested in the post above (#9) by Jean.
UoM was designed to act in a generic way both with symbolic and numeric data... when you use it in a inline function, since x is unknown, his unit is 1 (dimensionless - hold the mouse over the definition); if you want to use it in a inline function you have to use Units(x):UoM(eval(x)). In programming functions (when you use line), eval in the argument is not needed, because the evaluation of UoM(x) is made when you call your function.
Obviously if you know the dimensions the best approach is the one suggested in the post above (#9) by Jean.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
kevnol 3/10/2016 8:37:00 PM
#11 Posted: 3/11/2016 6:46:52 AM
Thank you again David, your input has been very helpful.
The background behind my query is that I use complex number calculations a lot for electrical engineering. Smath handles units well for basic complex number calculations but certain key functions do not work with units (Arg(), Re() and Im()) in particular). You can get around this by dividing off the unit but this looks inelegant and needs to be explained every time I show the work to someone. I hope to write my own user defined functions to replace them and having a UoM() function is a nessecary step.
The background behind my query is that I use complex number calculations a lot for electrical engineering. Smath handles units well for basic complex number calculations but certain key functions do not work with units (Arg(), Re() and Im()) in particular). You can get around this by dividing off the unit but this looks inelegant and needs to be explained every time I show the work to someone. I hope to write my own user defined functions to replace them and having a UoM() function is a nessecary step.
#12 Posted: 3/11/2016 11:36:46 AM
WroteThe background behind my query is that I use complex number calculations a lot for electrical engineering. Smath handles units well for basic complex number calculations but certain key functions do not work with units (Arg(), Re() and Im()) in particular). You can get around this by dividing off the unit but this looks inelegant and needs to be explained every time I show the work to someone. I hope to write my own user defined functions to replace them and having a UoM() function is a nessecary step.
I use lot of complex too. Im(,) Re(,) work well in Smath 5346.
A short example would help to compare.
Jean
#13 Posted: 3/11/2016 12:29:41 PM
Jean here is an example showing what I mean. The functions Re(), Im() and arg() don't work when the operands have units.

By the way you may be interested in the worksheet I did for a simple AC calculation in the complex domain. it is available in the exampls section under "Engineering" and you can see it here: https://smath.com/wiki/GetFile.aspx?File=Examples/ElecEngExample.pdf
By the way you may be interested in the worksheet I did for a simple AC calculation in the complex domain. it is available in the exampls section under "Engineering" and you can see it here: https://smath.com/wiki/GetFile.aspx?File=Examples/ElecEngExample.pdf
#14 Posted: 3/11/2016 5:43:43 PM
There is more than unit problem. I don't use unit
maths are unitless. BUT I append result in "UnitProject".
Years long fight in Mathcad, conclusion from collabs:
"Jean is right". ISO, Engineering ... formulas are given
wrt the unit system. Revisit the "Visual Graphic" example
just reposted this morning.
Jean

maths are unitless. BUT I append result in "UnitProject".
Years long fight in Mathcad, conclusion from collabs:
"Jean is right". ISO, Engineering ... formulas are given
wrt the unit system. Revisit the "Visual Graphic" example
just reposted this morning.
Jean
#15 Posted: 3/11/2016 8:26:42 PM
6 users liked this post
ioan92 3/12/2016 5:58:00 AM, kevnol 3/11/2016 8:34:00 PM, Davide Carpi 3/11/2016 10:09:00 PM, уни 3/12/2016 12:23:00 AM, frapuano 3/12/2016 3:21:00 AM, Radovan Omorjan 3/12/2016 5:47:00 AM
1 Pages (16 items)
-
New Posts
-
No New Posts