Please help me solve this issue I am getting a ode23error the code is as follows
function [t,x] = NAviGAtiON()
clc
time=[0 300];
x0=[0;0;0];
[t x]=ode23(@vehicle,time,x0);
plot(x(:,1),x(:,2),'r',Goal(1),Goal(2),'o',Obs1(1),Obsl(2),'x',Obs2(1),Obs2(2),'x')
axis([0 12 0 12])
function dx = vehicle(t,x)
Goal=[10;10];
Obs1=[3;3];
Obs2=[9;9];
KG=30;
Ko=30;
rG=sqrt((Goal(1)-x(1))^2+(Goal(2)-x(2)^2));
FGx=KG*(Goal(1)-x(1))/rG;
FGy=KG*(Goal(2)-x(2))/rG;
ro1=sqrt((Obs1(1)-x(1))^2+(Obs1(2)-x(2)^2));
Fo1x=-Ko*(Obs2(1)-x(1))/ro2^3;
Fo2y=-Ko*(Obs2(2)-x(1))/ro2^3;
Fx=(FGx+Fo1x+Fo2x);
Fy=(FGy+Fo1y+Fo2y);
alpha=atan(Fy/Fx);
v=1;L=2;
if rG<0.05
v=0;
end
K=2;
ph=(k*(alpha-x(3)));
dx=[v*cos(ph)*cos(x(3));v*cos(ph)*sin(x(3));v*sin(ph)/L];
end
end

댓글 수: 2

darova
darova 2020년 4월 8일
Can't run
James Tursa
James Tursa 2020년 4월 8일
Looks like that was supposed to be ro1

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

 채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 8일

0 개 추천

Rahul - when I run your code, I observe the following error
Undefined function or variable 'ro2'.
Error in NAviGAtiON/vehicle (line 23)
Fo1x=-Ko*(Obs2(1)-x(1))/ro2^3;
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode23 (line 112)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in NAviGAtiON (line 7)
[t x]=ode23(@vehicle,time,x0);
If you look closely at the code
ro1=sqrt((Obs1(1)-x(1))^2+(Obs1(2)-x(2)^2));
Fo1x=-Ko*(Obs2(1)-x(1))/ro2^3;
Fo2y=-Ko*(Obs2(2)-x(1))/ro2^3;
ro1 is defined but never used, and the subsequent two lines reference ro2 which has never been defined. So you need to either define ro2 or use ro1 instead. Or do both.
You'll have a similar problem with
Fx=(FGx+Fo1x+Fo2x);
Fy=(FGy+Fo1y+Fo2y);
where Fo2x and fo1y have never been defined. Also you define K=2 but use a lower case 'k' afterwards, Obsl instead of Obs1, etc.

추가 답변 (0개)

카테고리

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

제품

질문:

2020년 4월 8일

댓글:

2020년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by