Why " The boundary condition function BCFUN should return a column vector of length 5" error message is came?

조회 수: 10 (최근 30일)
% function Y6
solinit = bvpinit(linspace(0,1),[0;3;1;1],2);
sol = bvp4c(@ode, @bc, solinit);
Error using bvparguments
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The boundary condition function BCFUN should return a column vector of length 5.

Error in bvp4c (line 122)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
y = sol.y;
time = sol.parameters*sol.x;
ut = -y(4,:);
figure(1);
plot(time,y([1 2],:)','-'); hold on;
plot(time, ut, 'k:');
axis([0 time(1,end) -1.5 3]);
text(1.3,2.5,'x_1(t)');
text(1.3,.9,'x_2(t)');
text(1.3,-.5,'u(t)');
xlabel('time');
ylabel('states');
title('Numerical solution');
hold off;
% -------------------------------------------------------------------------
% ODE's of augmented states
function dydt = ode(t,y,T)
dydt = T*[2*y(2);4*y(4);0;-2*y(3)];
end
% -------------------------------------------------------------------------
% boundary conditions: x1(0)=11;p2(0)=2; x2(tf)=3; 3*p1(tf)+p2(2)^2=0
function res = bc(ya,yb,T)
res = [ ya(1) - 11; ya(4); yb(2) - 3; 3*yb(3)+yb(4)^2];
end

채택된 답변

Jan
Jan 2022년 11월 14일
You provide an extra parameter:
solinit = bvpinit(linspace(0,1),[0;3;1;1],2);
% ^ here
But there is no condition for this parameter in bc().
  댓글 수: 4
Tu
Tu 2022년 11월 16일
편집: Tu 2022년 11월 16일
yes, i want to find U_optimal through numerical method of this problem. but i don''t know how to find it! can you help me please. U is a function of variable t u=u(t)
Jan
Jan 2022년 11월 16일
This not trivial. If you do not know, which function u is, there is an infinite number of possible solutions. This is an optimization problem and not a simple BVP.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2022년 11월 16일
편집: Torsten 2022년 11월 16일
Choose a grid
0=t0 < t1 < ... < tn = tf
With each grid point, associate a value ui of your control function u (the ui are your solution variables for the optimization problem).
Call fmincon with initial values for the ui.
Within the objective function for fmincon, solve the boundary value problem from above with the given vector u (e.g. using bvp4c or your own ODE solver for this simple boundary value problem) and return the value for J to the optimizer. The integral can be approximated by the trapezoidal rule, e.g.
Maybe the YouTube video is of help:
  댓글 수: 3
Torsten
Torsten 2022년 11월 16일
I described the steps you have to follow and even gave a link to a video where everything is described in detail. This is all I can do for you - the task is not a "one-liner".

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by