3

Love this site and all the wonderful contributors on it! it has helped me out numerous times, but I can't find what I'm looking for in this instance.

Quick question:

How can I prevent Matlab from automatically 'simplifying' an equation in my matlab m-file?

Example:

Code

syms w l a
V3=(w/(2*l))*(l^2+a^2)

output in command window

V3 =
(w*(a^2 + l^2))/(2*l)

Problem:

The equation V3 is rearranged in its simplest form 'automatically', this makes equations difficult to relate to the referenced equations.

Any help would be much appreciated

Cheers

Amro
  • 123,847
  • 25
  • 243
  • 454
Ben Winding
  • 10,208
  • 4
  • 80
  • 67
  • 1
    Both are exactly same, isn't ? – P0W Sep 03 '13 at 02:58
  • It's the same equation, but written differently. I'm asking if there's a way to prevent Matlab from rearranging the equation. – Ben Winding Sep 03 '13 at 04:28
  • It's probably worth mentioning which version of MATLAB and/or the Symbolic Toolbox you're working with. The internals of the Symbolic Toolbox were swapped out a few years ago. I *assume* that you're working with a version that's new enough to be MuPAD based, but you never can tell... (Sorry, I don't remember at *which* version The MathWorks switched to a MuPAD-based implementation.) – Bob Gilmore Sep 07 '13 at 05:24

2 Answers2

2

You can suppress automatic simplification using

sympref('AbbreviateOutput', false)
0

One way to achieve what you're trying to do would be to use strings and consequentially using the sym() function as illustrated here to convert them to symbolic equations as and when needed.

In doing so, whenever you need to relate to the referenced equations, you can simply compare their string versions which would remain unchanged.

Roney Michael
  • 3,964
  • 5
  • 30
  • 45
  • Cheers for the suggestion. Yes I am defining the equation as a string and converting it to a symbolic equation to use in Matlab. the trouble I'm having is that when I go to display the equation using the latex() function it rearranges itself, often not looking like the desired formula. Is there any way to change this? – Ben Winding Sep 03 '13 at 05:26
  • 1
    @TylerDurden: I'm not sure about that, but you should be able to place strings just as easily on your graphs. – Roney Michael Sep 03 '13 at 06:12