Replace a multiple of two symbolic numbers

1 次查看(过去 30 天)
Hi,
I'm attempting to replace (to linearise my equation) the multiple of two very small values dx and dy.
I attempted to use subs but it doesn't seem to work.
Code: PO=subs(PO,[(dx*dy),(dy*dx)],[0,0]);
PO is my symbolic vector. There is no error message but it just doesn't pick up the combination. Any Ideas?
Thanks!
Matlab Version: 2012a

采纳的回答

Star Strider
Star Strider 2012-10-18
编辑:Star Strider 2012-10-18
I honestly don't understand why your subs call doesn't work. I can't make it work either, in spite of a number of different approaches that have worked for me previously. I consider this a bug, so you may want to report it to TMW as such.
All is not lost, however. Here's a kludgy but effective work-around. Note that it still only recognizes (dx*dy) and not such as (dx*dy)^2:
syms dx dy x y
PO = expand( (x + dx) * (y + dy) + (dx * dy) ) % Prototype expression
[POc, T] = coeffs(PO, [dx dy])
Tfind = find(T == 'dx*dy')
POc(Tfind) = 0
PO = POc * T.'
This could probably be made more efficient. I wrote it as I did to make the logic behind it transparent.
  2 个评论
Moritz
Moritz 2012-10-19
Thanks! I adapted it to make it work with vectors and now it works like a charm.
Thank you very much!
P.S.: I'm gonna report it as a bug and see what Mathworks has to say about it.
Star Strider
Star Strider 2012-10-19
Great! I'm glad it worked for you. It is always my pleasure to help.
Please post what TMW replies to your bug report here in a new ‘Answers’ question (use ‘announcement’ as the first tag and then the same tags and products you used here), and include a link to this thread so you don't have to completely re-describe the problem. This seems to me to be a significant issue — and one I hadn't previously discovered — so it merits special attention.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2012-10-18
In the Symbolic Toolbox, the order of operands is treated algebraically, so any subexpression might get rewritten to an equivalent subexpression. For example, x*2*x would get rewritten to 2*x^2. When you replace dx*dy with dy*dx the order might get rewritten arbitrarily.
I do not know the order used by the Symbolic Toolbox. In another package I am familiar with, the order used is the order the operands were first encountered in (or so it used to be; the package added new controls around this in later releases.)

Community Treasure Hunt

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

Start Hunting!

Translated by