1

Let's say I have a symbolic variable "q" that depends on another symbolic variable "t". This is how I define each symbolic variables.

t= sym('t');
q = sym('q(t)');

And I have an expression that contains this (when I use pretty(expression))

result = blah1* diff(q(t),t) *blah2 

I want to make this particular part a new variable. Let's say "qdot" In the end, I want it to be like this.

result2 = blah1*qdot*blah2

I'm in the process of figuring it out. Thank you in advance.

PiThanacha
  • 11
  • 1

1 Answers1

0

You should use the subs function. Here is how to use it for your particular question

function Rewrite()
t = sym('t');
q = sym('q(t)');

a = sym('a');
blah1 = a^2;
blah2 = t^3;
result1 = blah1*diff(q,t)*blah2;

qDot = sym('qDot');
result2 = subs(result1, diff(q,t), qDot)
% result2 = a^2*qDot*t^3;
end

Note that

result2 = subs(result1, 'diff(q(t),t)', qDot)

and

newMiddle = sym('qDot');
result2 = subs(result1, diff(q,t), newMiddle)

also give the desired result.

Strategy Thinker
  • 343
  • 1
  • 3
  • 15