MATLAB Answers

Why are the symbolic units not evaluated by a square root?

17 views (last 30 days)
Lucas Clark
Lucas Clark on 12 Jan 2020
Commented: Lucas Clark on 13 Jan 2020
clear, clc
u = symunit;
d = .025*u.m; %Automatically convert to meters
l = .6*u.m;
A = pi*d^2/4;
g = 9.81*u.m/u.s^2;
E = 207e9*u.Pa;
I = pi*d^4/64;
lambda = 76.5e3*u.N/u.m^3;
omega_n = vpa((pi/l)^2*(g*E*I/(A*lambda))^(1/2),4)
When I plug this in, the units stay the same inside the square root.
Why aren't they evaluated?


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 12 Jan 2020
It appears that the square root is still expressed as a square root, so the units remain the same within it:
omega_n =
Doing this:
[omega_n,omega_n_u] = separateUnits(omega_n)
produces this:
omega_n =
omega_n_u =
So the units convert correctly. It is necessary to specifically request the conversion.


Lucas Clark
Lucas Clark on 12 Jan 2020
I'm not sure.
I separated the units out and tried converting them as 1/seconds using unitConvert function.
It does not turn out at 1/seconds though, the square root still fails to evaluate the units inside it.
Lucas Clark
Lucas Clark on 12 Jan 2020
So, I tried a few other things.
When I broke down the units of E from:
E = 207e9*u.Pa;
E = 207e9*u.N/u.m^2;
Then everything simplified very easily and I ended up with a value of 1/seconds.
I'm not sure what this means. Let me know if you understand why it didn't work the first time.
Thank you.
Star Strider
Star Strider on 12 Jan 2020
My pleasure.
The reason it did not work the first time is that the units will not convert until you request that they be converted. This likely makes things easier for the Symbolic Math Toolbos, so that it does not have to convert and then re-convert interim results, converting them only when requested at the end.

Sign in to comment.

More Answers (1)

David Goodmanson
David Goodmanson on 13 Jan 2020
Edited: David Goodmanson on 13 Jan 2020
Hi Lucas,
try your original code but with the last two lines
omega_n = (pi/l)^2*(g*E*I/(A*lambda))^(1/2)
omega_n = vpa(simplify(omega_n),4)
omega_n = 882.8*(1/[s])
Then you don't have to do any conversions yourself, e.g Pa to SI.

  1 Comment

Lucas Clark
Lucas Clark on 13 Jan 2020
I was trying not to have to rewrite it like that. If I were to make small adjustments to the area or inertia, then I would have to run it and then type out the correct one again.
I'd prefer not to have to retype everytime I make a change, but if I couldn't figure out the way I wanted this is what I wouldv'e done.
Thank you.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by