the optimal control i used the command BVP4C but i don't use because generates me a this error
my code is:
function dydx = ex1ode(x,y)
dydx = [y(2)
-2.2727*y(1)+ (-1.1364)*y(2)+(0.0136)*y(3)
(-11)*y(2)+(-40)*y(3)+(1000)*((-1000*y(6))/2*1)
(-2.2727)*y(5),y(4)+((-1.1364)*y(5))+(-11*y(6))
(-1.1364*y(5))+(-40*y(6))];
the other function is
function res = ex1bc(ya,yb)
res = [ ya(1); yb(1)-1
ya(2); yb(2)-10
ya(3); yb(3)-1
ya(4); yb(4)-1
ya(5); yb(5)-1
ya(6); yb(6)-1];
and the principal program is,
clear all
clc
solinit = bvpinit(linspace(0,18,6),[0 0 0 0 0 1])
sol = bvp4c(@ex1ode,@ex1bc,solinit);
x = linspace(0,4);
y = deval(sol,x);
plot(x,y(1,:))
I don't know which the problem
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in ex1ode (line 3)
dydx = [y(2)
Error in bvparguments (line 105)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 130)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
thanks.

 채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 29일
편집: Walter Roberson 2017년 5월 29일

0 개 추천

You have
dydx = [y(2)
-2.2727*y(1)+ (-1.1364)*y(2)+(0.0136)*y(3)
(-11)*y(2)+(-40)*y(3)+(1000)*((-1000*y(6))/2*1)
(-2.2727)*y(5),y(4)+((-1.1364)*y(5))+(-11*y(6))
(-1.1364*y(5))+(-40*y(6))];
Notice that in the fourth line you have
(-2.2727)*y(5),y(4)+((-1.1364)*y(5))+(-11*y(6))
that is a comma between the y(5) and y(4), and it indicates that you are putting a second value horizontally at that location, making two entries on that row but all the other rows have only one entry.
You probably need
dydx = [y(2)
-2.2727*y(1)+ (-1.1364)*y(2)+(0.0136)*y(3)
(-11)*y(2)+(-40)*y(3)+(1000)*((-1000*y(6))/2*1)
(-2.2727)*y(5)
y(4)+((-1.1364)*y(5))+(-11*y(6))
(-1.1364*y(5))+(-40*y(6))];

추가 답변 (1개)

Stefany  Rodriguez
Stefany Rodriguez 2017년 5월 29일
편집: Walter Roberson 2017년 5월 29일

0 개 추천

yes, I have a mistake but i don't know
Error using bvparguments (line 111)
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The boundary condition function BCFUN should return a column vector of length 6.
Error in bvp4c (line 130)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in controloptimo (line 4)
sol = bvp4c(@ex1ode,@ex1bc,solinit);
and my principal code is
clear all
clc
solinit = bvpinit(linspace(0,18,6),[0 0 0 0 0 1])
sol = bvp4c(@ex1ode,@ex1bc,solinit);
x = linspace(0,4);
y = deval(sol,x);
plot(x,y(1,:))
and my functions are equals, his answer I solve my problem but now I have a new problem.

댓글 수: 2

The code
function res = ex1bc(ya,yb)
res = [ ya(1); yb(1)-1
ya(2); yb(2)-10
ya(3); yb(3)-1
ya(4); yb(4)-1
ya(5); yb(5)-1
ya(6); yb(6)-1];
returns a column vector of length 12, but it needs to return a column of length 6.
The length of the column vectors returned by ex1ode and ex1bc need to be the same as the length of the initial condition [0 0 0 0 0 1]
thanks, his answer is correct ;D

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

카테고리

도움말 센터File Exchange에서 Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by