Calculus Variational; code for finding the value of two constants for 2 values of the variable

17 次查看(过去 30 天)
Hello,
I want to write a code for Calculus Variational problem. I have to find the extremals this equation J = $(0->1) [diff(x,t)^2+10*t*x]dt
After the Euler equation, I found x(t) == (5*t^3)/6 + c1*t + c2; but here I didn't suceed in writing the code for calculating c1 and c2 for t=0 and t=1.
Is there a chance for anyone to help me?
Thank you,
% optimal control course
%Example: optimal control problem, min J = $(0->1) [diff(x,t)^2+10*t*x]dt
%boundary conditions: x(0) = 1, x(1)=2;
%dsolve – solve differential equations
%solve – solve algebraic equations
%solve differential equations (Euler – Lagrange equations)
syms x(t)
f = diff(x,t)^2+10*t*x;
G = functionalDerivative(f,x)
%solve differential equations (Euler – Lagrange equations)
syms x(t)
eqns =[ x(t) == (5*t^3)/6 + c1*t + c2];
%solve algebraic equations by applying boundary conditions
syms t0 tf
t0=0
tf=1
SS = solve(eqns);
c1 = SS.c1;
c2 = SS.c2;

回答(2 个)

Paul
Paul 2024-1-20
Boundary conditions can be specified in the call to dsolve
syms x(t)
f = diff(x,t)^2+10*t*x
f(t) = 
eqn = functionalDerivative(f,x) == 0
eqn(t) = 
sol = dsolve(eqn,x(0)==1,x(1)==2)
sol = 
  2 个评论
Dyuman Joshi
Dyuman Joshi 2024-1-22
Hello @Viorica Alina, if this answer solved your problem, please consider accepting the answer.
Accepting the answer indicates that your problem has been solved (which can be helpful to other people in future) and it awards the volunteer with reputation points for helping you.
You can accept only 1 answer for a question, but you can vote for as many answers as you want. Voting an answer also provides reputation points.

请先登录,再进行评论。


Torsten
Torsten 2024-1-20
编辑:Torsten 2024-1-20
I didn't check whether the Euler equation gives x(t) = 5*t^3/6 + c1*t + c2, but if this is the case, you can get c1 and c2 via
syms t c1 c2
x(t) = 5*t^3/6 + c1*t + c2;
eqn1 = x(0)==1;
eqn2 = x(1)==2;
sol = solve([eqn1,eqn2],[c1,c2]);
xsol = subs(x,[c1,c2],[sol.c1,sol.c2])
xsol(t) = 

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by