Negative sign produced by “functionalDerivative” – why?
I am asking this question to both get some understanding, but to also provide a possible workaround to a problem that I have seen posted before with no solutions.
I have written some code to determine the equations of motion for a somewhat simple system (in preparation for the analysis of a much more complex system) and have noticed some odd behavior when using the "functionalDerivative" command and am curious is anyone has ideas on why the behavior detailed below occurs.
Background:
The Lagrangian is given by:
The constraint equations are given by:
I have already developed the EOM’s using the method of Lagrange multipliers, and would now like to develop them by simply substituting the constraint equations into the Lagrangian. Note however that is a function of time, therefore is a composite function:
Note that the generalized coordinate is acted on by a non-conservative generalized force, which I account for on the rhs of the equation of motion (line 20).
Initial Attempts
My initial attempts utilized the "diff" command to try and determine the generalized forces and momenta, however I got the following error message for the generalized force for :
"Error using symengine, First argument must not contain functionals"
This makes sense, as "diff" needs a symbolic variable, not a function. Since this failed, I decided to utilize the functionalDerivative command (which coincidently requires much less code and appears to be overall more efficient), as shown in the code below:
syms theta_c(t) theta_hc(t) z_h(t) I_eq I_h m_h k z_hi Q_c f(t)
%setting assumptions
assume(I_eq,’positive’);
assume(I_h,’positive’);
assume(m_h,’positive’);
assume(z_hi,’positive’);
assume(k,’positive’);
%constraint equations
theta_h=theta_c+theta_hc;
g=compose(f,theta_hc);
%Lagrangian
L=0.5*I_eq*diff(theta_c,t)^2+0.5*I_h*diff(theta_h,t)^2+0.5*m_h*diff(z_h,t)^2-0.5*k*(z_hi+z_h)^2;
%substitution
L=subs(L,z_h,g); %note that theta_h substitution occurs automatically
%Equations of Motion
EOM_theta_c=functionalDerivative(L,theta_c) == Q_c;
EOM_theta_hc=functionalDerivative(L,theta_hc) == 0;
%isolating accelerations
theta_c_2dot=isolate(EOM_theta_c,diff(theta_c,t,t));
theta_hc_2dot=isolate(EOM_theta_hc,diff(theta_hc,t,t));
Question
The resulting equations of motion were given by MATLAB as:
When applying the Euler-Lagrange equation by hand the equation for is correct, but the equation for has an incorrect sign for as it should be positive. Checking just the functional derivative gives:
test=functionalDerivative(L,theta_c)
test(t)=
I am confused as to why these terms have a negative sign, as according the standard form of the Euler-Lagrange equation these terms should have a positive sign. Now, in cases where the functional derivative is equal to zero (conservative systems) this negative sign has no bearing on the result as it can simply be divided out. However, as I have shown in my case (non-conservative) this negative sign does have a bearing on the result. Why is this negative sign added when the functional derivative is calculated?
Possible Fix
I have managed to mitigate this behavior by adjusting my code:
%Equations of Motion
EOM_theta_c=-functionalDerivative(L,theta_c) == Q_c;
EOM_theta_hc=-functionalDerivative(L,theta_hc) == 0;
My only worry when moving to a more complex system is if the behavior of the functionalDerivative command will be consistent as far as signs are considered.I am asking this question to both get some understanding, but to also provide a possible workaround to a problem that I have seen posted before with no solutions.
I have written some code to determine the equations of motion for a somewhat simple system (in preparation for the analysis of a much more complex system) and have noticed some odd behavior when using the "functionalDerivative" command and am curious is anyone has ideas on why the behavior detailed below occurs.
Background:
The Lagrangian is given by:
The constraint equations are given by:
I have already developed the EOM’s using the method of Lagrange multipliers, and would now like to develop them by simply substituting the constraint equations into the Lagrangian. Note however that is a function of time, therefore is a composite function:
Note that the generalized coordinate is acted on by a non-conservative generalized force, which I account for on the rhs of the equation of motion (line 20).
Initial Attempts
My initial attempts utilized the "diff" command to try and determine the generalized forces and momenta, however I got the following error message for the generalized force for :
"Error using symengine, First argument must not contain functionals"
This makes sense, as "diff" needs a symbolic variable, not a function. Since this failed, I decided to utilize the functionalDerivative command (which coincidently requires much less code and appears to be overall more efficient), as shown in the code below:
syms theta_c(t) theta_hc(t) z_h(t) I_eq I_h m_h k z_hi Q_c f(t)
%setting assumptions
assume(I_eq,’positive’);
assume(I_h,’positive’);
assume(m_h,’positive’);
assume(z_hi,’positive’);
assume(k,’positive’);
%constraint equations
theta_h=theta_c+theta_hc;
g=compose(f,theta_hc);
%Lagrangian
L=0.5*I_eq*diff(theta_c,t)^2+0.5*I_h*diff(theta_h,t)^2+0.5*m_h*diff(z_h,t)^2-0.5*k*(z_hi+z_h)^2;
%substitution
L=subs(L,z_h,g); %note that theta_h substitution occurs automatically
%Equations of Motion
EOM_theta_c=functionalDerivative(L,theta_c) == Q_c;
EOM_theta_hc=functionalDerivative(L,theta_hc) == 0;
%isolating accelerations
theta_c_2dot=isolate(EOM_theta_c,diff(theta_c,t,t));
theta_hc_2dot=isolate(EOM_theta_hc,diff(theta_hc,t,t));
Question
The resulting equations of motion were given by MATLAB as:
When applying the Euler-Lagrange equation by hand the equation for is correct, but the equation for has an incorrect sign for as it should be positive. Checking just the functional derivative gives:
test=functionalDerivative(L,theta_c)
test(t)=
I am confused as to why these terms have a negative sign, as according the standard form of the Euler-Lagrange equation these terms should have a positive sign. Now, in cases where the functional derivative is equal to zero (conservative systems) this negative sign has no bearing on the result as it can simply be divided out. However, as I have shown in my case (non-conservative) this negative sign does have a bearing on the result. Why is this negative sign added when the functional derivative is calculated?
Possible Fix
I have managed to mitigate this behavior by adjusting my code:
%Equations of Motion
EOM_theta_c=-functionalDerivative(L,theta_c) == Q_c;
EOM_theta_hc=-functionalDerivative(L,theta_hc) == 0;
My only worry when moving to a more complex system is if the behavior of the functionalDerivative command will be consistent as far as signs are considered. I am asking this question to both get some understanding, but to also provide a possible workaround to a problem that I have seen posted before with no solutions.
I have written some code to determine the equations of motion for a somewhat simple system (in preparation for the analysis of a much more complex system) and have noticed some odd behavior when using the "functionalDerivative" command and am curious is anyone has ideas on why the behavior detailed below occurs.
Background:
The Lagrangian is given by:
The constraint equations are given by:
I have already developed the EOM’s using the method of Lagrange multipliers, and would now like to develop them by simply substituting the constraint equations into the Lagrangian. Note however that is a function of time, therefore is a composite function:
Note that the generalized coordinate is acted on by a non-conservative generalized force, which I account for on the rhs of the equation of motion (line 20).
Initial Attempts
My initial attempts utilized the "diff" command to try and determine the generalized forces and momenta, however I got the following error message for the generalized force for :
"Error using symengine, First argument must not contain functionals"
This makes sense, as "diff" needs a symbolic variable, not a function. Since this failed, I decided to utilize the functionalDerivative command (which coincidently requires much less code and appears to be overall more efficient), as shown in the code below:
syms theta_c(t) theta_hc(t) z_h(t) I_eq I_h m_h k z_hi Q_c f(t)
%setting assumptions
assume(I_eq,’positive’);
assume(I_h,’positive’);
assume(m_h,’positive’);
assume(z_hi,’positive’);
assume(k,’positive’);
%constraint equations
theta_h=theta_c+theta_hc;
g=compose(f,theta_hc);
%Lagrangian
L=0.5*I_eq*diff(theta_c,t)^2+0.5*I_h*diff(theta_h,t)^2+0.5*m_h*diff(z_h,t)^2-0.5*k*(z_hi+z_h)^2;
%substitution
L=subs(L,z_h,g); %note that theta_h substitution occurs automatically
%Equations of Motion
EOM_theta_c=functionalDerivative(L,theta_c) == Q_c;
EOM_theta_hc=functionalDerivative(L,theta_hc) == 0;
%isolating accelerations
theta_c_2dot=isolate(EOM_theta_c,diff(theta_c,t,t));
theta_hc_2dot=isolate(EOM_theta_hc,diff(theta_hc,t,t));
Question
The resulting equations of motion were given by MATLAB as:
When applying the Euler-Lagrange equation by hand the equation for is correct, but the equation for has an incorrect sign for as it should be positive. Checking just the functional derivative gives:
test=functionalDerivative(L,theta_c)
test(t)=
I am confused as to why these terms have a negative sign, as according the standard form of the Euler-Lagrange equation these terms should have a positive sign. Now, in cases where the functional derivative is equal to zero (conservative systems) this negative sign has no bearing on the result as it can simply be divided out. However, as I have shown in my case (non-conservative) this negative sign does have a bearing on the result. Why is this negative sign added when the functional derivative is calculated?
Possible Fix
I have managed to mitigate this behavior by adjusting my code:
%Equations of Motion
EOM_theta_c=-functionalDerivative(L,theta_c) == Q_c;
EOM_theta_hc=-functionalDerivative(L,theta_hc) == 0;
My only worry when moving to a more complex system is if the behavior of the functionalDerivative command will be consistent as far as signs are considered. lagrangian, functional derivative, composite functions MATLAB Answers — New Questions