Finding similar symbolic expressions in a vector
Afficher commentaires plus anciens
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
Réponses (1)
Star Strider
le 12 Oct 2012
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 commentaires
Jan Kappen
le 12 Oct 2012
Star Strider
le 12 Oct 2012
Modifié(e) : Star Strider
le 12 Oct 2012
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')
Catégories
En savoir plus sur Common Operations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!