How to stop MatLab from automatically substituting in variables?

Hello everyone,
I am wondering how I can get Matlab to not automatically substitute in for the variables in the expressions that follow. For instance, if I wrote this code
syms R w rho
volume = pi * R^2 * w
m= rho * volume
I = (1/2)*m*R^2 + m*e^2
Matlab gives me the following outputs:
volume = pi * R^2 * w
m = pi * R^2 * w * rho
I = (rho * w *pi * R^4)/2 + etcetera
What I want is to have the outputs in terms of the variables that came before them, instead of substituting for the base variables.
So for m I would want it to visually display m = rho * volume, instead of plugging in all the individual variables from the volume equation.
Thank you,

 Accepted Answer

To have the output in terms of volume, you may declare volume as a symbolic variable and define it after defining m.
syms R w rho volume
m = rho * volume
volume = pi * R^2 * w

More Answers (0)

Categories

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!