%1, %2 and %3 in solution

1 次查看(过去 30 天)
Chris
Chris 2011-10-13
Hello,
I have a long analytic symbolic solution to a system of polynomials using the solve command in matlab. The solution is given with variables %1 %2 and %3 to be substituted into the solution. Is there anyway to isolate these expressions and evaluate them first before substitution of values into the equation? I am using the maple symbolic toolbox.
Thanks,
Chris

采纳的回答

Walter Roberson
Walter Roberson 2011-10-13
You can use, for example,
maple('V3 := %3: V2 := %2: V1 := %1: subs(%3=v3,%2=v2,%1=v1,%);');
Be sure to use colon and not semi-colon until the end!
This should output a new expression that has v1, v2, v3 in place of the %1, %2, %3 subexpressions, with the values of those % subexpressions recorded in V1, V2, V3.
Note here that if you want to get V1, V2, V3 back out of Maple (because they are in Maple's engine, not MATLAB's), then you would need something like
V1 := maple('V1'); V2 := maple('V2'); V3 := maple('V3');
Note also that I assigned in reverse order. That is probably not so important, but substituting in reverse order can be important. When you substitute a variable name for a % expression then sometimes a different % expression that uses the other gets shorter enough that it is no longer long enough to break out later subexpression as a subexpression. The % expressions produced are always in increasing order, in the sense that an earlier-numbered one can refer to a later numbered one but a later numbered one can never refer to an earlier numbered one. By substituting for the last first, the nodes do not get destroyed before they would get rewritten out of existence.
Likewise if you assign from %1 first and accidentally do not suppress the assignment to %, %%, and %%% (the assignment is not done if you terminate the Maple command with colon), then when the first expression displays and builds subexpression breakouts for that, those subexpressions would get numbered starting from 1. Assigning in reverse helps reduce the impact of that (but you still need to be careful.)
I wrote above about the importance of doing the substitutions in reverse. That was a bit of a simplification of the real situation. In Maple, if you have a subs() command with multiple substitutions listed, then they are all done "simultaneously" -- e.g., the %1, %2, and %3 would be located in the expression tree before any substitution, so the order of subexpressions would not matter. But that only applies to any single subs() call, and it only applies within the Maple: I make no claim about the subs() that gets exported from the Symbolic Toolbox to the MATLAB interface.
More, perhaps, than you wanted to know ;-)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by