Calculus Variational; code for finding the value of two constants for 2 values of the variable
조회 수: 16 (최근 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;
댓글 수: 0
답변 (2개)
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
eqn = functionalDerivative(f,x) == 0
sol = dsolve(eqn,x(0)==1,x(1)==2)
댓글 수: 2
Dyuman Joshi
2024년 1월 22일
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
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])
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!