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

조회 수: 10 (최근 30일)
Lucas Clark
Lucas Clark 2020년 1월 12일
댓글: Paul 2024년 3월 15일
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?

채택된 답변

Star Strider
Star Strider 2020년 1월 12일
It appears that the square root is still expressed as a square root, so the units remain the same within it:
omega_n =
27.42*(1037.0*(([Pa]*[m]^6)/([N]*[s]^2)))^(1/2)*(1/[m]^2)
Doing this:
[omega_n,omega_n_u] = separateUnits(omega_n)
produces this:
omega_n =
882.80792016869907152094706300452
omega_n_u =
1*((1/[N]^(1/2)*[Pa]^(1/2)*[m])/[s])
So the units convert correctly. It is necessary to specifically request the conversion.
  댓글 수: 3
Lucas Clark
Lucas Clark 2020년 1월 12일
So, I tried a few other things.
When I broke down the units of E from:
E = 207e9*u.Pa;
to
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 2020년 1월 12일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Goodmanson
David Goodmanson 2020년 1월 13일
편집: David Goodmanson 2020년 1월 13일
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.
  댓글 수: 3
Breyonna
Breyonna 2024년 3월 14일
I am hoping that there is a better way. I'm off to video tutorials.
Paul
Paul 2024년 3월 15일
Maybe I'm missing something, but I don't unerstand what the issue is. One extra call to simplify seems to solve the problem. What is the downside of that?
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)
omega_n = 
omega_n = simplify(omega_n)
omega_n = 

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by