Symbolic math- substitute a derivative function for a variable - subs
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Jaskirat
2025-1-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!