Symbolic math- substitute a derivative function for a variable - subs
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Jaskirat
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!