How do I separate terms using symbolic expression?

26 ビュー (過去 30 日間)
zak owen
zak owen 2023 年 1 月 27 日
回答済み: John D'Errico 2023 年 1 月 27 日
How can I edit my code so that the symbolic expression displays as (pi/L)^2 * sqrt((g*E*I/A*gamma)) instead of displaying pi^2*sqrt((g*E*I/A*gamma))/L^2?
Here's the code i've tried and the output I'm trying to correct.
syms omega_1 pi I A omega_2 L g E d gamma
omega_1 = ((pi/L)^2)*(sqrt((g*E*I)/(A*gamma)))
omega_1 = 
  1 件のコメント
Torsten
Torsten 2023 年 1 月 27 日
How can I edit my code so that the symbolic expression displays as (pi/L)^2 * sqrt((g*E*I/A*gamma)) instead of displaying pi^2*sqrt((g*E*I/A*gamma))/L^2?
You can't. MATLAB decides internally how to display expressions.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2023 年 1 月 27 日
Trying to get a symbolic tool to give you exactly the form you want to see is often terribly difficult, and usually not worth the effort especially when the change is pretty minor. In this case, you can see the two forms are mathematically identical. So is it really worth stumbling around? Go on to the next step in your work.
syms omega_1 pi I A omega_2 L g E d gamma
omega_1 = ((pi/L)^2)*(sqrt((g*E*I)/(A*gamma)))
omega_1 = 
Sometimes you can play around with simplify, to get it to find a different version of the expression.
simplify(omega_1,'steps',100,'all',true)
ans = 
And sometimes you can convince rewrite to find some alternative form.
One thought is to try to force subs to just replace the offending pair of terms. Unfortunately, subs also seems to do a simplify before it returns a result. I wish an option for subs is to not do a simplify.
subs(omega_1,pi^2/L^2,(pi/L)^2)
ans = 
You might do this, if it really bothers you.
syms piOverL
subs(omega_1,pi/L,piOverL)
ans = 
subs(ans,piOverL,pi/L)
ans = 
The subs just insists on performing a simplify.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by