problem with reduceDifferentialOrder -> massMatrixForm -> odeFunction

20 vues (au cours des 30 derniers jours)
Carlos Soria-Hoyo
Carlos Soria-Hoyo le 10 Nov 2016
Hello.
I am trying to get the Euler-Lagrange equation for a mechanical system and to integrate them numerically. The code is pasted below.
What I get is an error message from 'odeFunction'
Error using mupadengine/feval (line 163) The parameter 'diff(phi(t), t)' is invalid.
Error in sym/odeFunction (line 118) A = feval(symengine, 'daetools::odeFunction', expr, vars, params{:});
I do not understand this error as, at least explicitly, the derivatives diff(phi(t),t), etc are not present neither in M nor in F.
Thank you. Best regards.
syms R L0 m g real
for s = [R L0 m g]
assume(s>0);
end
syms phi(t)
%phi(t) = (L0-s(t))/R;
urho = [ cos(phi), sin(phi)];
uphi = [-sin(phi), cos(phi)];
ux = sym([1 0]);
uy = sym([0 1]);
syms l2(t)
%
r1 = R*urho + (L0-l2-phi*R)*uphi;
r2 = R*ux - l2*uy;
v1 = diff(r1,t);
v2 = diff(r2,t);
T = sym(1/2)*m*( simplify(v1*v1.'+v2*v2.'));
V = (m*g*r1+m*g*r2)*(uy.');
L = T-V;
eqnizq = simplify(functionalDerivative(L,[phi l2]) );
eqn = eqnizq == 0;
[newEqs, newVars, R] = reduceDifferentialOrder(eqn, [phi(t) l2(t)]);
[M,F] = massMatrixForm(newEqs,newVars);
Mn = odeFunction(M, newVars, m,g,R,L0)
Fn = odeFunction(F, newVars, m,g,R,L0)

Réponses (2)

Mischa Kim
Mischa Kim le 10 Nov 2016
Modifié(e) : Mischa Kim le 10 Nov 2016
Carlos, the Euler-Lagrange tool package does exactly what you need.

Carlos Soria-Hoyo
Carlos Soria-Hoyo le 10 Nov 2016
Thank you for your answer, Mischa.
I already knew the Euler-Lagrange tool package. It is very good, of course. But I am also interested in improving my use of Symbolic Math Toolbox, both for me and my students. And it is not being easy...
Probably odeToVectorField will work better for this case than reduceDifferentialOrder, etc. But, in any case, I would like to understand why Matlab complains about a variable that, apparently, is not among the inputs.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by