Symbolic math- substitute a derivative function for a variable - subs

조회 수: 2 (최근 30일)
Mario Miralles Delgado
Mario Miralles Delgado 2017년 5월 18일
답변: Jaskirat 2025년 1월 29일
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?

답변 (1개)

Jaskirat
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 :

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by