MATLAB Answers

Moritz
0

Replace a multiple of two symbolic numbers

Asked by Moritz
on 18 Oct 2012
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

  0 Comments

Sign in to comment.

2 Answers

Answer by Star Strider
on 18 Oct 2012
Edited by Star Strider
on 18 Oct 2012
 Accepted Answer

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 Comments

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.
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.

Sign in to comment.


Answer by Walter Roberson
on 18 Oct 2012

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.)

  0 Comments

Sign in to comment.