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

42 次查看(过去 30 天)
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?

采纳的回答

MathWorks Support Team
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.

更多回答(0 个)

类别

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

产品


版本

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by