MATLAB: Replace expression of variables with an equivalent variable

substitutionSymbolic Math Toolbox

Hi,
how can i get back theta_v instead of omega*t + phi_v?
% Code
clearvars; clc;
syms Vx positive
syms theta_v phi_v
syms omega t positive
theta_v = omega*t + phi_v;
v = Vx*sin(theta_v)
y = diff(v, t)
subs(y,omega*t + phi_v, theta_v)

Best Answer

Your substitution can't work because you defined "theta_v" to be "omega*t + phi_v". So you're just substituting "omega*t + phi_v" for the same thing. If you want to keep "theta_v" then don't define it as "omega*t + phi_v". Keep it as a symbolic function, and substitute in at the end.
>> syms x
>> syms theta_v(t)
>> syms Vx
>> v = Vx*sin(theta_v)
v(t) =
Vx*sin(theta_v(t))
>> y = diff(v, t)
y(t) =
Vx*cos(theta_v(t))*diff(theta_v(t), t)
>> syms omega phi_v
>> subs(y,theta_v, omega*t + phi_v)
ans(t) =
Vx*omega*cos(phi_v + omega*t)