I am trying to solve a differential equation using the bvp4c function (using boundary value conditions) but i always get the error "In an assignment A(:) = B, the number of elements in A and B must be the same. " i dont know why this error happens ?
init = bvpinit(linspace(0,2,10),[0 0 0]);
sol = bvp4c(@Kpath1,@bcpath,init);
t = linspace(0,2,100);
BS = deval(sol,t);
plot(t,BS(1,:))
function bv = bcpath(L,R)
bv = [L(1) L(2) L(3)-1.2; R(1)-2 R(2)-2 R(3)-1.2];
end
function dt = Kpath1(~,c)
L = 0.12;
r = 0.1;
WL = 0.25;WR = 0.25;
x = c(1);y = c(2);th = c(3);
dx = (((r*WL)+(r*WR))/2) * cos(th);
dy = (((r*WL)+(r*WR))/2) * sin(th);
dth= ((r*WR)-(r*WL))/L;
dt = [dx;dy;dth];
pose = [x y th];
end
Thanks in advance

 Réponse acceptée

Torsten
Torsten le 24 Avr 2017

0 votes

You need to return a 3x1 vector instead of a 2x3 matrix in "bcpath".
Best wishes
Torsten.

3 commentaires

Moustafa Aboubakr
Moustafa Aboubakr le 24 Avr 2017
Thanks Torsten, the thing is i have a system of 3 equations [x,y,theta] which are a function of time(t), there are boundary conditions at time (t) = 0, [0 0 1.2] and at time (t) = 2,[2 2 1.2] how can this be written in only a 3*1 vector ?
Torsten
Torsten le 24 Avr 2017
Seems you'll have to use "pdepe" instead of "bvp4c".
Best wishes
Torsten.
Moustafa Aboubakr
Moustafa Aboubakr le 24 Avr 2017
Thanks, but i converted the system of equations from dydt,dxdt into dydx ad dtheta/dx and bvp4c worked fine :) I didnt understand the concept of bvp correctly thnaks again

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by