Have a maple symbolic expression in MATLAB with % symbols, how can I get to just the solution?
6 次查看(过去 30 天)
显示 更早的评论
I have a long solution to polynomials I found using matlab's solve command using the maple symbolic engine. The reusult however has %1, %2 and %3 for substitution. I can isolate the %1, %2 and %3 and get an expression in MATLAB i can assign values to. Is there any way I could isolate the actual solution in terms of an expression I can evaluate with MATLAB. Thanks
Chris
0 个评论
回答(1 个)
Walter Roberson
2011-10-14
I think this is what I answered the first time around in http://www.mathworks.com/matlabcentral/answers/18235-1-2-and-3-in-solution ??
If the % expressions involve only variables that appear only there, then it might make sense to "isolate the actual solution in terms of an expression" you can evaluate with MATLAB, if by "actual solution" you refer to the entire long expression (probably in RootOf's) that expresses all of the roots.
But if the % expressions involve variables that also appear in other places, then assigning a fixed value to the subexpression is equivalent to assigning a constraint that it is not certain that one would be able to satisfy to get the overall roots. In such a case, you would add the constraint to the solve() equations and try again.
I think maybe I do not understand the question...
2 个评论
Walter Roberson
2011-10-14
Do you have the Extended Symbolic Toolbox or just the Symbolic Toolbox? If you have the Extended Symbolic, then you have full access to Maple and could then potentially use Maple's
CodeGeneration[Matlab]
in combination with codegen[optimize]
The Codegeneration facility is not available with the plain Symbolic Toolbox (not unless perhaps you are interfacing to a full version of Maple.)
With the way Maple works internally, subs() for %1 etc is one of the faster operations: each of those common expressions that are labeled with the same label points to exactly the same symbolic sub-tree, so subs() of all of them is implemented by simply replacing that symbolic sub-tree once with the replacement value.
Anyhow, if you want to do it the text-representation way, then we are back to the evalc() method I described in the other answer.
Note: when you are working with large symbolic expressions like this and doing subs(), then except for the "mandatory simplifications" (like removing + 0, or gathering constants at the same algebraic level), the resulting expression is not evaluated or simplified, which is why often you will see simplify(subs(...)) in Maple programs. subs() is pretty fast. What is slow is formatting large symbolic expressions for 2D printout!! If you have a large symbolic expression, print it out as seldom as you can get away with. And the process of labeling with %1 etc only applies for 2D printouts.
If you have a solution of polynomials, then _usually_ the approach is to concentrate on the RootOf() expressions, rather than the labeled expressions. If you substitute numeric values for the RootOf()'s, then a lot of the rest will usually collapse. Oh, you might still end up with big subtrees like sqrt(2+sqrt(2+sqrt(2+sqrt(....))))) but you can evalf() [Maple level] or vpa (MATLAB level) those out of existence pretty quickly unless you have a free variable caught up in them.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!