How can I solve symbolic Lagrange equations of motion numerically?

26 次查看(过去 30 天)
I made a code to obtain the system of Lagrange equations of motion in symbolic form. Now I want to solve it, but the system is huge, so I need to solve it numerically. Here's the code
if true
function fout = deriv(f, g)
% deriv differentiates f with respect to g=g(t)
% the variable g=g(t) is a function of time
b = sym('b');
f1 = subs(f, g, b);
f2 = diff(f1, b);
fout = subs(f2, b, g);
x=sym('x(t)');
tettapl=sym('tettapl(t)');
tettal1=sym('tettal1(t)');
tettal2=sym('tettal2(t)');
%Here is the calculation of the Kinetic and Potential energies
eqn1=diff(deriv(K,diff(x)))-deriv(K,x)+deriv(P,x)
eqn2=diff(deriv(K,diff(tettapl)))-deriv(K,tettapl)+deriv(P,tettapl)
eqn3=diff(deriv(K,diff(tettal1)))-deriv(K,tettal1)+deriv(P,tettal1)-diff(tettal1)
eqn4=diff(deriv(K,diff(tettal2)))-deriv(K,tettal2)+deriv(P,tettal2)-diff(tettal2)
end
I tried to use
if true
V=odeToVectorField(eqn1,eqn2,eqn3,eqn4)
end
but got:
if true
Error using symengine (line 58)
Could not extract the differential variables. Try using symbolic functions in contrast to ordinary symbolic objects as dependent ODE variables.
end
How can I define variables so Matlab can see derivatives?

回答(1 个)

Mischa Kim
Mischa Kim 2016-4-1
Hi Alexander, check out the Euler-Lagrange tool package.

类别

Help CenterFile Exchange 中查找有关 Assembly 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by