// Robot_Q1.sce clear function code = dec2baseArray(N, Size, base) code = zeros(1,Size); Nc = N; i = 0; for k = Size-1 : -1 : 0 i = i+1 p = int(Nc/(base^k)) code(i) = p; Nc = Nc - p*(base^k); end // for k endfunction Size = 8 Nmode = 3 Ncombi = Nmode^Size code = zeros(Ncombi, Size); for k = 1:Ncombi code(k,:) = dec2baseArray(k-1, Size, Nmode); end function Xdot = F(t, X, currentmode) // mode 0: virage gauche // mode 1 : tout droit // mode 1 : virage droite M = X(1:2) V = X(3:4) c = 0.1; if (currentmode==0) then Vdot = c*[0 -1; 1 0]*V; elseif (currentmode==1) then Vdot = [0;0]; elseif (currentmode==2) then Vdot = -c*[0 -1; 1 0]*V; end // if Xdot(1:2) = V; Xdot(3:4) = Vdot; endfunction clf code = [2 2 0 2 1 1 2 1]; DT = 10; X0 = [0, 0, 0.1, 0]'; Xstart = X0; Xd = []; td = 0.5 : 0.5 : DT; for iseq = 1 : Size Xsol = ode(Xstart, 0, td, list(F,code(iseq))); Xstart = Xsol(:,$); Xd = [Xd, Xsol]; end //clf; plot(Xd(1,:), Xd(2,:), '-', 'lineWidth', 3); xgrid;