5

This symbolic expression in Matlab

syms x y;
f = x * y * y

returns

f =

x*y^2

How can I stop Matlab from simplifying the expression and let it remain as x * y * y? I'm trying to print the steps of a calculation this way, so reordering the terms causes confusion.

Mohsen Kamrani
  • 7,177
  • 5
  • 42
  • 66
semekh
  • 3,867
  • 2
  • 24
  • 34
  • Can you provide a full (simple) example of the big picture? I mean, are you trying to print the steps in the process of simplifying `f`? If not, why aren't you happy with the expression MATLAB yields? – Eitan T Oct 29 '13 at 18:09
  • @EitanT No, I'm trying to implement a more complicated numerical method (or any algorithm) and I'd like to output some of the expressions generated in those steps, so that a trainee will be able to follow how things are going on. – semekh Oct 29 '13 at 18:49
  • @EitanT I need the order preserved for derivation – Plinth Oct 12 '16 at 18:09

1 Answers1

1

A workaround that I can think of, is something like this:

str = 'f = x * y * y' ;

Then

eval(str);

will perform the operation you want and you can still use str for presenting it.

Chris
  • 460
  • 2
  • 12
  • Is there any way to preserve it after the evaluation? I need to keep variable order for the sake of derivatives. – Plinth Oct 12 '16 at 18:07