How can I remove parentheses in a symbolic expression and perform the operations for the coefficients?

I cannot use parentheses and / operations in my code because PHClab can't interpret them. So I need to remove them. How can I make it? For example I have
x2/24 - x1/6 + (x1*x4)/8 + (2*x3)/15 - (11*x4)/120 - x5/14 + (5*x6)/56 + x7/2 - x8 + x9
and I need
0.04167*x2 - 0.1667*x1 + 0.125*x1*x4 + ... + x9
Thank you

댓글 수: 2

If you remove the brackets, the expression will change
Perhaps, but I can only remove the brackets if I convert the symbolic expression to a character array. I removed the parentheses so I got:
x2/24 - x1/6 + x1*x4/8 + 2*x3/15 - 11*x4/120 - x5/14 + 5*x6/56 + x7/2 - x8 + x9
What should I do next? How can I get from x2/24 to 0.04167*x2 ?

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

 채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 15일
편집: Mischa Kim 2014년 3월 15일
Zoltán, use the vpa command:
syms x2 x1 x4 x3
f = x2/24 - x1/6 + x1*x4/8 + 2*x3/15
f =
x2/24 - x1/6 + (2*x3)/15 + (x1*x4)/8
vpa(f,5) % the "5" denotes the number of significant digits
ans =
0.041667*x2 - 0.16667*x1 + 0.13333*x3 + 0.125*x1*x4

댓글 수: 3

...except one thing. some of the coefficients have the form:
1.0760050095961908208164032839825*10^(-82)
So vpa works well, but how can I turn from the scientific notation to the the standard notation (so that it does not contain parentheses)? 1.0760050095961908208164032839825e-82 would be correct.
I solved it by string manipulations (strrep).

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2014년 3월 15일

댓글:

2014년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by