%% Demonstration of stability of switched systems %% % Example 4.7 from (Lin & Antsaklis, 2022), page 177. %% Unstable systems % Matrices describing two unstable systems are Aa = [1, -100; 10, 1] Ab = [1, 10; -100, 1] eig(Aa) eig(Ab) %% Plotting the vector fields [X1,X2] = meshgrid(-10:2:10,-10:2:10); Fa1 = Aa(1,1)*X1 + Aa(1,2)*X2; Fa2 = Aa(2,1)*X1 + Aa(2,2)*X2; figure(1) quiver(X1,X2,Fa1,Fa2) axis equal Fb1 = Ab(1,1)*X1 + Ab(1,2)*X2; Fb2 = Ab(2,1)*X1 + Ab(2,2)*X2; figure(2) quiver(X1,X2,Fb1,Fb2) axis equal %% Solving for the (stable) state responses of a switched system % Again, the definition of the switched model, including the switching % logic, is provided in the equally named file. sbu = SwitchBetweenUnstable(); % Initial conditions x0 = [1; 1]; q0 = 1; % Time spans tspan = [0, 1]; jspan = [0, 30]; % Specify solver options. config = HybridSolverConfig('AbsTol', 1e-3, 'RelTol', 1e-7); % Compute solution sol = sbu.solve([x0;q0], tspan, jspan, config); %% Plotting the solution of a switched system figure(3) %plotFlows(sol) %plotHybrid(sol) hp = HybridPlotBuilder().plotPhase(sol.select([1,2])) hold on axis equal x1 = (-2:2); plot(x1,-x1) plot(x1,zeros(length(x1))) grid on hold off