how do i correct this error in command bvp4c?

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.

 Accepted Answer

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))];

More Answers (1)

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 Comments

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

Sign in to comment.

Categories

Find more on Optimization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!