MATLAB Answers

PLEASE SOMEONE HELP ME WITH THE ODE23 ERROR

4 views (last 30 days)
Rahul Bhaumik
Rahul Bhaumik on 8 Apr 2020
Commented: Adam Danz on 22 Apr 2020
I am gettting an ode23 error when i run y code please help me solve this issue.
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

  5 Comments

Show 2 older comments
Rahul Bhaumik
Rahul Bhaumik on 8 Apr 2020
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);
Rahul Bhaumik
Rahul Bhaumik on 8 Apr 2020
@Steven Lord, I have fixed all the issues with the code but now the output result is not the one expected.
The vehicle does not reach the final goal in the plot.
The final code and the result are as follows. Kindly find the attachment.
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),Obs1(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;
L=2;
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*(Obs1(1)-x(1))/ro1^3;
Fo1y=-Ko*(Obs1(2)-x(2))/ro1^3;
ro2=sqrt((Obs2(1)-x(1))^2+(Obs2(2)-x(2)^2));
Fo2x=-Ko*(Obs2(1)-x(1))/ro2^3;
Fo2y=-Ko*(Obs2(2)-x(2))/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

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 8 Apr 2020
Nowhere in the code you posted do you define a variable named ro2. On the line before you tried to use ro2 you defined a variable named ro1. Perhaps you meant to use ro1 instead of ro2, or perhaps you intended to define a variable named ro2 instead of one named ro1?

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by