How can I solve the Euler-Lagrange equation in the Symbolic Toolbox 5.3 (R2009b)?

34 views (last 30 days)
Does the Symbolic Toolbox in MATLAB have a function that performs what the function "EulerEquations" in Mathematica does, in order to compute the differential equation obeyed by the integrand of the functional?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Oct 2013
Unfortunately, symbolic functions are not available in R2009b, and this feature was introduced in R2012a. So, you would need to use MuPad.
There is no written function that solves the Euler Lagrange equation in MATLAB. However, one can write a program that does so, since the problem boils down to solving a symbolic ODE, when the integrand of the functional is known, which MuPad can do.
We can do this in two ways:
1) In MuPad
The trick here is that the differentiation is done in steps, where intermediary dependant variables (the function "y(x)" and its first derivative) are substittuted by a dummy variable, then substituted back once the differentiation is performed.
For example in MuPad, for the mass-spring system, one would proceed as follows:
T:=(1/2)*m*diff(x(t),t)^2
V:=(1/2)*k*x(t)^2
L:=T-V
term1:=diff(L|[diff(x(t),t)=xdot],xdot)|[xdot=diff(x(t),t)]
term1d:=diff(term1,t)
term2:=diff(L|[x(t)=p],p)|[p=x(t)]
EulerLagrangeEq:=term2-term1d
sol := ode::solve({EulerLagrangeEq,x(0)=x0,x'(0)=0},x(t))
2) In MATLAB:
You need to create a function that performs the derivative of symbolic function with respect to a dependent variable, e.g with respect to 'y(x)'.
Then, Use that function to define the Euler Lagrange equation and in your tests on different types of Lagrangians.
Here is an exmaple:
function res = diffDepVar(fun,depVar)
syms xx
res = diff(subs(fun,depVar,xx),xx);
res = subs(res,xx,depVar);
end
Then, test it on different types of integrands:
1. Arclength:
syms x y(x)
arcFun = sqrt(1+diff(y,x)^2)
ds = EulerLagrange(arcFun,x,y,diff(y))
ds = simplify(ds)
dsolve(ds) % Specify conditions as needed. See the Documentation.
2. Total energy of a non-forced spring-mass system
syms m k t X(t) A
syms x1 x2 x3
syms KE PE TE L
EulerLagrange = @(fun,x1,x2,x3) diff(diffDepVar(fun,x3),x1) - ...
diffDepVar(fun,x2)
KE = 1/2*m*diff(X,t)^2
PE = 1/2*k*X(t)^2
L = KE - PE
dL = EulerLagrange(L,t,X,diff(X))
DX = diff(X)
dsolve(dL) % Specify conditions as needed. See the Documentation.

More Answers (0)

Products


Release

R2009b

Community Treasure Hunt

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

Start Hunting!