Finding similar symbolic expressions in a vector
조회 수: 1 (최근 30일)
이전 댓글 표시
Hey guys, i have following problem:
Let there be a long vector containing symbolic expressions. To reduce the vector length i try to find elements which are correlated (i don't know if that is the right word for what i mean, maybe an example will help).
For example:
v = [a, b^2+c, d^4/e, -a+b^2+c, -a].'
Here is v(5)=-v(1) or the other way round. And v(4)=-v(1)+v(2)
There might exist other combinations, but these i can see directly.
The big question is: Is there a function or some functions i can use, or should i iterate the whole vector and compare each row to the others?
The first problem (v(x) = t*v(y) where t is a constant, x and y are some rows in the vector) is easier than the second one i think.
I tried some combinations of unique and sort, but unique only shows me identical lines, not similar ones.
Any ideas? Thank you very much :)
ps : i use matlab 2011a
댓글 수: 0
답변 (1개)
Star Strider
2012년 10월 12일
syms a b c d e
v = [a, b^2+c, d^4/e, -a+b^2+c, -a].'
cv = children(v)
cv{1:5}
I have 2012b but I believe this is also available in 2011a.
댓글 수: 2
Star Strider
2012년 10월 12일
편집: Star Strider
2012년 10월 12일
Sorry.
In that situation, I suggest subexpr, the only other alternative I can find. It should exist in 2011a.
You can use subexpr iteratively:
syms a b c d e
v = [a, b^2+c, d^4/e, -a+b^2+c, -a].'
[r1,s1] = subexpr(v, 'S1')
[r2,s2] = subexpr(r1, 'S2')
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!