how to use loops and ode solver
Show older comments
I using two control inputs multiple times against certain condition to drive the states to zero in a certain order.i know that i need to use loops to achieve this but am totally lost.any help would be greatly appreciated. My code is as below.
function xdot=njc(t,x)
k1=1;
k2=1.5;
k3=1.5;
b1=0.5;
b2=0.6;
b3=0.75;
%Step 1. Drive the system to a nonzero equilibrium such that tan(x4) =/ 0 in finite time using
uu(1)=0;
uu(2)=-k1*(abs(x(4)-4)).^b1*sign(x(4)-4)-k2*(abs(x(5))).^b2*sign(x(5))-k3*(abs(x(6))).^b3*sign(x(6));
uu=[uu(1);uu(2)];
%Step 2. (After step 1 completes)Drive the x7 variable to zero while keeping x4 = 4 using
if x(4)==4
uu(1)=-1/tan(4)*(k1*(abs(x(7))).^b1*sign(x(7))+k2*(abs(x(8))).^b2*sign(x(8))+k3*(abs(x(9))).^b3*sign(x(9)));
uu(2)=-k1*(abs(x(4)-4)).^b1*sign(x(4)-4)-k2*(abs(x(5))).^b2*sign(x(5))-k3*(abs(x(6))).^b3*sign(x(6));
uu=[uu(1);uu(2)];
end
% % Step 3.(After step 2 completes) Drive the x4 variable to zero while keeping x7 = 0 using
if x(7)<=0.0005
uu(1)=-k1*(abs(x(7))).^b1*sign(x(7))-k2*(abs(x(8))).^b2*sign(x(8))-k3*(abs(x(9))).^b3*sign(x(9));
uu(2)=-k1*(abs(x(4))).^b1*sign(x(4))-k2*(abs(x(5))).^b2*sign(x(5))-k3*(abs(x(6))).^b3*sign(x(6));
uu=[uu(1);uu(2)];
end
% % Step 4. (After step 3 completes)Drive the x1 variable to zero while keeping x4 = 0 using
if x(4)<=0.002
uu(1)=-k1*(abs(x(1))).^b1*sign(x(1))-k2*(abs(x(2))).^b2*sign(x(2))-k3*(abs(x(3))).^b3*sign(x(3));
uu(2)=-k1*(abs(x(4))).^b1*sign(x(4))-k2*(abs(x(5))).^b2*sign(x(5))-k3*(abs(x(6))).^b3*sign(x(6));
uu=[uu(1);uu(2)];
end
xdot(1)=x(2);
xdot(2)=x(3);
xdot(3)=uu(1);
xdot(4)=x(5);
xdot(5)=x(6);
xdot(6)=uu(2);
xdot(7)=x(8);
xdot(8)=x(9);
xdot(9)=uu(1)*tan(x(4));
xdot=xdot';
Answers (0)
Categories
Find more on Ordinary Differential Equations 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!