2
votes

I have a question about MATLAB symbolic variable substitution which I feel should have an elegant solution but I can't work out the method of how.

I want to substitute one symbolic variable for two symbolic variable in an equation. I have taken the differentiation of a position with respect to time to find the velocity, and then taken the differentiation of the velocity to find the acceleration. Now, I want to substitute something like vel=acc*t into the equation for velocity so as to eliminate the symbolic variable t.

For example

vel_robot=S*acc*t;

and I want it to show;

vel_robot=S*vel

This is a simplified problem of the program I am working on. Basically I need to eliminate t from my answer.

Is there a way to do this in MATLAB? I know I can substitute one symbolic variable with another using vel_robot = subs(vel_robot,acc,vel) but what I want to know is if I can substitute two symbolic variables with another e.g. vel_robot = subs(vel_robot,acc*t,vel) - N.B. Subs doesn't work in this case.

Thank you!

1
It is not exactly safe and you need to worry about order and spacing. But you could give control+H a chance. Or if your answer is simple enough perhaps dividing by acc*t can do the trick. - Dennis Jaheruddin
Unfortunately the program needs to be more generic so I can't use control+H...though it is how it is currently solved :) - user2979365

1 Answers

3
votes

One way to do it is with assumptions and simplification using assume and simplify:

syms S acc t vel
vel_robot=S*acc*t;
assume(vel == acc*t);
vel_robot = simplify(vel_robot)

which returns

vel_robot =

S*vel

Note that vel had to be declared as a symbolic variable here.