Is it possible to define a 'sym' as the derivative of another 'sym' ? If not, Is there a workaround for that in my script (differential equations)?

3 views (last 30 days)
Hi, I'm trying to solve an Euler-Lagrange differential equation on MATLAB
d/dt(dL/dq')-dL/dq = Q
I defined various relevant 'sym's:
syms r velocity accceleration theta1 theta2 angvel1 angvel2 angaxel1 angaxel2
q = [ r ; theta1 ; theta2 ];
qdot = [ velocity ; angvel1 ; angvel2 ];
qdotaim = [ acceleration ; angaxel1 ; angaxel2 ];
I also created an expression for L(q,qdot), which writing here will just be confusing and unnecessary.
I had no problem of course computing dL/dq and dL/dq'
L_q = [r;r;r];
for i = 1:3
L_q(i) = diff(L, q(i));
end
L_qdot = [r;r;r];
for i = 1:3
L_qdot(i) = diff(L, qdot(i));
end
but now I want the derivative of the latter expression, d/dt(dL/dq').
Is there any way in which I can define the sym "acceleration" as the derivative of "velocity" (and so on with the "angaxel"s and "angvel"s), supposedly through some "third party" sym, say t?
so that MATLAB sees something like (just a guess, sure I don't care what the syntax is as long as it works):
L_qdot_dt(i) = diff(L_qdot(i), t);
and knows that the derivative of "velocity" is "acceleration" ?
In case that's not an option, is there another way to solve my equation?

Answers (1)

Mischa Kim
Mischa Kim on 18 Feb 2015
Edward, it is doable using the functionality of the Symbolic Math toolbox. A bit tricky though. One approach is to define the Lagrangian symbolically with generalized coordinates defined as symbolic variables (for differentiation w.r.t. q and qdot). For the time derivative the symbolic variables need to replaced by symbolic functions.
If it's not all that urgent, there is a toolbox about to be released (within the next couple of days) on File Exchange that does exactly what you are looking for. I'll let you know when it is available.

Community Treasure Hunt

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

Start Hunting!