Symbolic math- substitute a derivative function for a variable - subs
2 views (last 30 days)
Show older comments
I want to substitute in the following matrix result: A=[diff(theta(t),t) -diff(psi(t),t) -diff(theta(t),t) diff(psi(t),t)] I want to substitute diff(theta(t),t) for a variable called thetap and diff(psi(t),t) for a variable called psip in orden to obtain the following matrix A=[thetap -psip -thetap psip]
then I tried to do this:
theta2 = sym('theta2(t)') psi2 = sym('psi2(t)'
A=[diff(theta(t),t) -diff(psi(t),t) -diff(theta(t),t) diff(psi(t),t)]
dtheta = diff(theta,t) dpsi = diff(psi,t)
Ap_s = subs(A,{dtheta,dpsi},{thetap,psip})
but it doesn't work. It returns again the dependent expression diff(theta(t),t) and diff(psi(t),t) without doing the substitution. I've tried: Ap_s = subs(A,{diff(theta(t),t),diff(psi(t),t)},{thetap,psip}) but it doesn't work. Can anybody help me?
0 Comments
Answers (1)
Jaskirat
on 29 Jan 2025
I see that you are using the “subs” function of the Symbolic Math Toolbox from MATLAB.
The given substitution of differential expressions in a matrix with other symbols can be achieved by using “subs” and “str2sym”.
Here is an example code which shows the process of substitution-
syms theta(t) t psi(t)
A=[diff(theta(t),t) -diff(psi(t),t); -diff(theta(t),t) diff(psi(t),t)]
subs(A,[str2sym("diff(theta(t),t)"),str2sym("diff(psi(t),t)")],[str2sym('theta2(t)'),str2sym('psi2(t)')])
The following documentation links can be referred to get more information about “subs” function :
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!