Factorization of syms class objects
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I create Syms class matrices with elements taking a similar structure to this,
a11*(a1*a4*a7 + a2*a5*a9) + a3*a7*a11
I wish to factor each cell in such a way that there is no reptition of variables. In cases such as the above using 'factor' or 'simplify' only removes the common factor 'a11' from the term yielding,
a11*(a3*a7 + a1*a4*a7 + a2*a5*a9).
However, i am looking for 'a7' to also be factored out; thus yielding,
a11*( a7*(a3 + a1*a4) + a2*a5*a9).
I am interested to hear if anyone has an approach for dealing with such a problem.
Regards
Ross
Note: The methods applied to reach the original matrix would never return solutions which could not be factored in such a way that every variable occurs only once in the term.
2 Commenti
Sean de Wolski
il 16 Dic 2011
Just a note: Naming a variable a11 is very hard to understand since it looks like all, a very useful builtin function.
Risposta accettata
Walter Roberson
il 16 Dic 2011
You get the "low-lying fruit" with using factor(), but after that it gets more messy for sure.
The approximate route I can think of at the moment is:
Create a MuPad procedure. In the procedure, if op(0) of the result is _mult then map() the procedure recursively over the expression. When the expression is not _mult then factor() the expression; if the result of that has op(0) of _mult then map() the procedure recursively over the factored expression.
Now if the expression type was not _mult and factor() did not result in a _mult, then use indets() to find the variable names in the expression. If there were no variables then return (this takes care of numeric constants and constants such as Pi and symbolic constants such as tan(Pi/17)). If there were variables, loop over the variables and coeff the current expression with regards to each variable in turn. If the result of the coeff is an expression sequence then nops([TheSequence]) to get the number of items; if the result of the coeff has op(0) of _plus then nops() to get the number of subexpressions; otherwise the count is 1. If all the counts were 1, return -- each variable occurs uniquely. Otherwise, determine the variable that had the largest count out of all the variables (i.e., the variable that occurred most frequently) and collect() the expression with regards to that variable, and then map() the function over the collected expression.
I didn't say it was easy!
2 Commenti
Walter Roberson
il 16 Dic 2011
I do not have the Symbolic Toolbox myself, so I have not had a chance to work through the "standard tricks" in analyzing expressions. I use Maple, and in Maple I suspect I would probably write this using Maple's subsindets() or evalindets() and use more pattern matching and less recursion; and the counting would be made easier by using Maple's coeffs().
The symbolic packages are pretty big; there is often some obscure way to do things.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!