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

16 views (last 30 days)
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;

Answers (2)

Paul
Paul on 20 Jan 2024
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 Comments
Dyuman Joshi
Dyuman Joshi on 22 Jan 2024
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.

Sign in to comment.


Torsten
Torsten on 20 Jan 2024
Edited: Torsten on 20 Jan 2024
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) = 

Community Treasure Hunt

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

Start Hunting!