├── ADP code.zip ├── Adaptive dynamic programming ├── IRL.zip └── Readme ├── Application ├── Bidram coop ctrl AC microgrid.zip ├── game theory ctrl in DC microgrid.zip └── readme ├── Bidram coop ctrl AC microgrid.zip ├── CT graph games.zip ├── DT GG Q.zip ├── DT GG.zip ├── README.md ├── Robust ADP ├── Robust-ADP ├── Chapter2_Example1 │ ├── Ch2Ex1_main.m │ ├── LinearADPSimullink_R2014b.slx │ ├── LinearADPSimullink_R2015a.slx │ ├── LinearADPSimullink_R2015b.slx │ └── devel │ │ ├── Ch2_ex1_fig2_x.eps │ │ ├── LinearADPSimullink__new.slx │ │ ├── plotK.m │ │ └── plotX.m ├── Chapter2_Example2 │ ├── Ch2Ex2_main.m │ ├── README.md │ ├── aug_sys.m │ └── html │ │ ├── RADP_Ch2Ex2.zip │ │ ├── RADP_Ch2Ex2_main.html │ │ ├── RADP_Ch2Ex2_main.png │ │ ├── RADP_Ch2Ex2_main_01.png │ │ ├── RADP_Ch2Ex2_main_02.png │ │ └── RADP_Ch2Ex2_main_03.png ├── Chapter3_Example1 │ ├── Ch3Ex1_main.m │ ├── Phi_fun.m │ ├── Psi_fun.m │ ├── adpSysWrapper.m │ ├── getRegionOfAttraction.m │ ├── isInRegionOfAttraction.m │ ├── simFigures │ │ ├── Ch3_ex1_fig1_x.eps │ │ ├── Ch3_ex1_fig2_v.eps │ │ └── Ch3_ex1_fig3_Omega.eps │ ├── simResults │ │ └── simResults.mat │ ├── simpleSysWrapper.m │ ├── susp_sys.m │ ├── temp │ │ ├── NNADP_susp.m │ │ ├── mdlCoeff.m │ │ ├── susp_sys_linear.m │ │ └── tester.m │ └── test.mat ├── Chapter4_Example1 │ ├── Ch4Ex1_main.m │ └── figures │ │ ├── Ch4_Ex1_V.pdf │ │ ├── Ch4_Ex1_x.eps │ │ ├── Ch4_Ex1_x.jpg │ │ ├── Ch4_Ex1_x.pdf │ │ └── x.fig ├── Chapter4_Example2 │ ├── Ch4Ex2_main.m │ ├── ExplorationNoise.m │ ├── SystemWrapper.m │ ├── devel │ │ ├── GADP_offline_validation.m │ │ └── prepareFigure.m │ ├── figures │ │ ├── Ch4_Ex2_control.pdf │ │ ├── Ch4_Ex2_control_curve.pdf │ │ ├── Ch4_Ex2_cost.pdf │ │ └── Ch4_Ex2_state.pdf │ └── html │ │ ├── Ch4Ex2_main.html │ │ ├── Ch4Ex2_main.png │ │ ├── Ch4Ex2_main_01.png │ │ ├── Ch4Ex2_main_02.png │ │ ├── Ch4Ex2_main_03.png │ │ └── Ch4Ex2_main_04.png ├── Chapter4_Example3 │ ├── BasisPlanMono.m │ ├── BasisQuadPhiX.m │ ├── BasisQuadPlantMono.m │ ├── Ch4Ex3_main.m │ ├── ExplNoise.m │ ├── FTSys.m │ ├── FTSystemWrapper.m │ ├── figures │ │ ├── Ch4_Ex3_V.pdf │ │ ├── Ch4_Ex3_u.pdf │ │ └── Ch4_Ex3_x.pdf │ └── html │ │ ├── Ch4Ex3_main.html │ │ ├── Ch4Ex3_main.png │ │ ├── Ch4Ex3_main_01.png │ │ ├── Ch4Ex3_main_02.png │ │ └── Ch4Ex3_main_03.png ├── Chapter4_Example4 │ ├── Ch4Ex4_main.m │ └── figures │ │ ├── Ch4_Ex4_V.pdf │ │ └── Ch4_Ex4_x.pdf ├── Chapter5_Example1 │ ├── Ch5Ex1_main.m │ ├── createAnimation.m │ ├── devel │ │ └── utCreateAnimation.m │ ├── figures │ │ ├── Ch5_fig_ani.eps │ │ ├── Ch5_fig_delta.eps │ │ └── Ch5_fig_w.eps │ ├── html │ │ ├── Ch5Ex1_main.html │ │ ├── Ch5Ex1_main.png │ │ ├── Ch5Ex1_main_01.png │ │ ├── Ch5Ex1_main_02.png │ │ ├── Ch5Ex1_main_03.png │ │ └── Ch5Ex1_main_04.png │ ├── paramMgr.m │ └── syncMachine.m ├── Chapter5_Example2 │ ├── Ch5Ex2_main.m │ ├── control_anno.m │ ├── figures │ │ ├── Ch5_Ex2_cost.eps │ │ ├── Ch5_Ex2_phi.eps │ │ ├── Ch5_Ex2_r.eps │ │ └── Ch5_Ex2_u_curve.eps │ ├── polysys.m │ ├── polysys0.m │ └── state_anno.m ├── Chapter6_Example1 │ ├── Ch6Ex1_main.m │ ├── figures │ │ ├── Ch6_Ex1_Angle.eps │ │ ├── Ch6_Ex1_Angle.pdf │ │ ├── Ch6_Ex1_Freq.eps │ │ └── Ch6_Ex1_Freq.pdf │ ├── html │ │ ├── RADP_MultiMachine.html │ │ ├── RADP_MultiMachine.png │ │ ├── RADP_MultiMachine_01.png │ │ ├── RADP_MultiMachine_02.png │ │ ├── RADP_MultiMachine_03.png │ │ ├── RADP_MultiMachine_04.png │ │ ├── RADP_MultiMachine_05.png │ │ └── RADP_MultiMachine_06.png │ └── temp │ │ └── LinearADPSimullink__new.slx ├── Chapter7_Example1 │ ├── AbstractSimulator.m │ ├── Ch7Ex1_main.m │ ├── DFSimulator.m │ ├── VFSimulator.m │ └── figures │ │ ├── Ch7_DFStiffness.eps │ │ ├── Ch7_VFStiffness.eps │ │ ├── Ch8_ADP_DFMoveTraj.eps │ │ ├── Ch8_ADP_DFStiffness.eps │ │ ├── Ch8_ADP_DFTimeCourse.eps │ │ ├── Ch8_ADP_Fitts.eps │ │ ├── Ch8_ADP_VFMoveTraj.eps │ │ ├── Ch8_ADP_VFStiffness.eps │ │ └── Ch8_ADP_VFTimeCourse.eps ├── Chapter7_Example2 │ ├── Ch7Ex2_main.m │ ├── LocalSDESolver.m │ ├── Motor2D.m │ ├── draw_bg.m │ ├── filledCircle.m │ ├── html │ │ ├── Ch7Ex2_main.html │ │ ├── Ch7Ex2_main.png │ │ ├── Ch7Ex2_main_01.png │ │ ├── Ch7Ex2_main_02.png │ │ ├── Ch7Ex2_main_03.png │ │ ├── Ch7Ex2_main_04.png │ │ ├── Ch7Ex2_main_05.png │ │ ├── Ch7Ex2_main_06.png │ │ └── Ch7Ex2_main_07.png │ ├── old │ │ ├── draw_bg.m │ │ ├── filledCircle.m │ │ ├── main.m │ │ ├── ode_yu_AE.m │ │ ├── ode_yu_AL.m │ │ ├── ode_yu_NF.m │ │ ├── ode_yu_VF.m │ │ ├── para.m │ │ ├── para2.m │ │ ├── timecourse_AE.m │ │ ├── timecourse_AL.m │ │ ├── timecourse_NF.m │ │ └── timecourse_VF.m │ └── plotTimecourse.m ├── Readme ├── publishandpack.m └── tRADP_Examples.m ├── code MAK HJB.zip ├── code MAK HJI.zip ├── constrained input ├── Readme ├── code MAK HJB.zip └── code MAK HJI.zip ├── cooperative game ├── Cooperative game.rar └── readme ├── experience replay ├── concurrent learning_.zip └── readme ├── game theory ctrl in DC microgrid.zip ├── multi-agent game ├── CT graph games.zip ├── DT GG Q.zip ├── DT GG.zip ├── game theory ctrl in DC microgrid.zip └── readme ├── nonzero-sum game ├── nonlinear.rar ├── readme └── 连续linear system.rar ├── online synch Hinf.zip ├── online synch opt ctrl.zip └── zero-sum game ├── Readme ├── code MAK HJI.zip └── online synch Hinf.zip /ADP code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/ADP code.zip -------------------------------------------------------------------------------- /Adaptive dynamic programming/IRL.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Adaptive dynamic programming/IRL.zip -------------------------------------------------------------------------------- /Adaptive dynamic programming/Readme: -------------------------------------------------------------------------------- 1 | Frank L. Lewis 2 | -------------------------------------------------------------------------------- /Application/Bidram coop ctrl AC microgrid.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Application/Bidram coop ctrl AC microgrid.zip -------------------------------------------------------------------------------- /Application/game theory ctrl in DC microgrid.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Application/game theory ctrl in DC microgrid.zip -------------------------------------------------------------------------------- /Application/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Bidram coop ctrl AC microgrid.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Bidram coop ctrl AC microgrid.zip -------------------------------------------------------------------------------- /CT graph games.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/CT graph games.zip -------------------------------------------------------------------------------- /DT GG Q.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/DT GG Q.zip -------------------------------------------------------------------------------- /DT GG.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/DT GG.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Collected-ADP-algorithm 2 | 3 | 1. This code is from http://www.uta.edu/utari/acs/code/Software%20from%20Research.htm. 4 | 5 | Software Related to Funded Research of F.L. Lewis 6 | 7 | 8 | This Software was developed under Research Sponsored by: 9 | 10 | National Science Foundation 11 | Army Research Office, National Automotive Center, TARDEC 12 | US Air Force Office of Scientific Research, Office of Naval Research 13 | 14 | 15 | This software is not supported. If you have trouble making it work, please figure it out yourself. The methods are explained in the papers. 16 | 17 | 18 | 19 | 2. Robust Code is from http://yu-jiang.github.io/radpbook/ 20 | 21 | The first author (Yu Jiang) is a Software Engineer with the Controls Toolbox Team at MathWorks, and most likely will hold the same position at the time the book is published. However, it should be noted that this book is not sponsered by MathWorks. It is entirely based on the papers submitted and/or published during Yu's PhD at the New York University. The MATLAB/Simulink-based simulations were originally created during that period. Hence, they are not products of MathWorks, and do not contain any intellectual property of the company. -- Yu Jiang (12/4/2016). . 22 | -------------------------------------------------------------------------------- /Robust ADP: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example1/Ch2Ex1_main.m: -------------------------------------------------------------------------------- 1 | %% A Simulink model that implements the linear ADP algorithm 2 | % 3 | % This example shows how to implement the linear ADP algorithm in Simulink. 4 | % The plant dynamics are not known to the controller, yet the controller 5 | % learns the optimal performance via real-time data. 6 | % 7 | % Copyright 2016 Yu Jiang 8 | 9 | %% Check your MATLAB version 10 | mlver = ver('MATLAB'); 11 | rlStr = mlver.Release(5:7); % Get release number 12 | if ismember(rlStr, {'14b', '15a', '15b'}); 13 | mdl = ['LinearADPSimullink_R20', rlStr]; 14 | else 15 | error('The example is only supported in MATLAB R2014b--R2015b') 16 | end 17 | 18 | %% Open the model 19 | open_system(mdl); 20 | 21 | %% Simulate the system 22 | % 23 | sim(mdl); 24 | %% Clean up 25 | close_system(mdl,0); -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example1/LinearADPSimullink_R2014b.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter2_Example1/LinearADPSimullink_R2014b.slx -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example1/LinearADPSimullink_R2015a.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter2_Example1/LinearADPSimullink_R2015a.slx -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example1/LinearADPSimullink_R2015b.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter2_Example1/LinearADPSimullink_R2015b.slx -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example1/devel/LinearADPSimullink__new.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter2_Example1/devel/LinearADPSimullink__new.slx -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example1/devel/plotK.m: -------------------------------------------------------------------------------- 1 | % Plot P 2 | 3 | a = getElement(logsout, 'Kdata'); 4 | t = squeeze(a.Values.time); 5 | K = squeeze(a.Values.data); 6 | 7 | plot(t, K(1,:), '-', ... 8 | t, K(2,:), '-.',... 9 | t, K(3,:), ':', ... 10 | 'LineWidth', 2) 11 | 12 | legend('K_1', 'K_2', 'K_3') 13 | 14 | xlabel('Time (sec)') 15 | 16 | %% 17 | print('Ch2_ex1_fig3_K', '-depsc') -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example1/devel/plotX.m: -------------------------------------------------------------------------------- 1 | % Plot X 2 | 3 | t = ScopeData.time; 4 | x = ScopeData.signals.values; 5 | 6 | plot(t, x(:,1), '-', ... 7 | t, x(:,2), '-.',... 8 | t, x(:,3), ':', ... 9 | 'LineWidth', 2) 10 | 11 | legend('x_1', 'x_2', 'x_3') 12 | 13 | xlabel('Time (sec)') 14 | 15 | annotation(gcf,'textarrow',[0.310714285714285 0.223214285714285],... 16 | [0.753761904761908 0.719047619047623],'String',{'First Iteration'}); 17 | 18 | % Create textarrow 19 | annotation(gcf,'textarrow',[0.266071428571429 0.224999999999999],... 20 | [0.564285714285715 0.51428571428572],'String',{'First Iteration'}); 21 | 22 | % Create textarrow 23 | annotation(gcf,'textarrow',[0.280357142857143 0.237499999999998],... 24 | [0.276190476190476 0.326190476190481],'String',{'First Iteration'}); 25 | 26 | % Create textarrow 27 | annotation(gcf,'textarrow',[0.683928571428571 0.639285714285714],... 28 | [0.576190476190476 0.473809523809525],'String',{'Last Iteration'}); 29 | 30 | 31 | %% 32 | print('Ch2_ex1_fig2_x', '-depsc') -------------------------------------------------------------------------------- /Robust-ADP/Chapter2_Example2/Ch2Ex2_main.m: -------------------------------------------------------------------------------- 1 | %% Off-policy learning for a turbocharged diesel engine 2 | % This is the Numerical Example 2.2 in Chapter 2 of book 3 | % Robust Adaptive Dynamic Programming 4 | % by Yu Jiang and Zhong-Ping Jiang 5 | 6 | %% Parameters configuration 7 | xn = 6; 8 | un = 2; 9 | 10 | % Set the weighting matrices for the cost function 11 | Q = diag([100 0 0 0 0 100]); 12 | R = diag([1 1]); 13 | 14 | % Initialize the feedback gain matrix 15 | Kinit = zeros(un,xn); %Only if A is Hurwitz, K can be set as zero. 16 | K = Kinit; 17 | N = 100; %Length of the window, should be at least xn^2+2*xn*un 18 | MaxIteration = 10; %Max iteration times 19 | T = 0.01; %Length of each integration interval 20 | 21 | x0 = [20;5;10;2;-1;-2]; %Initial condition 22 | 23 | expl_noise_freq = (rand(un,100)-.5)*100; % Exploration noise frequencies 24 | 25 | % Matrices to collect online data and perform learning 26 | Dxx=[]; 27 | Ixx=[]; 28 | Ixu=[]; 29 | 30 | % Initial condition of the augmented system 31 | X=[x0;kron(x0',x0')';kron(x0,zeros(un,1))]'; 32 | 33 | %% Run the simulation and obtain the data matrices \delta_{xx}, 34 | %I_{xx}, and I_{xu} 35 | 36 | ifLearned = 0; 37 | 38 | x_save=[]; 39 | t_save=[]; 40 | 41 | for i=1:N 42 | % Simulation the system and at the same time collect online info. 43 | [t,X] = ode45(@(t,x)aug_sys(t,x,K,ifLearned,expl_noise_freq), ... 44 | [(i-1)*T,i*T],X(end,:)); 45 | 46 | %Append new data to the data matrices 47 | Dxx=[Dxx;kron(X(end,1:xn),X(end,1:xn))-kron(X(1,1:xn),X(1,1:xn))]; 48 | Ixx=[Ixx;X(end,xn+1:xn+xn^2)-X(1,xn+1:xn+xn^2)]; 49 | Ixu=[Ixu;X(end,xn+xn^2+1:end)-X(1,xn+xn^2+1:end)]; 50 | 51 | % Keep track of the system trajectories 52 | x_save=[x_save;X]; 53 | t_save=[t_save;t]; 54 | end 55 | 56 | ifLearned = 1; % Mark learning finished 57 | 58 | P_old = zeros(xn); 59 | P = eye(xn)*10; % Initialize the previous cost matrix 60 | it = 0; % Counter for iterations 61 | p_save = []; % Track the cost matrices in all the iterations 62 | k_save = []; % Track the feedback gain matrix in each iterations 63 | 64 | % The system matrices are copied here only for the purpose of analyzing the 65 | % results 66 | A = [-0.4125 -0.0248 0.0741 0.0089 0 0; 67 | 101.5873 -7.2651 2.7608 2.8068 0 0; 68 | 0.0704 0.0085 -0.0741 -0.0089 0 0.0200; 69 | 0.0878 0.2672 0 -0.3674 0.0044 0.3962; 70 | -1.8414 0.0990 0 0 -0.0343 -0.0330; 71 | 0 0 0 -359 187.5364 -87.0316]; 72 | 73 | B = [-0.0042 0.0064 74 | -1.0360 1.5849 75 | 0.0042 0; 76 | 0.1261 0; 77 | 0 -0.0168; 78 | 0 0]; 79 | 80 | [Kopt,Popt] = lqr(A,B,Q,R); % Calculate the ideal solution for comparion purpose 81 | k_save = norm(K-Kopt); % keep track of the differences between the actual K 82 | % and the idea valu 83 | 84 | %% Off-policy learning using the collected online data 85 | while norm(P-P_old)>1e-8 & it 31 | PsiPsi = [PsiPsi; 32 | X(end,4 + (1:PsiLength^2))]; %#ok 33 | PsiU = [PsiU; 34 | X(end,4 + PsiLength^2 + (1:PsiLength))]; %#ok 35 | CostQ = [CostQ; 36 | X(end,end)]; %#ok 37 | t_save = [t_save; 38 | t(:)]; %#ok 39 | x_save = [x_save; 40 | X(:,1:4)]; %#ok 41 | currentTime = t_save(end); 42 | end 43 | 44 | % Off-Policy Learning. Solve the matrix A*pw = B 45 | 46 | w = zeros(PsiLength,1); 47 | 48 | for i = 1:IterMax 49 | A = [Phi -2*r*PsiU-2*r*PsiPsi*kron(w,eye(PsiLength))]; 50 | % Note: To be consistent with the notations in (Y Jiang & ZP Jiang, 51 | % TNNLS 2014), the above line should be replaced with 52 | % A = [Phi 2*r*PsiU-2*r*PsiPsi*kron(w,eye(PsiLength))]; 53 | % i.e., consider u = w'*phi, not u = -w'*psi 54 | % In that case, the simpleSysWrapper should be called as 55 | % >> simpleSysWrapper(t,x,-w) 56 | B = -(CostQ + PsiPsi*kron(w,w)); 57 | pw = A\B; 58 | p = pw(1:PhiLength); 59 | w = pw(PhiLength+1:end); 60 | if i == 1 61 | p0 = p; % save the initial value function 62 | else 63 | if norm(p-pp) <= 0.01 64 | Iter = i; 65 | break 66 | end 67 | end 68 | pp = p; %save the previous p for convergence check 69 | end 70 | 71 | %% Post learning 72 | % Terminate exploration noise but keep appying the inital gains until the 73 | % states enters the region of attraction 74 | 75 | % Compute the region of attraction 76 | D = getRegionOfAttraction(p); 77 | % Keep checking if state is in the region of attraction 78 | currentStates = x_save(end,:); 79 | while ~isInRegionOfAttraction(currentStates,p,D); 80 | [t,y] = ode45(@(t,x) simpleSysWrapper(t,x,w*0), ... 81 | currentTime+[0,0.1], ... 82 | currentStates); 83 | t_save = [t_save; t]; 84 | x_save = [x_save; y]; 85 | currentStates = x_save(end,:); 86 | currentTime = t_save(end); 87 | end 88 | 89 | %% Update controller and finish the rest of the simulation 90 | [t,y] = ode45(@(t,x) simpleSysWrapper(t,x,-w), ... 91 | currentTime+[0,5], ... 92 | currentStates); 93 | t_save = [t_save 94 | t(:)]; 95 | x_save = [x_save 96 | y(:,1:4)]; 97 | 98 | % Also compare with unlearned performance 99 | [t0,y0] = ode45(@(t,x) simpleSysWrapper(t,x,w*0), ... 100 | currentTime+[0,5], ... 101 | currentStates); 102 | 103 | %% Plotting results 104 | % Create figure folder 105 | if exist('simFigures','dir') == 0 106 | mkdir('simFigures'); 107 | end 108 | 109 | %% Figure 1 Time course 110 | figure(1) 111 | % subplot(221) 112 | plot(t_save,x_save(:,1),t0, y0(:,1), 'r--', 'LineWidth', 2) 113 | xlabel('Time (sec)') 114 | legend1 = legend('x_1 (Under ADP)', 'x_1 (Unlearned)'); 115 | set(legend1,'FontSize',12); 116 | xlim([0,5]) 117 | % % 118 | % subplot(222) 119 | % plot(t_save,x_save(:,2),t0, y0(:,2), 'r--', 'LineWidth', 2) 120 | % xlabel('Time (sec)') 121 | % legend('x_b (Under ADP)', 'd/dt x_b (Unlearned)') 122 | % % 123 | % subplot(223) 124 | % plot(t_save,x_save(:,3),t0, y0(:,3), 'r--', 'LineWidth', 2) 125 | % xlabel('Time (sec)') 126 | % legend('x_b (Under ADP)', 'x_w (Unlearned)') 127 | % % 128 | % subplot(224) 129 | % plot(t_save,x_save(:,4),t0, y0(:,4), 'r--', 'LineWidth', 2) 130 | % xlabel('Time (sec)') 131 | % legend('x_b (Under ADP)', 'd/dt x_w (Unlearned)') 132 | 133 | % Create textarrow 134 | annotation('textarrow',[0.366326530612245 0.268112244897959],... 135 | [0.681349206349206 0.743253968253969],'String',{'Controller Updated'},... 136 | 'FontSize',12); 137 | 138 | print('.\simFigures\Ch3_ex1_fig1_x','-depsc'); 139 | %% Figure 2 140 | % Plot the value function surfaces and compare the inital one and the 141 | % optimized one 142 | xxb = -0.5:0.05:0.5; 143 | xxw = -0.2:0.02:0.2; 144 | [XX,YY] = meshgrid(xxb, xxw); 145 | VV = zeros(size(XX)); 146 | VV0 = VV; 147 | 148 | for i = 1:numel(XX) 149 | VV0(i) = p0'*Phi_fun([XX(i),0,YY(i),0])'; 150 | VV(i) = p'*Phi_fun([XX(i),0,YY(i),0])'; 151 | end 152 | 153 | figure(2) 154 | surf(XX,YY,VV0) 155 | hold on 156 | surf(XX,YY,VV) 157 | hold off 158 | 159 | xlabel('x_b', 'FontSize', 14); 160 | ylabel('x_w', 'FontSize', 14); 161 | 162 | % Create textarrow 163 | annotation('textarrow',[0.821428571428571 0.889285714285713],... 164 | [0.821759259259259 0.652380952380954],'String','V_0(x_b,0,x_w,0)',... 165 | 'FontSize',12); 166 | 167 | % Create textarrow 168 | annotation('textarrow',[0.833928571428571 0.868148148148148],... 169 | [0.157142857142857 0.336798336798337],'String', ... 170 | ['V_' num2str(Iter-1) '(x_b,0,x_w,0)'],... 171 | 'FontSize',12); 172 | 173 | print('.\simFigures\Ch3_ex1_fig2_v','-depsc') 174 | 175 | %% Figure 3 -- Region of Attraction 176 | % Note: This section will be skipped if you are running an order version of 177 | % MATLAB which does not have the function delaunayTriangulation 178 | 179 | SkipSection = false; 180 | try 181 | delaunayTriangulation; 182 | catch e 183 | if strcmp(e.identifier, 'MATLAB:UndefinedFunction'); 184 | SkipSection = true; 185 | warning(['The Region of attraction will not be plotted because', ... 186 | ' MATLAB version is too old']) 187 | end 188 | end 189 | 190 | if SkipSection == false 191 | indexToRemove = []; 192 | 193 | xxb = linspace(-0.5,0.5,30); 194 | xxw = linspace(-0.2,0.2,30); 195 | xxdb = linspace(-5,5,30); 196 | 197 | [XX,YY,ZZ] = meshgrid(xxb, xxdb, xxw); 198 | 199 | for i = 1:numel(XX) 200 | if ~isInRegionOfAttraction([XX(i) YY(i) ZZ(i) 0],p,D) 201 | indexToRemove = [indexToRemove i]; 202 | end 203 | end 204 | XX(indexToRemove) = []; 205 | YY(indexToRemove) = []; 206 | ZZ(indexToRemove) = []; 207 | 208 | DT = delaunayTriangulation(XX(:),YY(:),ZZ(:)); 209 | figure(3) 210 | k = convexHull(DT); 211 | faceColor = [0.6875 0.8750 0.8984]; 212 | trisurf(k,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3), ... 213 | 'FaceColor', faceColor, ... %'EdgeAlpha', 0.2, ... 214 | 'FaceAlpha', 0.3) 215 | xlim([-0.5 0.5]) 216 | ylim([-5 5]) 217 | zlim([-0.2 0.2]) 218 | % Create textbox 219 | annotation('textbox',... 220 | [0.453 0.168 0.07 0.017],... 221 | 'String','\Omega',... 222 | 'LineStyle','none',... 223 | 'FontSize',12,... 224 | 'FitBoxToText','off'); 225 | % Create textarrow 226 | annotation('textarrow',[0.735714285714286 0.68],... 227 | [0.85952380952381 0.72],'String',{ '\Omega_i estimate'},'FontSize',12); 228 | xlabel('x_b', 'FontSize', 14); 229 | ylabel('x''_b', 'FontSize', 14); 230 | zlabel('x_w', 'FontSize', 14); 231 | 232 | print('.\simFigures\Ch3_ex1_fig3_Omega','-depsc') 233 | end 234 | 235 | %% Save Numerical Results and Clean Up 236 | % Uncomment the following code to save data 237 | 238 | % if exist('simResults','dir') == 0 239 | % mkdir('simResults') 240 | % end 241 | % save .\simResults\simResults.mat -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/Phi_fun.m: -------------------------------------------------------------------------------- 1 | function y = Phi_fun(x) 2 | % Basis function for V(x) 3 | x1 = x(1); 4 | x2 = x(2); 5 | x3 = x(3); 6 | x4 = x(4); 7 | 8 | y = [x1^2 9 | x2^2 10 | x3^2 11 | x4^2 12 | x1*x2 13 | x1*x3 14 | x1*x4 15 | x2*x3 16 | x2*x4 17 | x3*x4 18 | x1^4 19 | x2^4 20 | x3^4 21 | x4^4 22 | x1^2*x2^2 23 | x1^2*x3^2 24 | x1^2*x4^2 25 | x2^2*x3^2 26 | x2^2*x4^2 27 | x3^2*x4^2 28 | ]'; 29 | 30 | 31 | % Notice that the output will be a ROW vector 32 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/Psi_fun.m: -------------------------------------------------------------------------------- 1 | function y = Psi_fun(x) 2 | % Derivative of Phi 3 | 4 | x1 = x(1); 5 | x2 = x(2); 6 | x3 = x(3); 7 | x4 = x(4); 8 | 9 | y = [x1 % #1 10 | x2 % #2 11 | x3 % #3 12 | x4 % #4 13 | x1*x1*x1 % #5 14 | x1*x1*x2 % #6 15 | x1*x1*x3 % #7 16 | x1*x1*x4 % #8 17 | x1*x2*x2 % #9 18 | x1*x2*x3 % #10 19 | x1*x2*x4 % #11 20 | x1*x3*x3 % #12 21 | x1*x3*x4 % #13 22 | x1*x4*x4 % #14 23 | x2*x2*x2 % #15 24 | x2*x2*x3 % #16 25 | x2*x2*x4 % #17 26 | x2*x3*x3 % #18 27 | x2*x3*x4 % #19 28 | x2*x4*x4 % #20 29 | x3*x3*x3 % #21 30 | x3*x3*x4 % #22 31 | x3*x4*x4 % #23 32 | x4*x4*x4 % #24 33 | ]; 34 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/adpSysWrapper.m: -------------------------------------------------------------------------------- 1 | function dX = adpSysWrapper(t,X) 2 | 3 | % System dynamics part 4 | x = X(1:4); 5 | u = sum(0.2*sin([1 3 7 11 13 15]*t)); 6 | 7 | dx = susp_sys(x,u); % dx as the first 1-4 states of the wrapper 8 | 9 | % Augmented part 10 | 11 | psi = Psi_fun(x); 12 | 13 | PsiPsi = kron(psi,psi); % Export \psi\otimes\psi as the 4+[1,24^2] states 14 | Psiu = psi*u; % Export \psi*u as the 4+[1,24^2]+ [1,99*24] states 15 | Q = x'*x; % Export q(x) as the last state 16 | 17 | dX = [dx; 18 | PsiPsi; 19 | Psiu; 20 | Q]; 21 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/getRegionOfAttraction.m: -------------------------------------------------------------------------------- 1 | function D = getRegionOfAttraction(p) 2 | %% 3 | 4 | % The set for approximation is set as 5 | %\Omega = {x1,x2,x3,x4 | x1\in(-0.5, 0.5), 6 | % x2\in(-5,5), 7 | % x3\in(-0.2,0.2), 8 | % x4\in(-10,10)} 9 | 10 | % We need to find D, by solving 11 | % 12 | % max D 13 | % st. V(x)\le D => x\in\Omega 14 | % 15 | % One necessary condition is that if x in boundary of \Omega 16 | % => V(x) >= D 17 | 18 | 19 | % Boundary checking 20 | D = 0; 21 | xs = 1; 22 | dx1 = 0.1; 23 | dx2 = 1; 24 | dx3 = 0.05; 25 | dx4 = 2; 26 | 27 | while all(xs) == 1 28 | D = D + 0.01; 29 | % 1. Check the boundary of x1 30 | for x1 = [-0.5 0.5] 31 | for x2 = -5:dx2:5 32 | for x3 = -0.2:dx3:0.2 33 | for x4 = -10:dx4:10 34 | % xs = [xs;[x1 x2 x3 x4]]; 35 | xs = [xs; p'*Phi_fun([x1 x2 x3 x4])'>= D]; 36 | end 37 | end 38 | end 39 | end 40 | 41 | % 2. Check the boundary of x2 42 | for x1 = -0.5:dx1:0.5 43 | for x2 = [-5 5] 44 | for x3 = -0.2:dx3:0.2 45 | for x4 = -10:dx4:10 46 | % xs = [xs;[x1 x2 x3 x4]]; 47 | xs = [xs; p'*Phi_fun([x1 x2 x3 x4])'>= D]; 48 | end 49 | end 50 | end 51 | end 52 | 53 | % 3. Check the boundary of x3 54 | for x1 = -0.5:dx1:0.5 55 | for x2 = -5:dx2:5 56 | for x3 = [-0.2 0.2] 57 | for x4 = -10:dx4:10 58 | % xs = [xs;[x1 x2 x3 x4]]; 59 | xs = [xs; p'*Phi_fun([x1 x2 x3 x4])'>= D]; 60 | end 61 | end 62 | end 63 | end 64 | 65 | % 4. Check the boundary of x4 66 | for x1 = -0.5:dx1:0.5 67 | for x2 = -5:dx2:5 68 | for x3 = -0.2:dx3:0.2 69 | for x4 = [-10 10] 70 | % xs = [xs;[x1 x2 x3 x4]]; 71 | xs = [xs; p'*Phi_fun([x1 x2 x3 x4])'>= D]; 72 | end 73 | end 74 | end 75 | end 76 | end 77 | 78 | D = D - 0.01; 79 | end 80 | %% 81 | 82 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/isInRegionOfAttraction.m: -------------------------------------------------------------------------------- 1 | function y = isInRegionOfAttraction(x,p,D) 2 | % Check to see if x is in the Region or Attraction 3 | y = (p'*Phi_fun(x)' <= D); 4 | end 5 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/simResults/simResults.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter3_Example1/simResults/simResults.mat -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/simpleSysWrapper.m: -------------------------------------------------------------------------------- 1 | function dx = simpleSysWrapper(~,x,w) 2 | % System dynamics part 3 | u = w'*Psi_fun(x); 4 | dx = susp_sys(x,u); % dx as the first 1-4 states of the wrapper 5 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/susp_sys.m: -------------------------------------------------------------------------------- 1 | function dx = susp_sys(x,u) 2 | 3 | % Dynamics of the syspension system 4 | x1 = x(1); 5 | x2 = x(2); 6 | x3 = x(3); 7 | x4 = x(4); 8 | 9 | % Coefficients 10 | mb = 300; % kg 11 | mw = 60; % kg 12 | bs = 1000; % N/m/s 13 | ks = 16000 ; % N/m 14 | kt = 190000; % N/m 15 | kn = ks/10; % N/m 16 | 17 | % System Dynamics 18 | dx1 = x2; 19 | dx2 = -(ks*(x1-x3)+kn*(x1-x3)^3)/mb - (bs*(x2-x4)-10000*u)/mb; 20 | dx3 = x4; 21 | dx4 = (ks*(x1-x3)+kn*(x1-x3)^3)/mw + (bs*(x2-x4)-kt*x3-10000*u)/mw; 22 | 23 | % Combine the output 24 | dx = [dx1; 25 | dx2; 26 | dx3; 27 | dx4]; 28 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/temp/NNADP_susp.m: -------------------------------------------------------------------------------- 1 | classdef NNADP_susp < handle 2 | properties 3 | PsiPsi = [] 4 | PsiU = [] 5 | Phi = [] 6 | CostQ = [] 7 | PhiLength % = numel(Phi_fun(zeros(1,4))); 8 | PsiLength % = numel(Psi_fun(zeros(1,4))); 9 | r = 1 % Weight on u, r*u^2 10 | N = 100 % Number of intervals 11 | IterMax = 10 % Number of iterations 12 | X = [1,.3,1,-.2,zeros(1,PsiLength^2+PsiLength+1)]; 13 | end 14 | 15 | methods 16 | end 17 | end 18 | 19 | 20 | 21 | % ==================== Functions for system dynamics ==================== % 22 | function dx = susp_sys(x,u) 23 | %% SUSP_SYS decribes the dynamics of the suspension system 24 | x1 = x(1); 25 | x2 = x(2); 26 | x3 = x(3); 27 | x4 = x(4); 28 | 29 | % Coefficients 30 | mb = 300; % kg 31 | mw = 60; % kg 32 | bs = 1000; % N/m/s 33 | ks = 16000 ; % N/m 34 | kt = 190000; % N/m 35 | kn = ks/10; % N/m 36 | 37 | % System Dynamics 38 | dx1 = x2; 39 | dx2 = -(ks*(x1-x3)+kn*(x1-x3)^3)/mb-(bs*(x2-x4)-u)/mb; 40 | dx3 = x4; 41 | dx4 = (ks*(x1-x3)+kn*(x1-x3)^3)/mw +(bs*(x2-x4)-kt*x3-u)/mw; 42 | 43 | % Combine the output 44 | dx = [dx1; 45 | dx2; 46 | dx3; 47 | dx4]; 48 | end 49 | 50 | function dX = adpSysWrapper(t,X) 51 | %% ADPSYSWRAPPER augments the systems dynamics function by adding integrators 52 | 53 | % System dynamics part 54 | x = X(1:4); 55 | u = sum(0.1*sin([1 3 7 11 13 15]*t)); 56 | 57 | dx = susp_sys(x,u); % dx as the first 1-4 states of the wrapper 58 | 59 | % Augmented part 60 | 61 | psi = Psi_fun(x); 62 | 63 | PsiPsi = kron(psi,psi); % Export \psi\otimes\psi as the 4+[1,24^2] states 64 | Psiu = psi*u; % Export \psi*u as the 4+[1,24^2]+ [1,24] states 65 | Q = x'*x; % Export q(x) as the last state 66 | 67 | dX = [dx; 68 | PsiPsi; 69 | Psiu; 70 | Q]; 71 | end 72 | 73 | 74 | % =========================== Utility functions ========================= % 75 | function y = Phi_fun(x) 76 | %% PHI_FUN is the function to approximate the value function V(x) 77 | x1 = x(1); 78 | x2 = x(2); 79 | x3 = x(3); 80 | x4 = x(4); 81 | % 82 | y = [x1^2 83 | x2^2 84 | x3^2 85 | x4^2 86 | x1*x2 87 | x1*x3 88 | x1*x4 89 | x2*x3 90 | x2*x4 91 | x3*x4 92 | x1^4 93 | x2^4 94 | x3^4 95 | x4^4 96 | x1^2*x2^2 97 | x1^2*x3^2 98 | x1^2*x4^2 99 | x2^2*x3^2 100 | x2^2*x4^2 101 | x3^2*x4^2 102 | ]'; 103 | % Notice that the output will be a ROW vector 104 | end 105 | 106 | 107 | function y = Psi_fun(x) 108 | %% PSI_FUN are the basic functions to approximate u(x) 109 | x1 = x(1); 110 | x2 = x(2); 111 | x3 = x(3); 112 | x4 = x(4); 113 | % 114 | y = [x1 % #1 115 | x2 % #2 116 | x3 % #3 117 | x4 % #4 118 | x1*x1*x1 % #5 119 | x1*x1*x2 % #6 120 | x1*x1*x3 % #7 121 | x1*x1*x4 % #8 122 | x1*x2*x2 % #9 123 | x1*x2*x3 % #10 124 | x1*x2*x4 % #11 125 | x1*x3*x3 % #12 126 | x1*x3*x4 % #13 127 | x1*x4*x4 % #14 128 | x2*x2*x2 % #15 129 | x2*x2*x3 % #16 130 | x2*x2*x4 % #17 131 | x2*x3*x3 % #18 132 | x2*x3*x4 % #19 133 | x2*x4*x4 % #20 134 | x3*x3*x3 % #21 135 | x3*x3*x4 % #22 136 | x3*x4*x4 % #23 137 | x4*x4*x4 % #24 138 | ]; 139 | end 140 | 141 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/temp/mdlCoeff.m: -------------------------------------------------------------------------------- 1 | mb = 300; % kg 2 | mw = 60; % kg 3 | bs = 1000; % N/m/s 4 | ks = 16000 ; % N/m 5 | kt = 190000; % N/m 6 | kn = 0*ks/10; % N/m -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/temp/susp_sys_linear.m: -------------------------------------------------------------------------------- 1 | function dx = susp_sys_linear(x,u, A, B) 2 | 3 | % Dynamics of the syspension system 4 | x1 = x(1); 5 | x2 = x(2); 6 | x3 = x(3); 7 | x4 = x(4); 8 | 9 | % Coefficients 10 | mdlCoeff 11 | 12 | % System Dynamics 13 | dx1 = x2; 14 | dx2 = -(ks*(x1-x3)+kn*(x1-x3)^3)/mb - (bs*(x2-x4)-10000*u)/mb; 15 | dx3 = x4; 16 | dx4 = (ks*(x1-x3)+kn*(x1-x3)^3)/mw + (bs*(x2-x4)-kt*x3-10000*u)/mw; 17 | 18 | 19 | % Combine the output 20 | dx = [dx1; 21 | dx2; 22 | dx3; 23 | dx4]-(A*x+B*u); 24 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/temp/tester.m: -------------------------------------------------------------------------------- 1 | % Test if the A B Matrices are valid 2 | 3 | % Coefficients 4 | mdlCoeff 5 | 6 | 7 | A = [ 0 1 0 0; [-ks -bs ks bs]/mb ; ... 8 | 0 0 0 1; [ks bs -ks-kt -bs]/mw]; 9 | B = [0; 10000/mb ; 0; -10000/mw]; 10 | 11 | susp_sys_linear(rand(4,1),rand, A, B); 12 | 13 | P_init = lyap(A',eye(4)); 14 | K1 = 1/r*B'*P_init; 15 | 16 | [P,~,K] = care(A,B,eye(4),1) 17 | 18 | 19 | 20 | % Optimal values 21 | % 22 | % P = 23 | % 24 | % 1.8639 0.0703 -1.5871 0.0123 25 | % 0.0703 0.0638 -0.9956 0.0069 26 | % -1.5871 -0.9956 40.3489 -0.0763 27 | % 0.0123 0.0069 -0.0763 0.0063 28 | % 29 | % 30 | % K = 31 | % 32 | % 0.2868 0.9727 -20.4658 -0.8259 -------------------------------------------------------------------------------- /Robust-ADP/Chapter3_Example1/test.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter3_Example1/test.mat -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example1/Ch4Ex1_main.m: -------------------------------------------------------------------------------- 1 | function Ch4Ex1_main() 2 | %% SOS-based Policy Iteration for a car suspension systems 3 | % The function is tested in MATLAB R2014b 4 | % Copyright 2015 Yu Jiang 5 | % Contact Yu Jiang (yu.jiang@nyu.edu) 6 | 7 | % System requirements: 8 | % - MATLAB (Manually Tested in MATLAB R2014b) 9 | % - MATLAB Symbolic Toolbox 10 | % - SDPT3-4.0 11 | % - SISOTOOLS (free to download at http://www.cds.caltech.edu/sostools/) 12 | 13 | % You can download tools.zip and run setuptools.m in the folder. 14 | 15 | syms x1 x2 x3 x4 real 16 | mb = 300; % kg 17 | mw = 60; % kg 18 | bs = 1000; % N/m/s 19 | ks = 16000 ; % N/m 20 | kt = 190000; % N/m 21 | kn = 0.1*ks; 22 | 23 | % State matrices 24 | A = [ 0 1 0 0; 25 | [-ks -bs ks bs]/mb ; ... 26 | 0 0 0 1; 27 | [ks bs -ks-kt -bs]/mw]; 28 | B = [ 0 0; 0 10000/mb ; 0 0 ; [kt -10000]/mw]; 29 | B = B(:,2); 30 | 31 | % LQR feedback gains for the linearized system 32 | % Klqr = lqr(A,B,eye(4),1); 33 | % f(x) 34 | f = A*[x1;x2;x3;x4] + [0;-kn*(x1-x3)^3/mb;0;kn*(x1-x3)^3/mw]; 35 | 36 | % Polynomial Weighting functions 37 | q0 = 100*x1^2+x2^2+x3^2+x4^2; 38 | rx = 1;%+(x1^2+x2^2+x3^2+x4^2); 39 | vars = [x1;x2;x3;x4]; 40 | 41 | % Initialize the SOSp 42 | prog = sosprogram(vars); 43 | 44 | % The Lyapunov function V(x) 45 | [prog,V] = sospolyvar(prog,monomials([x1;x2;x3;x4],2:4),'wscoeff'); 46 | 47 | % Objective of the SOSp 48 | myObj = int(int(int(int(V,-.5,.5),-10,10),-.5,.5),-10,10); 49 | 50 | % Add Inequality constraint to assure V is positive definite 51 | prog = sosineq(prog,V-0.0001*(x1^2+x2^2+x3^2+x4^2)); 52 | 53 | % Add Inequality constraint to assure stability and performance 54 | expr = -[diff(V,x1) diff(V,x2) diff(V,x3) diff(V,x4)]*rx*f-rx*q0; 55 | prog = sosineq(prog,expr); 56 | 57 | % Solve the SOSp 58 | prog = sossolve(prog); 59 | 60 | % Obtain the Initial Lyapunov function 61 | V0 = sosgetsol(prog,V); 62 | V_old = V0; 63 | 64 | % Initializing the old contol policy 65 | u_prev = zeros(size(x1)); 66 | 67 | % Iteration 68 | for i=1:10 69 | clear prog V 70 | %------------------------------ SOSp Start ---------------------------- 71 | prog = sosprogram(vars); 72 | [prog,V] = sospolyvar(prog,monomials([x1;x2;x3;x4],2:4),'wscoeff'); 73 | prog = sosineq(prog,V_old - V); 74 | prog = sosineq(prog, V); 75 | u = -1/2*B'*[diff(V_old,x1) diff(V_old,x2) diff(V_old,x3) diff(V_old,x4)].'; 76 | qfcn =rx*q0 + u'*u; 77 | expr = -[diff(V,x1) diff(V,x2) diff(V,x3) diff(V,x4)]*(rx*f+B*u)-qfcn; 78 | prog = sosineq(prog,expr); 79 | prog = sossetobj(prog, myObj); 80 | prog = sossolve(prog); 81 | %------------------------------ SOSp End ------------------------------ 82 | V_ = sosgetsol(prog,V); 83 | V_old = V_; 84 | end 85 | 86 | % Save the improved value function 87 | Vnew = V_; 88 | 89 | %% Post-processing results 90 | x0 = [0,0,0,0]; % Iniial Condition 91 | tIntv = [0 3]; 92 | [t1,y1] = ode23s(@(t,x) LocalSuspSys(t,x,u), [0 3], x0); 93 | [t,y] = ode23s(@(t,x) LocalSuspSys(t,x,0), tIntv, x0); 94 | 95 | %% Plot Results 96 | figure(1) 97 | subplot(411); 98 | plot(t1,y1(:,1),t,y(:,1), 'r:','linewidth',2); 99 | xlabel('time (sec)', 'FontSize',12) 100 | ylabel('x_1','FontSize',12) 101 | hl = legend('Improved performance', 'Uncontrolled performance'); 102 | set(hl, 'FontSize', 12'); 103 | subplot(412); 104 | plot(t1,y1(:,2),t,y(:,2),'r:','linewidth',2); 105 | xlabel('time (sec)', 'FontSize',12) 106 | ylabel('x_2','FontSize',12) 107 | hl = legend('Improved performance', 'Uncontrolled performance'); 108 | set(hl, 'FontSize', 12'); 109 | subplot(413); 110 | plot(t1,y1(:,3),t,y(:,3), 'r:','linewidth',2); 111 | xlabel('time (sec)', 'FontSize',12) 112 | ylabel('x_3','FontSize',12) 113 | hl = legend('Improved performance', 'Uncontrolled performance'); 114 | set(hl, 'FontSize', 12'); 115 | subplot(414); 116 | plot(t1,y1(:,4),t,y(:,4),'r:','linewidth',2); 117 | xlabel('time (sec)', 'FontSize',12) 118 | ylabel('x_4','FontSize',12) 119 | hl = legend('Improved performance', 'Uncontrolled performance'); 120 | set(hl, 'FontSize', 12'); 121 | 122 | 123 | figure(2) 124 | xx1 = -.4:.04:.4; 125 | xx2 = -5:0.5:5; 126 | vn = zeros(length(xx1),length(xx2)); 127 | v1 = zeros(length(xx1),length(xx2)); 128 | un=vn; 129 | ulqr = un; 130 | kn=vn; 131 | k1=v1; 132 | x3=0; 133 | x4=0; 134 | for i=1:length(xx1) 135 | x1 = xx1(i); 136 | for j=1:length(xx2) 137 | x2 = xx2(j); 138 | vn(i,j)=eval(Vnew); 139 | v1(i,j)=eval(V0); 140 | end 141 | end 142 | surf(xx1,xx2,vn') 143 | hold on 144 | surf(xx1,xx2,v1') 145 | hold off 146 | xlabel('x_1', 'FontSize', 12) 147 | ylabel('x_2', 'FontSize', 12) 148 | view(gca,[-30.5 28]); 149 | % Create textarrow 150 | annotation(gcf,'textarrow',[0.210714285714286 0.174535137214669],... 151 | [0.895238095238095 0.631440045897884],'TextEdgeColor','none','FontSize',12,... 152 | 'String',{'V_0(x1,x2,0,0)'}); 153 | 154 | % Create textarrow 155 | annotation(gcf,'textarrow',[0.139285714285714 0.186735060271868],... 156 | [0.183333333333333 0.386454388984516],'TextEdgeColor','none','FontSize',12,... 157 | 'String',{'V_{10}(x1,x2,0,0)'}); 158 | % export_fig Ex3_cost -pdf -transparent 159 | 160 | end 161 | 162 | 163 | %% LocalSuspSys 164 | % Dynamics of the nonlinear suspension system 165 | function dx = LocalSuspSys(t,x,u) 166 | mb = 300; % kg 167 | mw = 60; % kg 168 | bs = 1000; % N/m/s 169 | ks = 16000 ; % N/m 170 | kt = 190000; % N/m 171 | 172 | [x1,x2,x3,x4] = deal(x(1),x(2),x(3),x(4)); 173 | 174 | % State matrices 175 | A = [ 0 1 0 0; 176 | [-ks -bs ks bs]/mb ; ... 177 | 0 0 0 1; 178 | [ks bs -ks-kt -bs]/mw]; 179 | B = [ 0; 10000/mb ; 0 ; -10000/mw]; 180 | B1 = [ 0; 0 ; 0 ; kt/mw]; 181 | 182 | if ~isdouble(u) 183 | u = eval(u); 184 | end 185 | 186 | if t <= 0.001 187 | r = 10; 188 | else 189 | r = 0; 190 | end 191 | 192 | dx = A*x + B*u + B1*r; 193 | end 194 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example1/figures/Ch4_Ex1_V.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example1/figures/Ch4_Ex1_V.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example1/figures/Ch4_Ex1_x.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example1/figures/Ch4_Ex1_x.jpg -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example1/figures/Ch4_Ex1_x.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example1/figures/Ch4_Ex1_x.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example1/figures/x.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example1/figures/x.fig -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/Ch4Ex2_main.m: -------------------------------------------------------------------------------- 1 | function SimResults = Ch4Ex2_main() 2 | %% GADP for a scalar polynomial system 3 | % Demo #1 for Global Adaptive Dynamic Programming for Continuous-time 4 | % Nonlinear Systems, by Yu Jiang and Zhong-Ping 5 | % Jiang, IEEE Transasctions on Automatic Control, 2015 6 | % 7 | % This paper can be found at 8 | % 1. http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=7063901 9 | % 2. http://arxiv.org/pdf/1401.0020.pdf 10 | % 11 | % System requirements: 12 | % - MATLAB (Manually Tested in MATLAB R2014b) 13 | % - MATLAB Symbolic Toolbox 14 | % - CVX (free to download at http://cvxr.com/cvx/) 15 | % 16 | % Copyright 2015 Yu Jiang 17 | % 18 | % Contact: yu.jiang@nyu.edu (Yu Jiang) 19 | 20 | %% Setting parameters 21 | % Parameters for Simulation the dynamic system 22 | SysParams.Q = 0.01*[1 0 0;0 1 0;0 0 0]; % The cost function will be 23 | % ([x]_{1,3})'*Q*[x]_{1,3}+u^2 24 | SysParams.noiseFlag = true; % Inicator for noise on/off 25 | SysParams.K = [0.1 0 0.01]; % Initial feeback gain matrix 26 | SysParams.F = [0 0.01 0]; % System dynamics dx = F*[x]_1,3 + u, 27 | % F is not used in Online Policy Iteration 28 | SysParamsInit = SysParams; % Make a copy of initial parameters 29 | 30 | % Parameters for learning 31 | Params.iter_tol = 0.007; 32 | Params.T = 0.1; % Length of each time interval for data collection 33 | Params.MaxIter = 10; % Maximum iteration numbers 34 | Params.IterInterval = 5; % Length of each time interval for learning 35 | Params.xinit = 2; % Initial condition for the actual state x 36 | 37 | 38 | % Other params 39 | x = [Params.xinit;zeros(9,1)]'; % Initial condition for the augmented x 40 | P = eye(2)*10; % Initialize V_0: ([x]_{1,2})'*P*[x]_{1,2} 41 | Pold = -100*eye(2); % Initialize V_{-1} 42 | 43 | % Simulation results to export 44 | SimResults.Ksave = SysParams.K; % Keep track of the feedback gains 45 | SimResults.Psave = P(:)'; % Keep track of the value function 46 | SimResults.Usave = []; % Actual control signal during simulation 47 | SimResults.Xsave=[]; % Actual x(t) during simulation 48 | SimResults.Tsave=[]; % Sample time points during simulation 49 | 50 | 51 | % caculate the weights for V 52 | c = LocalComputeObjective(-1, 1); 53 | 54 | %% Start online simulation 55 | for i = 0:Params.MaxIter-1 56 | % Data collection 57 | Theta = [];Sigma = []; Xi = []; % Data matrices for online learning 58 | for j = 0:Params.IterInterval/Params.T-1 59 | [t,x] = ode45(@(t,x) SystemWrapper(t,x,SysParams), ... 60 | [j,j+1]*Params.T + i*Params.IterInterval, ... 61 | [x(end,1) zeros(1,9)]); 62 | Theta = [Theta; 63 | (x(end,1)^2-x(1,1)^2) (x(end,1)^3-x(1,1)^3) (x(end,1)^4-x(1,1)^4)]; 64 | Sigma = [Sigma; 65 | x(end,2:6) -x(end,7:9)]; 66 | Xi = [Xi; x(end,10)]; 67 | SimResults.Tsave = [SimResults.Tsave;t]; 68 | SimResults.Xsave = [SimResults.Xsave;x(:,1)]; 69 | for k=1:length(t) 70 | SimResults.Usave = [SimResults.Usave; 71 | LocalComputeControlSignal(x(k,1),SysParams.K,... 72 | SysParams.noiseFlag,t(k))]; 73 | end 74 | end 75 | 76 | % SOS-based Online Policy iteration 77 | if norm(P(:)-Pold(:)) > Params.iter_tol 78 | % Calling local function for policy improvement and policy 79 | % evaluation. Notice that we do not pass in the systen dynamics, 80 | % i.e, the F vector. Because online learning does not rely on it. 81 | [Pn,K] = LocalOnlinePI(Sigma,Xi,Theta,... % Data matrices collected online 82 | c, ... % weights 83 | P); % previous value function 84 | Pold = P; P = Pn; % Save the current and the old P 85 | SysParams.noiseFlag = true; 86 | SysParams.K = K; 87 | SimResults.Ksave = [SimResults.Ksave; K(:)']; 88 | SimResults.Psave = [SimResults.Psave; P(:)']; 89 | % Qlave=[Qlave;dQl(:)']; 90 | 91 | else 92 | SysParams.noiseFlag = false; 93 | disp('Convergence has been attained ...update is not necessary') 94 | end 95 | end 96 | 97 | %% Post-process and plot results 98 | SimResults.hFigs = LocalPostProcess(SysParams, SysParamsInit, ... 99 | SimResults,Params, P); 100 | end 101 | 102 | %% LocalPostProcess: Process results and generate figures 103 | function hFigs = LocalPostProcess(SysParams, SysParamsInit,SimResults, Params, P) 104 | % Figure 1: 105 | % Comparison of x between GADP and unlearned system 106 | hFig1 = figure(1); 107 | [t0,y0] = ode45(@(t,x) SystemWrapper(t,x,SysParamsInit),... 108 | [0 50], ... 109 | [Params.xinit, zeros(1,9)]); 110 | y0 = y0(:,1); % Only need the first column for the actual x 111 | for i=1:length(t0) 112 | u0(i) = SysParamsInit.K * y0(i).^[1 2 3]'; % Unleared controller 113 | end 114 | 115 | plot(SimResults.Tsave, SimResults.Xsave, 'b-', ... % Learned 116 | t0,y0, 'r-.', ... % Unlearned 117 | 'linewidth', 2) 118 | axis([0 50 -.5 2]) 119 | myLegend = legend('With GADP-based controller', 'With initial controller'); 120 | set(myLegend, 'Fontsize', 12); 121 | xlabel('time (sec)', 'FontSize', 12) 122 | %ylabel('x', 'FontSize', 12) 123 | 124 | % Create textarrows 125 | annotation(hFig1,'textarrow', ... 126 | [0.281132075471698 0.226415094339623],... 127 | [0.845386533665835 0.800498753117207],'TextEdgeColor','none',... 128 | 'FontSize',12,... 129 | 'String',{'1st iteration'}); 130 | annotation(hFig1,'textarrow',... 131 | [0.443396226415094 0.44188679245283],... 132 | [0.244389027431421 0.309127182044887],'TextEdgeColor','none',... 133 | 'FontSize',12,... 134 | 'String',{'4th iteration'}); 135 | annotation(hFig1,'textarrow',... 136 | [0.369811320754717 0.372452830188679],... 137 | [0.448877805486284 0.386334164588527],'TextEdgeColor','none',... 138 | 'FontSize',12,... 139 | 'String',{'3rd iteration'}); 140 | annotation(hFig1,'textarrow',... 141 | [0.284905660377358 0.286037735849057],... 142 | [0.321695760598504 0.416408977556109],'TextEdgeColor','none', ... 143 | 'FontSize',12,... 144 | 'String',{'2nd iteration'}); 145 | 146 | % Figure 2 147 | hFig2 = figure(2); 148 | plot(SimResults.Tsave, SimResults.Usave,'Linewidth',2) 149 | myLegend = legend('u'); 150 | set(myLegend, 'FontSize', 12); 151 | xlabel('time (sec)', 'FontSize', 12) 152 | axis([0 50 -0.5 2]); 153 | % Create textarrows 154 | annotation(hFig2 ,'textarrow',[0.239092495636998 0.2107082880569],... 155 | [0.221748400852878 0.320754616656652],'TextEdgeColor','none', ... 156 | 'FontSize',12,... 157 | 'String',{'1st iteration'}); 158 | annotation(hFig2 ,'textarrow',[0.396160558464223 0.361981626000198],... 159 | [0.176972281449893 0.27332776800004],'TextEdgeColor','none', ... 160 | 'FontSize',12,... 161 | 'String',{'3rd iteration'}); 162 | annotation(hFig2 ,'textarrow',[0.331588132635253 0.2999993414337],... 163 | [0.439232409381663 0.335385523398326],'TextEdgeColor','none', ... 164 | 'FontSize',12,... 165 | 'String',{'2nd iteration'}); 166 | annotation(hFig2 ,'textarrow',[0.471204188481675 0.443631993150911],... 167 | [0.37953091684435 0.304862789720793],'TextEdgeColor','none', ... 168 | 'FontSize',12,... 169 | 'String',{'4th iteration'}); 170 | 171 | 172 | 173 | % Figures 3: 174 | % Comparing the initial, the improved, and the ideal value fcn 175 | syms v(y) 176 | F = SysParams.F; 177 | % Solve the HJB analytically 178 | vsx = dsolve(diff(v)*(F(1)*y+F(2)*y^2+F(3)*y^3) + 0.01*(y^2+y^4)-1/4*(diff(v))^2==0, v(0)==0); 179 | vsx = vsx(1); 180 | x = -2.5:.01:2.5; 181 | vn = []; % V_n 182 | v1 = []; % V_1 183 | vs = []; % Optimal V* 184 | us = []; % Optimal u* 185 | u1 = []; % Initial u_1 186 | un = []; % Improved u_n 187 | P1 = [SimResults.Psave(2,1) SimResults.Psave(2,2); 188 | SimResults.Psave(2,3) SimResults.Psave(2,4)] ; 189 | 190 | for y = x 191 | vn = [vn [y y^2]*P*[y ;y^2]]; 192 | v1 = [v1 [y y^2]*P1*[y ;y^2]]; 193 | vs = [vs eval(vsx)]; 194 | u1 = [u1 -1/2*SysParamsInit.K*[y;y^2;y^3]]; 195 | un = [un -1/2*SysParams.K'*[y;y^2;y^3]]; 196 | us = [us -1/2*eval(diff(vsx))]; 197 | %(y*(y*(101*y^2 + 100)^(1/2) + 101*y^2 + 100))/(50*(101*y^2 + 100)^(1/2)) 198 | end 199 | 200 | hFig3 = figure(3); 201 | plot(x,v1,'g:',x,vn,'r-.',x,vs,'b','linewidth',2) 202 | myLegend = legend('V_1 : Initial cost', 'V_4: Improved cost', ... 203 | 'V^o: Optimal cost'); 204 | set(myLegend, 'FontSize', 12); 205 | xlabel('x', 'FontSize', 12) 206 | 207 | % Figures 4: 208 | % Comparing the initial, the improved, and the ideal control input 209 | hFig4 = figure(4); 210 | plot(x,u1,'g:',x,un,'r-.',x,us,'b','linewidth',2) 211 | myLegend = legend('u_1: Initial control policy', ... 212 | 'u_4: Improved control policy', ... 213 | 'u^o: Optimal control policy'); 214 | set(myLegend, 'FontSize', 12); 215 | xlabel('x', 'FontSize', 12) 216 | 217 | % Export all figure handles 218 | hFigs = [hFig1; hFig2; hFig3; hFig4]; 219 | 220 | end 221 | 222 | %% LocalOnlinePI 223 | % Local function to implement the online ADP method. 224 | % Note1: CVX solver is required (Download: http://cvxr.com/cvx/) 225 | % Note2: The learning process does not depend on the system dynamics (F) 226 | function [Pn,K] = LocalOnlinePI(Sigma,Xi,Theta,c,P) 227 | cvx_begin sdp 228 | variable pv(3,1) 229 | variable dQl(3,3) symmetric 230 | % SDP Objective function 231 | minimize(c(1)*pv(1)+c(3)*pv(3)) 232 | % 1) Equality constraint 233 | LnK = -inv(Sigma'*Sigma)*Sigma'*(Xi + Theta*pv(:)); 234 | % 2) SOS constraint: 235 | % L*[x]_2,6 is SOS 236 | % i.e., there exists Ql>0, such that 237 | % L*[x]_2,6 = ([x]_1,3)'*Ql*[x]_1,3 238 | LnK(1) == dQl(1,1); %#ok<*EQEFF> CVX Syntax 239 | LnK(2) == dQl(1,2) + dQl(2,1); 240 | LnK(3) == dQl(1,3) + dQl(3,1) + dQl(2,2); 241 | LnK(4) == dQl(3,2) + dQl(2,3); 242 | LnK(5) == dQl(3,3); 243 | dQl >= 0; %#ok<*VUNUS> CVX Syntax 244 | % 3) SOS constraint 245 | % pv_old*[x]_1,3 - pv*[x]_1,3 is SOS 246 | % This implies that 247 | % V_old >= V_new (i.e.,the value function is reduced) 248 | Pn = [ pv(1) 1/2*(pv(2)); 1/2*(pv(2)) pv(3)]; 249 | Pn <= P; 250 | K = LnK(6:8); 251 | cvx_end 252 | end 253 | 254 | 255 | 256 | %% LocalComputeObjective 257 | % Compute the objective function for the SOSp in 258 | % Policy Iterations. The objective depends on the interval [x_min, x_max]. 259 | % This requires MATLAB Symbolic Toolbox. 260 | function c = LocalComputeObjective(x_min, x_max) 261 | syms z 262 | c = double(int(z.^[2,3,4], x_min,x_max)); 263 | end 264 | 265 | %% LocalComputeControlSignal 266 | % Compute the control input 267 | function u = LocalComputeControlSignal(x,K,noiseFlag,t) 268 | u = -1/2*K(:)'*x.^[1 2 3]'+ ExplorationNoise(t)*noiseFlag; 269 | u = abs(u); 270 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/ExplorationNoise.m: -------------------------------------------------------------------------------- 1 | function e = ExplorationNoise(t) 2 | %% LocalExploration 3 | % Generate exploratoion noise 4 | e = (0.01*sin(10*t)+0.01*sin(3*t)+0.01*sin(100*t)); 5 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/SystemWrapper.m: -------------------------------------------------------------------------------- 1 | function dX = SystemWrapper(t,x,SysParams) 2 | %% SystemWrapper 3 | % Local function to Wrap the system with externally 4 | % specified integators for learning purpose 5 | 6 | % Get local copies for parameters 7 | K = SysParams.K(:)'; 8 | Q = SysParams.Q; 9 | 10 | x1 = x(1); 11 | sgm = x1.^[1 2 3]'; 12 | 13 | if SysParams.noiseFlag 14 | e = ExplorationNoise(t); 15 | else 16 | e = 0; 17 | end 18 | 19 | u = -1/2*K*sgm + e; 20 | dx = LocalSystemKernel(x1,u,SysParams.F); 21 | dZ = x1.^[2 3 4 5 6]'; 22 | deZ = sgm*e; 23 | dQ = sgm'*(Q + 1/4*K'*K)*sgm; 24 | dX = [dx;dZ;deZ;dQ]; % length 1 + 5 + 3 + 1 = 10 25 | end 26 | 27 | %% LocalSystemKernel 28 | % Local function to implement polynomial system dynamics 29 | function dx = LocalSystemKernel(x,u, F) 30 | sgm = x.^[1 2 3]'; 31 | dx = F * sgm + u; 32 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/devel/GADP_offline_validation.m: -------------------------------------------------------------------------------- 1 | %Global ADP 2 | % global W F Q 3 | F = [0 0.01 0]; 4 | 5 | Q=[1 0 0;0 1 0;0 0 1]; 6 | Q =0.01*[1 0 0;0 1 0;0 0 0]; 7 | W=[0.1 0 0.01]; 8 | P=[10 0;0 10]; 9 | Psave=[]; 10 | Qsave=[]; 11 | 12 | Qk = Q + 1/4*W'*W; 13 | 14 | for i=1:3 15 | cvx_begin sdp 16 | 17 | variable dQs(3,3) symmetric 18 | variable Wn(1,3) 19 | variable mu 20 | 21 | % Wn(1,3) 22 | %Wn=[2*Pn(1,1); 6*Pn(1,2); 4*Pn(2,2)]'; 23 | %Pn=[1/2*(Wn(1)-W(1)) 1/6*(Wn(2)-W(2));1/6*(Wn(2)-W(2)) 1/4*(Wn(3)-W(3))]; 24 | %dQ=-(1/2*(Wn'*(F-1/2*W)+(F-1/2*W)'*Wn)+Q+1/4*(W'*W));%==0; 25 | 26 | dQ=-(Wn'*(F-1/2*W)+Q+1/4*(W'*W)); 27 | dQs(1,1)==dQ(1,1); 28 | dQs(1,2)+dQs(2,1)==dQ(1,2)+dQ(2,1); 29 | dQs(1,3)+dQs(3,1)+dQs(2,2)==dQ(1,3)+dQ(3,1)+dQ(2,2); 30 | dQs(3,2)+dQs(2,3)==dQ(3,2)+dQ(2,3); 31 | dQs(3,3)==dQ(3,3); 32 | dQs>=0; 33 | Pn=[1/2*(Wn(1)) 1/6*(Wn(2)); 1/6*(Wn(2)) 1/4*(Wn(3))]; 34 | Pn>=0; 35 | %P<=(1e-8)*eye(2); 36 | %mu*eye(3)-dQs>= 0; 37 | %mu*eye(2)-P>= 0; 38 | Pn<=P-(1e-10)*eye(2); 39 | minimize(trace(dQs)) 40 | 41 | cvx_end; 42 | W=Wn; 43 | P=Pn; 44 | Psave=[Psave;P(:)'] 45 | Qsave=[Qsave;dQs(:)'] 46 | end 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/devel/prepareFigure.m: -------------------------------------------------------------------------------- 1 | figure(1) 2 | export_fig Ch4_Ex2_state -pdf -transparent 3 | figure(2) 4 | export_fig Ch4_Ex2_control -pdf -transparent 5 | figure(3) 6 | export_fig Ch4_Ex2_cost -pdf -transparent 7 | figure(4) 8 | export_fig Ch4_Ex2_control_curve -pdf -transparent -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_control.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_control.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_control_curve.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_control_curve.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_cost.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_cost.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_state.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/figures/Ch4_Ex2_state.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_01.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_02.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_03.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example2/html/Ch4Ex2_main_04.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/BasisPlanMono.m: -------------------------------------------------------------------------------- 1 | function y = BasisPlanMono(x1,x2) 2 | y = [x1; 3 | x2; 4 | x1*x1; 5 | x1*x2; 6 | x2*x2; 7 | x1*x1*x1; 8 | x1*x1*x2; 9 | x1*x2*x2; 10 | x2*x2*x2]; 11 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/BasisQuadPhiX.m: -------------------------------------------------------------------------------- 1 | function y = BasisQuadPhiX(x1,x2) 2 | y = [x1*x1; 3 | x1*x2; 4 | x2*x2; 5 | x1*x1*x1; 6 | x1*x1*x2; 7 | x1*x2*x2; 8 | x2*x2*x2; 9 | x1*x1*x1*x1; 10 | x1*x1*x1*x2; 11 | x1*x1*x2*x2; 12 | x1*x2*x2*x2; 13 | x2*x2*x2*x2;]; 14 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/BasisQuadPlantMono.m: -------------------------------------------------------------------------------- 1 | function y = BasisQuadPlantMono(x1,x2) 2 | % Basis for the generalized HJ 3 | y = [x1*x1; 4 | x1*x2; 5 | x2*x2; 6 | x1*x1*x1; 7 | x1*x1*x2; 8 | x1*x2*x2; 9 | x2*x2*x2; 10 | x1*x1*x1*x1; 11 | x1*x1*x1*x2; 12 | x1*x1*x2*x2; 13 | x1*x2*x2*x2; 14 | x2*x2*x2*x2; 15 | x1*x1*x1*x1*x1; 16 | x1*x1*x1*x1*x2; 17 | x1*x1*x1*x2*x2; 18 | x1*x1*x2*x2*x2; 19 | x1*x2*x2*x2*x2; 20 | x2*x2*x2*x2*x2; 21 | x1*x1*x1*x1*x1*x1; 22 | x1*x1*x1*x1*x1*x2; 23 | x1*x1*x1*x1*x2*x2; 24 | x1*x1*x1*x2*x2*x2; 25 | x1*x1*x2*x2*x2*x2; 26 | x1*x2*x2*x2*x2*x2; 27 | x2*x2*x2*x2*x2*x2]; 28 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/Ch4Ex3_main.m: -------------------------------------------------------------------------------- 1 | function SimResults = GADP_FT_main() 2 | % Demo #2 for Global Adaptive Dynamic Programming for Continuous-time 3 | % Nonlinear Systems, by Yu Jiang and Zhong-Ping 4 | % Jiang, IEEE Transasctions on Automatic Control, 2015 5 | % 6 | % This paper can be found at 7 | % 1. http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=7063901 8 | % 2. http://arxiv.org/pdf/1401.0020.pdf 9 | % 10 | % System requirements: 11 | % - MATLAB (Manually Tested in MATLAB R2014b) 12 | % - MATLAB Symbolic Toolbox 13 | % - CVX (free to download at http://cvxr.com/cvx/) 14 | % 15 | % Copyright 2015 Yu Jiang 16 | % 17 | % Contact: yu.jiang@nyu.edu (Yu Jiang) 18 | 19 | % Initialize Parameters 20 | % x1 x2 x1x1 x1x2 x2x2 x1^3 x1x1x2 x1x2x2 x2^3 21 | Params.F = [0 0 0 1 0 -1 0 -1 0; 22 | 1 2 0 0 0 0 0 0 0]; 23 | Params.G = [0 0.7; 0.6 0.7]; 24 | Params.Q = diag([1,1,0,0,0,0,0,0,0]); 25 | Params.R = 0.001; 26 | 27 | % Inital control gains, thees values are taken from literature 28 | Params.K0 = [10.283 -13.769; -10.7 -3.805]; 29 | 30 | % Extend the gains to match the new basis 31 | K = [Params.K0 zeros(2,7)]; 32 | K_old = K; 33 | 34 | Params.Gl = [0 1; 1 1]; % Lower Bound of G 35 | Params.Gu = [0 0.5; 0.5 0.5]; % Upper Bound of G 36 | 37 | % Initialize the value function 38 | p = LocalInitialValueControlPair(Params); 39 | p_old = ones(size(p))*100; 40 | 41 | x0 =[1 -2]; % Initial Condition 42 | X = x0; 43 | 44 | % Policy Iteraton Parameters 45 | IterMax = 7; %Max iterations 46 | T = 0.02; %Length of interval for data collection 47 | NumIntervals = 200; %Number of intervals for one interation 48 | tol_conv = 0.0001; %Convergence criterion 49 | 50 | % Compute the objective function for SOSs in Poilcy Iteration 51 | x1min = -0.1; 52 | x1max = 0.1; 53 | x2min = -0.1; 54 | x2max = 0.1; 55 | c = LocalComputeObjectiveFcn(x1min, x1max, x2min, x2max); 56 | 57 | % This varibles go to the output 58 | psave=[]; 59 | ksave= K; 60 | Xsave=[]; 61 | tsave=[]; 62 | 63 | for j = 1:IterMax 64 | % Online Simulation for Data Collection 65 | [Phi, Xi, Theta, Xsave, tsave, t, X] = LocalOnlineDataCollection(T, ... 66 | NumIntervals, X, Xsave, tsave, j, Params, K); 67 | 68 | % Online Policy Iteration 69 | if norm(p - p_old)>tol_conv 70 | p_old = p; 71 | [p, K] = LocalOnlinePolicyIteratoin(Theta, Xi, Phi, p, c); 72 | numAIter = j; 73 | end 74 | 75 | psave = [psave;p_old']; %#ok 76 | ksave = [ksave;K]; %#ok 77 | end 78 | % Note: Till this point, all the online simulation is finished. 79 | 80 | SimResults.psave = psave; 81 | SimResults.ksave = ksave; 82 | SimResults.xsave = Xsave; 83 | SimResults.tsave = tsave; 84 | 85 | % Generate figures 86 | SimResults.hFigs = LocalPostProcess(Params, ... 87 | t, Xsave, tsave, p, psave(1,:), K_old,K, numAIter); 88 | end 89 | 90 | 91 | %% -------------------------------------------------------------- 92 | % LocalOnlineDateCollection: 93 | % Local function for simulation and online data collection 94 | % ------------------------------------------------------------------------ 95 | function [Phi, Xi, Theta, Xsave, tsave, t, X] = LocalOnlineDataCollection(T, NumIntervals, X, Xsave, tsave, j, Params, K) 96 | Phi=[]; Xi=[]; Theta=[]; % Matricies to collect online data 97 | for i = 0:NumIntervals - 1 98 | [t,X] = ode45(@(t,x) FTSystemWrapper(t,x,Params,K), ... 99 | [i,(i+1)]*T+(j-1)*NumIntervals*T,... 100 | [X(end,1:2) zeros(1,35+9)]); 101 | Phi = [Phi;X(end,2+1:2+34+9)]; 102 | Xi = [Xi;X(end,end)]; 103 | Theta = [Theta; BasisQuadPhiX(X(end,1),X(end,2))'-BasisQuadPhiX(X(1,1),X(1,2))']; 104 | Xsave = [Xsave; X(:,1:2)]; 105 | tsave = [tsave; t(:)]; 106 | end 107 | end 108 | 109 | %% -------------------------------------------------------------- 110 | % LocalOnlinePolicyIteratoin: 111 | % Local function for implementing online SOS policy iteration. 112 | % Note: This does not require the system dynamics 113 | % ------------------------------------------------------------------------ 114 | function [p,K] = LocalOnlinePolicyIteratoin(Theta, Xi, Phi, p0, c) 115 | cvx_begin sdp 116 | % cvx_precision best 117 | variable p(12,1) 118 | variable P(5,5) symmetric 119 | variable L(9,9) symmetric 120 | % Obj: min integral{V(x)} on the set Omega 121 | % The objective is equivalently converted to 122 | % min c'*[x]_{1,5} 123 | minimize(c'*p) 124 | 125 | % 1) Equality constraint: 126 | % Given p (V(x)), L and K can be uniquelly determined 127 | LandK = (Phi'*Phi)\(Phi'*(-Xi-Theta*p)); 128 | 129 | l = LandK(1:25); 130 | K = [LandK(26:34)'; LandK(35:43)']; 131 | 132 | % 2) SOS contraint: 133 | % l'*[x] = -dV/dx (f+gu) - r(x,u) is SOS 134 | l == [L(1,1); 135 | L(1,2)+L(2,1); 136 | L(2,2); 137 | L(1,3)+L(3,1); 138 | L(1,4)+L(4,1)+L(2,3)+L(3,2); 139 | L(1,5)+L(5,1)+L(2,4)+L(4,2); 140 | L(2,5)+L(5,2); 141 | L(1,6)+L(6,1)+L(3,3); 142 | L(1,7)+L(7,1)+L(2,6)+L(6,2)+L(3,4)+L(4,3); 143 | L(1,8)+L(8,1)+L(2,7)+L(7,2)+L(3,5)+L(5,3)+L(4,4); 144 | L(1,9)+L(9,1)+L(2,8)+L(8,2)+L(5,4)+L(4,5); 145 | L(2,9)+L(9,2)+L(5,5); 146 | L(3,6)+L(6,3); 147 | L(3,7)+L(7,3)+L(4,6)+L(6,4); 148 | L(3,8)+L(8,3)+L(4,7)+L(7,4)+L(5,6)+L(6,5); 149 | L(3,9)+L(9,3)+L(4,8)+L(8,4)+L(5,7)+L(7,5); 150 | L(4,9)+L(9,4)+L(5,8)+L(8,5); 151 | L(5,9)+L(9,5); 152 | L(6,6); 153 | L(6,7)+L(7,6); 154 | L(6,8)+L(8,6)+L(7,7); 155 | L(6,9)+L(9,6)+L(7,8)+L(8,7); 156 | L(7,9)+L(9,7)+L(8,8); 157 | L(9,8)+L(8,9); 158 | L(9,9)]; 159 | L>=0; 160 | 161 | % 3) SOS constraint: 162 | % V(x) <= V_old(x) 163 | (p - p0) == [P(1,1) 164 | P(2,1) + P(1,2) 165 | P(2,2) 166 | P(1,3) + P(3,1) 167 | P(1,4) + P(4,1) + P(2,3) + P(3,2) 168 | P(1,5) + P(5,1) + P(2,4) + P(4,2) 169 | P(2,5) + P(5,2) 170 | P(3,3) 171 | P(3,4) + P(4,3) 172 | P(3,5) + P(5,3)+P(4,4) 173 | P(4,5) + P(5,4) 174 | P(5,5)]; 175 | P <= 0; 176 | 177 | cvx_end 178 | end 179 | 180 | function p = LocalInitialValueControlPair(Params) 181 | K = [Params.K0 zeros(2,7)]; 182 | 183 | cvx_begin sdp 184 | cvx_precision best 185 | variable P(5,5) symmetric 186 | variable L(9,9) symmetric 187 | variable L1(9,9) symmetric 188 | variable L2(9,9) symmetric 189 | 190 | p = [P(1,1) P(2,1)+P(1,2) P(2,2) P(1,3)+P(3,1) P(1,4)+P(4,1)+P(2,3)+P(3,2) P(1,5)+P(5,1)+P(2,4)+P(4,2) P(2,5)+P(5,2) P(3,3) P(3,4)+P(4,3) P(3,5)+P(5,3)+P(4,4) P(4,5)+P(5,4) P(5,5)]'; 191 | W = [2*p(1) p(2) 3*p(4) 2*p(5) p(6) 4*p(8) 3*p(9) 2*p(10) p(11); 192 | p(2) 2*p(3) p(5) 2*p(6) 3*p(7) p(9) 2*p(10) 3*p(11) 4*p(12)]; 193 | P >= 0; 194 | 195 | % Gl 196 | H1 = (1/2*W'*(Params.F+Params.Gl*K)+1/2*(Params.F+Params.Gl*K)'*W)+Params.Q+K'*Params.R*K; 197 | L1(1,1)==H1(1,1); 198 | L1(1,2)+L1(2,1)==H1(1,2)+H1(2,1); 199 | L1(2,2)==H1(2,2); 200 | L1(1,3)+L1(3,1)==H1(1,3)+H1(3,1); 201 | L1(1,4)+L1(4,1)+L1(2,3)+L1(3,2)==H1(1,4)+H1(4,1)+H1(2,3)+H1(3,2); 202 | L1(1,5)+L1(5,1)+L1(2,4)+L1(4,2)==H1(1,5)+H1(5,1)+H1(2,4)+H1(4,2); 203 | L1(2,5)+L1(5,2)==H1(2,5)+H1(5,2); 204 | L1(1,6)+L1(6,1)+L1(3,3)== H1(1,6)+H1(6,1)+H1(3,3); 205 | L1(1,7)+L1(7,1)+L1(2,6)+L1(6,2)+L1(3,4)+L1(4,3)==H1(1,7)+H1(7,1)+H1(2,6)+H1(6,2)+H1(3,4)+H1(4,3); 206 | L1(1,8)+L1(8,1)+L1(2,7)+L1(7,2)+L1(3,5)+L1(5,3)+L1(4,4)==H1(1,8)+H1(8,1)+H1(2,7)+H1(7,2)+H1(3,5)+H1(5,3)+H1(4,4); 207 | L1(1,9)+L1(9,1)+L1(2,8)+L1(8,2)+L1(5,4)+L1(4,5)==H1(1,9)+H1(9,1)+H1(2,8)+H1(8,2)+H1(5,4)+H1(4,5); 208 | L1(2,9)+L1(9,2)+L1(5,5)==H1(2,9)+H1(9,2)+H1(5,5); 209 | L1(3,6)+L1(6,3)==H1(3,6)+H1(6,3); 210 | L1(3,7)+L1(7,3)+L1(4,6)+L1(6,4)==H1(3,7)+H1(7,3)+H1(4,6)+H1(6,4); 211 | L1(3,8)+L1(8,3)+L1(4,7)+L1(7,4)+L1(5,6)+L1(6,5)==H1(3,8)+H1(8,3)+H1(4,7)+H1(7,4)+H1(5,6)+H1(6,5); 212 | L1(3,9)+L1(9,3)+L1(4,8)+L1(8,4)+L1(5,7)+L1(7,5)==H1(3,9)+H1(9,3)+H1(4,8)+H1(8,4)+H1(5,7)+H1(7,5); 213 | L1(4,9)+L1(9,4)+L1(5,8)+L1(8,5)==H1(4,9)+H1(9,4)+H1(5,8)+H1(8,5); 214 | L1(5,9)+L1(9,5)==H1(5,9)+H1(9,5); 215 | L1(6,6)==H1(6,6); 216 | L1(6,7)+L1(7,6)==H1(6,7)+H1(7,6); 217 | L1(6,8)+L1(8,6)+L1(7,7)==H1(6,8)+H1(8,6)+H1(7,7); 218 | L1(6,9)+L1(9,6)+L1(7,8)+L1(8,7)==H1(6,9)+H1(9,6)+H1(7,8)+H1(8,7); 219 | L1(7,9)+L1(9,7)+L1(8,8)==H1(7,9)+H1(9,7)+H1(8,8); 220 | L1(9,8)+L1(8,9)==H1(9,8)+H1(8,9); 221 | L1(9,9)==H1(9,9); 222 | L1<=0; 223 | 224 | % Gu 225 | H2 = (1/2*W'*(Params.F+Params.Gu*K)+1/2*(Params.F+Params.Gu*K)'*W)+Params.Q+K'*Params.R*K; 226 | L2(1,1)==H2(1,1); 227 | L2(1,2)+L2(2,1)==H2(1,2)+H2(2,1); 228 | L2(2,2)==H2(2,2); 229 | L2(1,3)+L2(3,1)==H2(1,3)+H2(3,1); 230 | L2(1,4)+L2(4,1)+L2(2,3)+L2(3,2)==H2(1,4)+H2(4,1)+H2(2,3)+H2(3,2); 231 | L2(1,5)+L2(5,1)+L2(2,4)+L2(4,2)==H2(1,5)+H2(5,1)+H2(2,4)+H2(4,2); 232 | L2(2,5)+L2(5,2)==H2(2,5)+H2(5,2); 233 | L2(1,6)+L2(6,1)+L2(3,3)== H2(1,6)+H2(6,1)+H2(3,3); 234 | L2(1,7)+L2(7,1)+L2(2,6)+L2(6,2)+L2(3,4)+L2(4,3)==H2(1,7)+H2(7,1)+H2(2,6)+H2(6,2)+H2(3,4)+H2(4,3); 235 | L2(1,8)+L2(8,1)+L2(2,7)+L2(7,2)+L2(3,5)+L2(5,3)+L2(4,4)==H2(1,8)+H2(8,1)+H2(2,7)+H2(7,2)+H2(3,5)+H2(5,3)+H2(4,4); 236 | L2(1,9)+L2(9,1)+L2(2,8)+L2(8,2)+L2(5,4)+L2(4,5)==H2(1,9)+H2(9,1)+H2(2,8)+H2(8,2)+H2(5,4)+H2(4,5); 237 | L2(2,9)+L2(9,2)+L2(5,5)==H2(2,9)+H2(9,2)+H2(5,5); 238 | L2(3,6)+L2(6,3)==H2(3,6)+H2(6,3); 239 | L2(3,7)+L2(7,3)+L2(4,6)+L2(6,4)==H2(3,7)+H2(7,3)+H2(4,6)+H2(6,4); 240 | L2(3,8)+L2(8,3)+L2(4,7)+L2(7,4)+L2(5,6)+L2(6,5)==H2(3,8)+H2(8,3)+H2(4,7)+H2(7,4)+H2(5,6)+H2(6,5); 241 | L2(3,9)+L2(9,3)+L2(4,8)+L2(8,4)+L2(5,7)+L2(7,5)==H2(3,9)+H2(9,3)+H2(4,8)+H2(8,4)+H2(5,7)+H2(7,5); 242 | L2(4,9)+L2(9,4)+L2(5,8)+L2(8,5)==H2(4,9)+H2(9,4)+H2(5,8)+H2(8,5); 243 | L2(5,9)+L2(9,5)==H2(5,9)+H2(9,5); 244 | L2(6,6)==H2(6,6); 245 | L2(6,7)+L2(7,6)==H2(6,7)+H2(7,6); 246 | L2(6,8)+L2(8,6)+L2(7,7)==H2(6,8)+H2(8,6)+H2(7,7); 247 | L2(6,9)+L2(9,6)+L2(7,8)+L2(8,7)==H2(6,9)+H2(9,6)+H2(7,8)+H2(8,7); 248 | L2(7,9)+L2(9,7)+L2(8,8)==H2(7,9)+H2(9,7)+H2(8,8); 249 | L2(9,8)+L2(8,9)==H2(9,8)+H2(8,9); 250 | L2(9,9)==H2(9,9); 251 | L2<=0; 252 | 253 | cvx_end 254 | end 255 | 256 | %% -------------------------------------------------------------- 257 | % LocalComputeObjectiveFcn: - Compute Coefficients for the objective 258 | % functioin in SOSp PI 259 | % ------------------------------------------------------------------------ 260 | function c = LocalComputeObjectiveFcn(x1min, x1max, x2min, x2max) 261 | % In the SOS-base Policy Iteration, we need to solve an SOSp in each 262 | % iteraton. The objective of the SOSp is 263 | % 264 | % min integration{V(x)}_Omega 265 | % 266 | % where Omega is a compact set, an area of interested of the system 267 | % performance. 268 | 269 | syms x1 x2 270 | v_basis_fcn = BasisQuadPhiX(x1,x2); 271 | c = double(int(int(v_basis_fcn,x1min,x1max),x2min,x2max)); 272 | end 273 | 274 | 275 | %% -------------------------------------------------------------- 276 | % LocalPostProcess - Post process data and plot the resuts 277 | % ------------------------------------------------------------------------ 278 | function hFigs = LocalPostProcess(Params, t, Xsave, tsave, p, p1, K_old,Knew, numAIter) 279 | close all 280 | 281 | [t,x] = ode45(@(t,x)FTSys(x, Params, Knew),[t(end) 30], Xsave(end,:)); 282 | tsave = [tsave;t(:)]; 283 | Xsave = [Xsave; x]; 284 | 285 | x00 = Xsave(end,:) + [5,10]; % coordinate transform 286 | [t,x] = ode45(@(t,x)FTSys(x, Params, Knew),[30 35], x00); 287 | tsave = [tsave;t(:)]; 288 | Xsave = [Xsave; x]; 289 | 290 | [t,x] = ode45(@(t,x)FTSys(x, Params, K_old),[30 35], x00); 291 | 292 | % Figure 1. Plot state trajectories 293 | h1 = figure(1); 294 | subplot(2,2,1) 295 | plot(tsave,Xsave(:,1), 'b-','Linewidth', 2) 296 | axis([0 35 -3 7]) 297 | legend('With GADP-based controller') 298 | xlabel('time (sec)') 299 | ylabel('x_1') 300 | 301 | subplot(2,2,2) 302 | plot(tsave,Xsave(:,1),'b-',t,x(:,1),'r-.', 'Linewidth', 2) 303 | legend('With GADP-based controller', 'With initial controller') 304 | xlabel('time (sec)') 305 | axis([29.8 30.5 -3 7]) 306 | 307 | subplot(2,2,3) 308 | plot(tsave,Xsave(:,2),'b-','Linewidth', 2) 309 | axis([0 35 -4 15]) 310 | legend('With GADP-based controller') 311 | xlabel('time (sec)') 312 | ylabel('x_2') 313 | 314 | subplot(2,2,4) 315 | plot(tsave,Xsave(:,2),'b-',t,x(:,2),'r-.', 'Linewidth', 2) 316 | axis([29.8 30.5 -4 15]) 317 | legend('With GADP-based controller', 'With initial controller') 318 | xlabel('time (sec)') 319 | 320 | % Figure 2. Plot and compare the value functions 321 | h2 = figure(2); 322 | x1 = (-10:1:10)/100; 323 | x2 = (-10:1:10)/100; 324 | vn = zeros(length(x1),length(x2)); 325 | v1 = zeros(length(x1),length(x2)); 326 | vs = []; us = []; un = []; 327 | kn = vn; 328 | k1 = v1; 329 | for i=1:length(x1) 330 | for j=1:length(x2) 331 | vn(i,j) = p(:)'*BasisQuadPhiX(x1(i),x2(j)); 332 | v1(i,j) = p1(:)'*BasisQuadPhiX(x1(i),x2(j)); 333 | k1(i,j) = norm([K_old(1,:)*BasisPlanMono(x1(i),x2(j)), ... 334 | K_old(2,:)*BasisPlanMono(x1(i),x2(j))]); 335 | kn(i,j) = norm([Knew(1,:)*BasisPlanMono(x1(i),x2(j)), ... 336 | Knew(2,:)*BasisPlanMono(x1(i),x2(j))]); 337 | end 338 | end 339 | surf(x1,x2,vn') 340 | hold on 341 | surf(x1,x2,v1') 342 | hold off 343 | xlabel('x_1', 'FontSize', 12) 344 | ylabel('x_2', 'FontSize', 12) 345 | % Create axes 346 | view(gca,[-40.5 14]); 347 | annotation(gcf,'textarrow',[0.216071428571429 0.174535137214669],... 348 | [0.845238095238095 0.731440045897881], ... 349 | 'TextEdgeColor','none','FontSize',12,... 350 | 'String',{'V_0(x1,x2)'}); 351 | annotation(gcf,'textarrow',[0.132142857142857 0.159949345986154],... 352 | [0.140476190476191 0.257882960413087], ... 353 | 'TextEdgeColor','none','FontSize',12,... 354 | 'String',{sprintf('V_%d(x1,x2)',numAIter)}); 355 | 356 | % Figure 3. Plot the control curve 357 | h3 = figure(3); 358 | surf(x1,x2,kn') 359 | hold on 360 | surf(x1,x2,k1') 361 | hold off 362 | xlabel('x_1') 363 | ylabel('x_2') 364 | annotation(gcf,'textarrow',[0.216071428571429 0.174535137214669],... 365 | [0.845238095238095 0.731440045897881], ... 366 | 'TextEdgeColor','none','FontSize',12,... 367 | 'String',{'|u_1|^2'}); 368 | annotation(gcf,'textarrow',[0.132142857142857 0.159949345986154],... 369 | [0.140476190476191 0.257882960413087], ... 370 | 'TextEdgeColor','none','FontSize',12,... 371 | 'String',{sprintf('|u_%d|^2',numAIter)}); 372 | %export_fig Ex2_control -pdf -transparent 373 | hFigs = [h1;h2;h3]; 374 | end 375 | 376 | %% Basic Minomial Functions are defined in separated files 377 | % Basis for system dynamics and controller 378 | % dx = F*sigma + G*u 379 | % u = K*sigma; 380 | % Basis for V(x) 381 | 382 | 383 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/ExplNoise.m: -------------------------------------------------------------------------------- 1 | function [e1,e2] = ExplNoise(t) 2 | %% -------------------------------------------------------------- 3 | % ExplNoise: 4 | % Function to generate Exploration Noise 5 | % ------------------------------------------------------------------------ 6 | e1 = 10*sum(sin([38.1558 76.5517 79.5200 18.6873 48.9764 44.5586 64.6313 70.9365 75.4687 27.6025]*t)); 7 | e2 = 20*sum(sin([17.9703 15.5098 -33.7388 -38.1002 100 45.9744 -15.9614 8.5268 -27.6188 25.1267]*t)); 8 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/FTSys.m: -------------------------------------------------------------------------------- 1 | function dx = FTSys(x, Params, K) 2 | %% -------------------------------------------------------------- 3 | % FTSys - The actual system dynamics 4 | % ------------------------------------------------------------------------ 5 | Fc = Params.F + Params.G*K; 6 | dx = Fc*BasisPlanMono(x(1),x(2)); 7 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/FTSystemWrapper.m: -------------------------------------------------------------------------------- 1 | function dxx = FTSystemWrapper(t,x,Params,K) 2 | %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % FTSystemWrapper: System Dynamics with external integrators for learning 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | % Create local copies of the parameters 6 | [F,G,Q,R] = deal(Params.F,Params.G,Params.Q,Params.R); 7 | 8 | [e1,e2] = ExplNoise(t); 9 | xm = BasisPlanMono(x(1),x(2)); 10 | u = K*xm + [e1;e2]; 11 | 12 | dx = F*xm + G*u; 13 | dphi = [BasisQuadPlantMono(x(1),x(2));2*e1*R*xm;2*e2*R*xm]; 14 | dQ = xm'*(Q+K'*R*K)*xm; 15 | 16 | dxx=[dx;dphi;dQ]; %size 2+ 34 +1 = 37 17 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/figures/Ch4_Ex3_V.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example3/figures/Ch4_Ex3_V.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/figures/Ch4_Ex3_u.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example3/figures/Ch4_Ex3_u.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/figures/Ch4_Ex3_x.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example3/figures/Ch4_Ex3_x.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main_01.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main_02.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example3/html/Ch4Ex3_main_03.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example4/Ch4Ex4_main.m: -------------------------------------------------------------------------------- 1 | function SimResults = Ch4Ex4_main() 2 | %% Global Adaptive Dynamic Programming for an inverted pendulum 3 | % 4 | % System requirements: 5 | % 6 | % - MATLAB (Manually Tested in MATLAB R2014b) 7 | % 8 | % - MATLAB Symbolic Toolbox 9 | % 10 | % - CVX (free to download at http://cvxr.com/cvx/) 11 | % 12 | % You can download CVX along with the examples, unzip tools.zip to 13 | % the root level folder of the examples. Then, run the following 14 | % 15 | % >> run('.\tools\cvx-w64\cvx\cvx_setup.m') 16 | % 17 | % >> run('.\tools\cvx-w64\cvx\cvx_startup.m') 18 | % 19 | % 20 | % Copyright 2015 Yu Jiang 21 | % 22 | % Contact: yu.jiang@nyu.edu (Yu Jiang) 23 | 24 | SimResults = []; 25 | k = 1; 26 | m = 1; % Mass of the pendulum 27 | l = 1; % Length of the pendulum 28 | g = 9.8; % Gravity accelaration rate 29 | Params.F = [0 1 0 ; 0 -k*l/m g ]; 30 | Params.G = [0; 1/m]; 31 | Params.Q = diag([10 10 0]); % Weighting matrix 32 | Params.R = 1; % Weighting matrix 33 | Params.Noise = 1; 34 | x = [-1.5 1]; % Initial Contidition; 35 | Params.x0 = x; 36 | 37 | K = [-10 -1 -15]; % Initial Feedback gains 38 | Psave = []; 39 | Ksave = K; 40 | xsave = []; 41 | tsave = []; 42 | 43 | T = 0.01; % Length of time interval for data collection 44 | P_old = 1000*eye(2); % Initializing the previous Value function 45 | P = 0.9*P_old; % Initialize the current Value function 46 | c = [1 0 1]; % Coefficient for SOS policy iteration 47 | 48 | NumDataIntv = 50; 49 | Iter = 0; 50 | Tol = 0.1; 51 | while norm(P_old - P)> Tol 52 | P_old = P; 53 | % Online Simulation for Data collection 54 | Theta = []; Xi = []; Phi = []; % Data matrices 55 | for IterIntv = 0:NumDataIntv - 1 56 | [t,x] = ode45(@(t,x) LocalInvertedPendulumSysWrapper(t,x,K,Params), ... 57 | ([IterIntv, IterIntv + 1] + NumDataIntv * Iter) * T,... 58 | [x(end,1:2) zeros(1,10)]); 59 | Theta = [Theta; x(end,1)^2-x(1,1)^2 x(end,1)*x(end,2)-x(1,1)*x(1,2) x(end,2)^2-x(1,2)^2]; 60 | Phi = [Phi; x(end,3:8) -2*x(end,9:11)]; 61 | Xi = [Xi; x(end,12)]; 62 | xsave = [xsave; x(:,1:2)]; 63 | tsave = [tsave;t]; 64 | end 65 | 66 | % Online SOSp based policy iteration 67 | [P,K] = LocalOnlinePolicyIteration(Theta,Xi,Phi,P_old,c); 68 | 69 | % Save results 70 | Psave = [Psave; P(:)']; 71 | Ksave = [Ksave; K(:)']; 72 | Iter = Iter + 1; 73 | end 74 | Params.Noise = 0; 75 | 76 | % Post learning simulation 77 | [t,x] = ode45(@(t,x) LocalInvertedPendulumSysWrapper(t,x,K,Params), ... 78 | [tsave(end) 5],[x(end,1:2) zeros(1,10)]'); 79 | xsave = [xsave; x(:,1:2)]; 80 | tsave = [tsave;t]; 81 | 82 | % Create Simulation output data 83 | SimResults.xsave = xsave; 84 | SimResults.tsave = tsave; 85 | SimResults.Psave = Psave; 86 | SimResults.Ksave = Ksave; 87 | SimResults.P = P; 88 | SimResults.Iter = Iter; 89 | 90 | % Plot results 91 | LocalPostProcessData(Params,SimResults); 92 | end 93 | 94 | %% LocalOnlinePolicyIteration: Implement online SOS policy iteration 95 | function [P,K] = LocalOnlinePolicyIteration(Theta,Xi,Phi,P_old,c) 96 | cvx_begin sdp 97 | variables p(3,1) 98 | variables bt r1 r2 r3 r4 r5 r6 99 | % Objective of the SDP 100 | minimize(c*p) 101 | 102 | % 1) Equality constraint to calculate L and K 103 | LandK = pinv(Phi)*(Xi + Theta*p); 104 | 105 | % 2) Inequality constraint 106 | L = LandK(1:6); 107 | dFGQR = [L(1) L(2)/2 L(4)/2; 108 | L(2)/2 L(3) L(5)/2; 109 | L(4)/2 L(5)/2 L(6)]; 110 | O = [0 0 bt; 111 | 0 0 0; 112 | bt 0 0]; 113 | bt>=0; 114 | gamma1 = [r1 0 r2/2; 0 0 0; r2/2 0 0]; 115 | gamma2 = [r3 0 0; 0 0 0; 0 0 r4]; 116 | gamma3 = [0 0 r5/2; 0 0 0; r5/2 0 r6]; 117 | r1 >= 0; 118 | r3 >= 0; 119 | r5 >= 0; 120 | r1+r2 >= 0; 121 | r3+r4 >= 0; 122 | r5+r6 >= 0; 123 | dFGQR + O + gamma1 + gamma2 + gamma3 <= 0; 124 | 125 | % 3) Inequality constraint 126 | P = [p(1) p(2)/2; 127 | p(2)/2 p(3)]; 128 | P_old - P >= 0; 129 | cvx_end; 130 | 131 | K = LandK(7:9)'; 132 | end 133 | 134 | %% invertedPendulumSys: Inverted Pendulum System Dynamics 135 | function dx = LocalInvertedPendulumSys(x,K,Params) 136 | u = K * LocalSigma(x); 137 | dx = Params.F * LocalSigma(x) + Params.G * u; 138 | end 139 | 140 | %% LocalInvertedPendulumSysWrapper: 141 | % Inverted Pendulum System Dynamics with external states for learning purpose 142 | function dx = LocalInvertedPendulumSysWrapper(t,x,K,Params) 143 | x1 = x(1); 144 | x2 = x(2); 145 | sgm = [x1;x2;sin(x1)]; 146 | 147 | e = LocalExplNoise(t) * Params.Noise; 148 | u = K * sgm+e; 149 | dx = Params.F * sgm + Params.G * u; 150 | 151 | dZ = [x1*x1 x2*x1 x2*x2 x1*sin(x1) x2*sin(x1) sin(x1)^2]'; 152 | deZ = sgm*e; 153 | 154 | Qk = Params.Q + K'*Params.R*K; 155 | dQ = sgm' * Qk * sgm; 156 | dx = [dx; %2 157 | dZ; %6 158 | deZ; %3 159 | dQ; %1 160 | ]; %12 161 | end 162 | 163 | %% LocalSigma: Basic function for the plant 164 | function y = LocalSigma(x) 165 | y = [x(1) x(2) sin(x(1))]'; 166 | end 167 | 168 | %% LocalExplNoise: Generate exploration noise 169 | function e = LocalExplNoise(t) 170 | e = sin(10*t) + sin(3*t) + sin(50*t) - sin(10*t) + sin(0.7*t) - sin(100*t); 171 | end 172 | 173 | %% LocalPostProcessData - Plot results after all simulation is finished 174 | function LocalPostProcessData(Params,SimResults) 175 | tsave = SimResults.tsave; 176 | xsave = SimResults.xsave; 177 | Ksave = SimResults.Ksave; 178 | Psave = SimResults.Psave; 179 | P = SimResults.P; 180 | x1 = -2:0.2:2; 181 | x2 = -5:0.5:5; 182 | vn = zeros(length(x1),length(x2)); 183 | v1 = zeros(length(x1),length(x2)); 184 | P1 = [Psave(1,1) Psave(1,2);Psave(1,3) Psave(1,4)] ; 185 | for i=1:length(x1) 186 | for j=1:length(x2) 187 | vn(i,j)=[x1(i) x2(j)]*P*[x1(i) x2(j)]'; 188 | v1(i,j)=[x1(i) x2(j)]*P1*[x1(i) x2(j)]'; 189 | end 190 | end 191 | figure(1) 192 | surf(x1,x2,vn') 193 | hold on 194 | surf(x1,x2,v1') 195 | hold off 196 | xlabel('x_1') 197 | ylabel('x_2') 198 | 199 | K = Ksave(1,:);[t1,y1]=ode45(@(t,x) LocalInvertedPendulumSys(x,K,Params), ... 200 | [0 5],Params.x0); 201 | %% 202 | figure(2) 203 | subplot(211) 204 | plot(tsave,xsave(:,1),'b-',t1,y1(:,1),'r-.','Linewidth',2) 205 | axis([0 5 -2 2]) 206 | ylabel('x_1') 207 | xlabel('time (sec)') 208 | legend('With GADP-based controller','With initial controller') 209 | subplot(212) 210 | plot(tsave,xsave(:,2),'b-',t1,y1(:,2),'r-.','Linewidth',2) 211 | axis([0 5 -4 6]) 212 | legend('With GADP-based controller','With initial controller') 213 | ylabel('x_2') 214 | xlabel('time (sec)') 215 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example4/figures/Ch4_Ex4_V.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example4/figures/Ch4_Ex4_V.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter4_Example4/figures/Ch4_Ex4_x.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter4_Example4/figures/Ch4_Ex4_x.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/Ch5Ex1_main.m: -------------------------------------------------------------------------------- 1 | %% RADP for synchronous machines 2 | % Instantiate the parameter manager 3 | pmgr = paramMgr.getInstance(); 4 | 5 | % Simulatin of 0<= t <= 1 when the system is on steady state. 6 | opt = odeset('OutputFcn',@createAnimation); 7 | 8 | [tt1,XX1] = ode45(@(t,x) syncMachine(t,x,pmgr), ... 9 | [0,1], ... 10 | zeros(24+6,1)', ... 11 | opt); 12 | 13 | % Adding perturbation at t = 1, simulate untill t = 2. 14 | [tt2,XX2] = ode45(@(t,x) syncMachine(t,x,pmgr), ... 15 | [1,2], ... 16 | 2*[0 0 .1 0 0 0.1 zeros(1,18) 0 0 .1 0 0 0.1]',opt); 17 | 18 | % Concatinate the simulatoin results on the first two intervals 19 | tt = [tt1;tt2]; 20 | XX = [XX1;XX2]; 21 | 22 | % Date matrices for learning 23 | Dxx=[]; 24 | Dzz=[]; 25 | Dxz=[]; 26 | Ixx=[]; 27 | Ixz=[]; 28 | Izz=[]; 29 | Izu=[]; 30 | Ixu=[]; 31 | Idx=[]; 32 | Idz=[]; 33 | Ixiu2=[]; 34 | Ixixi2=[]; 35 | Ixix2=[]; 36 | Dxixi2=[]; 37 | X = XX; 38 | 39 | % Collect data on 10 intervals 40 | for ct = 0:9 41 | % Simulation 42 | [t,X] = ode45(@(t,x) syncMachine(t,x,pmgr), ... 43 | [0,pmgr.T] + 2 + ct*pmgr.T, X(end,:)', opt); 44 | % Parse output simulation data 45 | tt = [tt;t]; %#ok 46 | XX = [XX;X]; %#ok 47 | Dxx = [Dxx;kron(X(end,1:2),X(end,1:2))-kron(X(1,1:2),X(1,1:2))]; %#ok 48 | Dzz = [Dzz;X(end,3)^2-X(1,3)^2]; %#ok 49 | Dxz = [Dxz;X(end,1:2)*X(end,3)-X(1,1:2)*X(1,3)]; %#ok 50 | Ixx = [Ixx;X(end,7:10)-X(1,7:10)]; %#ok 51 | Ixu = [Ixu;X(end,11:12)-X(1,11:12)]; %#ok 52 | Ixz = [Ixz;X(end,13:14)-X(1,13:14)]; %#ok 53 | Izz = [Izz;X(end,15)-X(1,15)]; %#ok 54 | Izu = [Izu;X(end,16)-X(1,16)]; %#ok 55 | Idx = [Idx;X(end,17:18)-X(1,17:18)]; %#ok 56 | Idz = [Idz;X(end,19)-X(1,19)]; %#ok 57 | Ixiu2 = [Ixiu2;X(end,21)-X(1,21)]; %#ok 58 | Ixixi2 = [Ixixi2;X(end,22)-X(1,22)]; %#ok 59 | Ixix2 = [Ixix2;X(end,23:24)-X(1,23:24)]; %#ok 60 | Dxixi2 =[Dxixi2; X(end,20)^2-X(1,20)^2]; %#ok 61 | end 62 | 63 | % For Phase-One Learning 64 | D = 0.3*eye(2); 65 | Q = [5 0; 0 0.0001]; 66 | R = 1; 67 | K = [1 1]; 68 | Pold = -100*eye(2); 69 | P = zeros(2); 70 | Psave = []; 71 | it1 = 0; 72 | [K0,P0,E0] = lqr(pmgr.A1(1:2,1:2),pmgr.A1(1:2,3),Q,R); 73 | 74 | while norm(P-Pold)>1e-8 75 | it1 = it1+1; 76 | Pold = P; 77 | theta = [Dxx(:,[1,2,4]) -2*Ixx*kron(eye(2),K')-2*(Ixz+Idx)]; 78 | Qk = Q + K'*R*K; 79 | Xi = -Ixx*Qk(:); 80 | PL = theta \ Xi; 81 | P = [PL(1) PL(2)/2; 82 | PL(2)/2 PL(3)]; 83 | 84 | L = PL(4:5)'; 85 | K = R \ L; 86 | end 87 | 88 | %% For Phase-Two Learning 89 | %K=K0;P=P0; 90 | B = pmgr.A1(1:2,3); 91 | H = 0; 92 | G = 1/pmgr.T1; 93 | F = -1/pmgr.T1; 94 | Dc = 0+ G\K*(P\K'); 95 | W = 0.1; 96 | V = 1.7438e-004; 97 | 98 | M = 10*K*(P\K'*R); 99 | Dxixi = Dzz + 2*Dxz*K'+ Dxx*kron(K',K'); 100 | Ixixi = Izz + 2*Ixz*K'+ Ixx*kron(K',K'); 101 | Ixxi = Ixz + Ixx*kron(eye(2),K'); 102 | Idxi = Idz + Idx*K'; 103 | Ixiuk = Izu + Ixu*K'; 104 | 105 | Sold = -100*eye(2); 106 | S = zeros(1); 107 | it2 = 0; 108 | Fc = F + pmgr.K0*B; 109 | [M0,S0,E2] = lqr(Fc,G,W,V); 110 | Ssave = []; 111 | Nsave = []; 112 | Msave = norm(M-M0); 113 | 114 | while norm(Sold-S)>1e-8 115 | Sold=S; 116 | it2 = it2+1; 117 | phi = [Dxixi -2*Ixixi*M*V-2*Ixiuk*V -2*Ixxi -2*Idxi]; 118 | Wk = W + M'*V*M; 119 | psi = -Ixixi*Wk(:); 120 | SN = phi\psi; 121 | S = SN(1); 122 | M = SN(2); 123 | N = SN(3:4)'; 124 | L = SN(5); 125 | end 126 | 127 | pmgr.KM = [(M*V)\(N+K)+M*K M]; 128 | 129 | N0 = S0*(pmgr.K0*(pmgr.A1(1:2,1:2)-B*pmgr.K0)); 130 | KM0 = [(M0*V)\(N0+pmgr.K0)+M0*pmgr.K0 M0]; 131 | KM = [(M*V)\(N+K)+M*K M]; 132 | 133 | % Post learning simulation 134 | [t,X]=ode45(@(t,x) syncMachine(t,x,pmgr),[tt(end) 15],XX(end,:)', opt); 135 | XX = [XX;X]; 136 | tt = [tt;t]; 137 | 138 | %% Plot results 139 | figure(2) 140 | subplot(211) 141 | plot(tt,(XX(:,1) + pmgr.angle10)*180/pi,tt,(XX(:,25) + pmgr.angle10)*180/pi,'r-.','Linewidth',1.5) 142 | legend('Robust ADP','Unlearned') 143 | xlabel('time (sec)') 144 | ylabel('Rotor Angle (degree)') 145 | axis([0 10 0 120]) 146 | title('Generator 1') 147 | 148 | subplot(212) 149 | plot(tt,(XX(:,4) + pmgr.angle20)*180/pi,tt,(XX(:,28) + pmgr.angle20)*180/pi,'r-.','Linewidth',1.5) 150 | legend('Robust ADP','Unlearned') 151 | xlabel('time (sec)') 152 | ylabel('Rotor Angle (degree)') 153 | axis([0 10 60 80]) 154 | title('Generator 2') 155 | 156 | % Create textarrow 157 | annotation(figure(2),'textarrow',[0.234811165845649 0.215106732348112],... 158 | [0.187763713080168 0.244725738396624],'String',{'Disturbance injected'}); 159 | annotation(figure(2),'textarrow',[0.399014778325123 0.371100164203612],... 160 | [0.657227848101265 0.71097046413502],'String',{'Controller updated'}); 161 | annotation(figure(2),'textarrow',[0.405582922824302 0.377668308702791],... 162 | [0.171995780590716 0.22573839662447],'String',{'Controller updated'}); 163 | annotation(figure(2),'textarrow',[0.239737274220033 0.220032840722496],... 164 | [0.681434599156118 0.738396624472574],'String',{'Disturbance injected'}); 165 | 166 | figure(3) 167 | subplot(211) 168 | plot(tt,XX(:,1)/2/pi+50,tt,XX(:,25)/2/pi+50,'r-.','Linewidth',1.5) 169 | legend('Robust ADP','Unlearned') 170 | xlabel('time (sec)') 171 | ylabel('Frequency (Hz)') 172 | axis([0 10 49.8 50.2]) 173 | title('Generator 1') 174 | 175 | subplot(212) 176 | plot(tt,XX(:,5)/2/pi+50,tt,XX(:,29)/2/pi+50,'r-.','Linewidth',1.5) 177 | legend('Robust ADP','Unlearned') 178 | xlabel('time (sec)') 179 | ylabel('Frequency (Hz)') 180 | axis([0 10 49.8 50.2]) 181 | title('Generator 2') 182 | 183 | % Create textarrow 184 | annotation(figure(3),'textarrow',[0.234811165845649 0.215106732348112],... 185 | [0.187763713080168 0.244725738396624],'String',{'Disturbance injected'}); 186 | annotation(figure(3),'textarrow',[0.399014778325123 0.371100164203612],... 187 | [0.657227848101265 0.71097046413502],'String',{'Controller updated'}); 188 | annotation(figure(3),'textarrow',[0.405582922824302 0.377668308702791],... 189 | [0.171995780590716 0.22573839662447],'String',{'Controller updated'}); 190 | annotation(figure(3),'textarrow',[0.239737274220033 0.220032840722496],... 191 | [0.681434599156118 0.738396624472574],'String',{'Disturbance injected'}); 192 | 193 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/createAnimation.m: -------------------------------------------------------------------------------- 1 | function status = createAnimation(t, y, ~) 2 | persistent pmgr 3 | if isempty(pmgr) 4 | pmgr = paramMgr.getInstance(); 5 | end 6 | status = 0; 7 | if ~isempty(t) 8 | t = t(end); 9 | delta = y(1, end); 10 | delta1 = y(4, end); 11 | delta_ul = y(25, end); 12 | delta1_ul = y(28, end); 13 | hf = figure(1); 14 | ax1 = subplot(211); 15 | LocalCreateAnimation(t,pmgr.angle10,delta + pmgr.angle10, ... 16 | pmgr.angle20,delta1 + pmgr.angle20,true,1*(t>2)+1*(t>3), pmgr, hf, ax1, true, 'ADP Learning') 17 | 18 | ax2 = subplot(212); 19 | LocalCreateAnimation(t,pmgr.angle10,delta_ul + pmgr.angle10, ... 20 | pmgr.angle20,delta1_ul + pmgr.angle20,true,0, pmgr, hf, ax2, false, 'Unlearned') 21 | end 22 | end 23 | 24 | 25 | function LocalCreateAnimation(t,delta,delta0,delta1,delta10,ifct,ifadp, pmgr, hf, ax, ifshowtime, caller) 26 | % utCreateAnimation creates the figure of two sync machines. 27 | 28 | B12 = pmgr.B12; 29 | B11 = pmgr.B11; 30 | Ef1 = pmgr.Ef1; 31 | Ef2 = pmgr.Ef2; 32 | 33 | % figure(1) 34 | set(hf,'color',[255,255,255]/255) 35 | %delta=1; 36 | r1=0.15; 37 | r2=0.1; 38 | theta=0:2*pi/1000:2*pi; 39 | xx1=r1*cos(theta); 40 | yy1=r1*sin(theta); 41 | xx2=r2*cos(theta); 42 | yy2=r2*sin(theta); 43 | 44 | 45 | x0=.4; 46 | y0=.4; 47 | x1=.85; 48 | y1=.4; 49 | 50 | plot(ax,xx1+x0,yy1+y0,'linewidth',1,'color',[1,0,0]) 51 | hold on 52 | 53 | plot(ax,xx2+x1,yy2+y1,'linewidth',1,'color',[1,0,0]) 54 | 55 | 56 | 57 | line([x0,x0+r1*cos(delta)],[y0,y0+r1*sin(delta)],'linewidth',2,'color',[0,.41,0]) 58 | line([x0,x0+r1*cos(delta0)],[y0,y0+r1*sin(delta0)],'linewidth',3,'color',[0,0,255]/255) 59 | 60 | 61 | 62 | %--------------------------------------------------- 63 | %----------- Draw the infinite Bus ----------------- 64 | line([.05,x0-r1],[y0,y0],'color',[0,0,0],'linewidth',2) 65 | line([.05+0.05,x0-r1-0.05],[y0,y0],'color',[0,0,0],'linewidth',4) 66 | line([.05,.05],[.2,.6],'color',[0,0,0],'linewidth',3) 67 | line([0,.05],[.2,.25],'color',[0,0,0],'linewidth',.5) 68 | line([0,.05],[.2,.25]+0.05,'color',[0,0,0],'linewidth',.5) 69 | line([0,.05],[.2,.25]+0.05+0.05,'color',[0,0,0],'linewidth',.5) 70 | line([0,.05],[.2,.25]+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 71 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 72 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 73 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 74 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 75 | %=================================================== 76 | 77 | %--------------------------------------------------- 78 | % show time 79 | if ifshowtime 80 | title(['t=',num2str(t,'%3.2f')],'fontsize',20) 81 | end 82 | %=================================================== 83 | 84 | ylabel(caller, 'fontsize',16) 85 | 86 | %--------------------------------------------------- 87 | % Draw the connection 88 | lineColor = [0, 0, 0]; 89 | if ifct==1 90 | patch([.73 .73 .87 .87]+0.05,[0.2 .25 .25 .2],[0,0,0]) 91 | % text(0.6,0.45,'Connected','fontsize',10,'color',[0,0.8,0]) 92 | %draw the connection 93 | line([.13,0.13]+0.1,[y0,y0+0.16],'color',lineColor,'linewidth',2) 94 | line([.13,0.47]+0.1,[y0+0.16,y0+0.16],'color',lineColor,'linewidth',2) 95 | line([.47,0.47]+0.1,[y0+0.16,y0],'color',lineColor,'linewidth',2) 96 | line([.57,x1-r2],[y0,y0],'color',lineColor,'linewidth',2) 97 | line([.62,0.72],[y0,y0],'color',lineColor,'linewidth',4) 98 | else 99 | patch([.73 .73 .87 .87]+0.05,[0.2 .25 .25 .2],[0,0,0]) 100 | text(0.6,0.45,'Disonnected','fontsize',10,'color',[0,0,0]) 101 | %draw the connection 102 | line([.13,0.13]+0.1,[y0,y0+0.16],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 103 | line([.13,0.47]+0.1,[y0+0.16,y0+0.16],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 104 | line([.47,0.47]+0.1,[y0+0.16,y0],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 105 | line([.57,x1-r2],[y0,y0],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 106 | %line([.62,0.72],[y0,y0],'color',lineColor,'linewidth',4,'linestyle',':') 107 | end 108 | %=================================================== 109 | 110 | 111 | if ifadp==0 112 | patch([.3 .3 .5 .5],[0.12 .2 .2 .12],[0,0,0]) 113 | end 114 | if ifadp==1 115 | patch([.3 .3 .5 .5],[0.12 .2 .2 .12],[1,0,0]) 116 | end 117 | if ifadp==2 118 | patch([.3 .3 .5 .5],[0.12 .2 .2 .12],[0,1,0]) 119 | end 120 | 121 | line([0.3,0.3]+0.1,[.2,.25],'color',[0,0,0],'linewidth',4) 122 | line([0.8,0.8]+0.05,[.25,.3],'color',[0,0,0],'linewidth',4) 123 | 124 | 125 | Pe20 = 0.1; 126 | 127 | 128 | if ifct==1 129 | Pe1=B11*Ef1*sin(delta0)+B12*Ef1*Ef2*sin(delta0-delta10); 130 | Pe2=-B12*Ef1*Ef2*sin(delta0-delta10)+Pe20; 131 | str_sta=['\Delta \delta_1=',num2str(delta0-delta,'%2.4f'),' rad']; 132 | str_p=['Pe_1=', num2str(Pe1,'%2.4f'), ' p.u.']; 133 | text(0.30,0.65,[str_sta]) 134 | text(0.31,0.60,[str_p]) 135 | 136 | line([x1,x1+r2*cos(delta1)],[y1,y1+r2*sin(delta1)],'linewidth',2,'color',[0,.41,0]) 137 | line([x1,x1+r2*cos(delta10)],[y1,y1+r2*sin(delta10)],'linewidth',3,'color',[0,0,255]/255) 138 | 139 | str_sta=['\Delta \delta_2=',num2str(delta10-delta1,'%2.4f'),' rad']; 140 | text(0.70,0.60,str_sta) 141 | str_p=['Pe_2=', num2str(Pe2,'%2.4f'), ' p.u.']; 142 | text(0.71,0.55,[str_p]) 143 | else 144 | Pe1 = B11*Ef1*sin(delta0); 145 | Pe2 = Pe20; 146 | str_sta = ['\Delta \delta_1=',num2str(delta0-delta,'%2.4f'),' rad']; 147 | str_p = ['Pe_1=', num2str(Pe1,'%2.4f'), ' p.u.']; 148 | text(0.30,0.65,[str_sta]) 149 | text(0.31,0.60,[str_p]) 150 | line([x1,x1+r2*cos(delta10)],[y1,y1+r2*sin(delta10)],'linewidth',3,'color',[0,0,255]/255) 151 | 152 | str_p = ['Pe_2=', num2str(Pe2,'%2.4f'), ' p.u.']; 153 | text(0.71,0.55,[str_p]) 154 | end 155 | 156 | 157 | if ifadp==0 158 | text(0.3,0.05,'Initial Control Law','fontsize',12,'color',[0,0,0]) 159 | end 160 | if ifadp==1 161 | text(0.3,0.05,'Online Learning','fontsize',12,'color',[.5,0,0]) 162 | end 163 | if ifadp==2 164 | text(0.3,0.05,'Post Learning','fontsize',12,'color',[0,.5,0]) 165 | end 166 | % polylogo=imread('c:\logo.jpg'); 167 | % imagesc([0.72 1],[0.08 0],polylogo); 168 | axis([0,1,0,1*.8]) 169 | axis equal 170 | axis off 171 | hold off 172 | drawnow 173 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/devel/utCreateAnimation.m: -------------------------------------------------------------------------------- 1 | function utCreateAnimation(t,delta,delta0,delta1,delta10,ifct,ifadp, pmgr) 2 | % utCreateAnimation creates the figure of two sync machines. 3 | 4 | % utCreateAnimation(0,pmgr.angle10, pmgr.angle10, pmgr.angle20,pmgr.angle20,true,-1, pmgr) 5 | 6 | B12 = pmgr.B12; 7 | B11 = pmgr.B11; 8 | Ef1 = pmgr.Ef1; 9 | Ef2 = pmgr.Ef2; 10 | 11 | figure(1) 12 | set(figure(1),'color',[255,255,255]/255) 13 | %delta=1; 14 | r1=0.15; 15 | r2=0.1; 16 | theta=0:2*pi/1000:2*pi; 17 | xx1=r1*cos(theta); 18 | yy1=r1*sin(theta); 19 | xx2=r2*cos(theta); 20 | yy2=r2*sin(theta); 21 | 22 | 23 | x0=.4; 24 | y0=.4; 25 | x1=.85; 26 | y1=.4; 27 | 28 | plot(xx1+x0,yy1+y0,'linewidth',1,'color',[1,0,0]) 29 | hold on 30 | 31 | plot(xx2+x1,yy2+y1,'linewidth',1,'color',[1,0,0]) 32 | 33 | 34 | 35 | line([x0,x0+r1*cos(delta)],[y0,y0+r1*sin(delta)],'linewidth',2,'color',[0,.41,0]) 36 | line([x0,x0+r1*cos(delta0)],[y0,y0+r1*sin(delta0)],'linewidth',3,'color',[0,0,255]/255) 37 | 38 | 39 | 40 | %--------------------------------------------------- 41 | %----------- Draw the infinite Bus ----------------- 42 | line([.05,x0-r1],[y0,y0],'color',[0,0,0],'linewidth',2) 43 | line([.05+0.05,x0-r1-0.05],[y0,y0],'color',[0,0,0],'linewidth',4) 44 | line([.05,.05],[.2,.6],'color',[0,0,0],'linewidth',3) 45 | line([0,.05],[.2,.25],'color',[0,0,0],'linewidth',.5) 46 | line([0,.05],[.2,.25]+0.05,'color',[0,0,0],'linewidth',.5) 47 | line([0,.05],[.2,.25]+0.05+0.05,'color',[0,0,0],'linewidth',.5) 48 | line([0,.05],[.2,.25]+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 49 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 50 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 51 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 52 | line([0,.05],[.2,.25]+0.05+0.05+0.05+0.05+0.05+0.05+0.05,'color',[0,0,0],'linewidth',.5) 53 | %=================================================== 54 | 55 | %--------------------------------------------------- 56 | % Draw the title 57 | title(['t=',num2str(t,'%3.2f')],'fontsize',20) 58 | %=================================================== 59 | 60 | %--------------------------------------------------- 61 | % Draw the connection 62 | lineColor = [0, 0, 0]; 63 | if ifct==1 64 | patch([.73 .73 .87 .87]+0.05,[0.2 .25 .25 .2],[0,0,0]) 65 | % text(0.6,0.45,'Connected','fontsize',10,'color',[0,0.8,0]) 66 | %draw the connection 67 | line([.13,0.13]+0.1,[y0,y0+0.16],'color',lineColor,'linewidth',2) 68 | line([.13,0.47]+0.1,[y0+0.16,y0+0.16],'color',lineColor,'linewidth',2) 69 | line([.47,0.47]+0.1,[y0+0.16,y0],'color',lineColor,'linewidth',2) 70 | line([.57,x1-r2],[y0,y0],'color',lineColor,'linewidth',2) 71 | line([.62,0.72],[y0,y0],'color',lineColor,'linewidth',4) 72 | else 73 | patch([.73 .73 .87 .87]+0.05,[0.2 .25 .25 .2],[0,0,0]) 74 | text(0.6,0.45,'Disonnected','fontsize',10,'color',[0,0,0]) 75 | %draw the connection 76 | line([.13,0.13]+0.1,[y0,y0+0.16],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 77 | line([.13,0.47]+0.1,[y0+0.16,y0+0.16],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 78 | line([.47,0.47]+0.1,[y0+0.16,y0],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 79 | line([.57,x1-r2],[y0,y0],'color',lineColor,'linewidth',2,'linestyle',':','color','c') 80 | %line([.62,0.72],[y0,y0],'color',lineColor,'linewidth',4,'linestyle',':') 81 | end 82 | %=================================================== 83 | 84 | 85 | if ifadp==1 86 | patch([.3 .3 .5 .5],[0.12 .2 .2 .12],[1,0,0]) 87 | elseif ifadp==2 88 | patch([.3 .3 .5 .5],[0.12 .2 .2 .12],[0,1,0]) 89 | else 90 | patch([.3 .3 .5 .5],[0.12 .2 .2 .12],[0,0,0]) 91 | end 92 | 93 | line([0.3,0.3]+0.1,[.2,.25],'color',[0,0,0],'linewidth',4) 94 | line([0.8,0.8]+0.05,[.25,.3],'color',[0,0,0],'linewidth',4) 95 | 96 | 97 | Pe20 = 0.1; 98 | 99 | 100 | if ifct==1 101 | Pe1=B11*Ef1*sin(delta0)+B12*Ef1*Ef2*sin(delta0-delta10); 102 | Pe2=-B12*Ef1*Ef2*sin(delta0-delta10)+Pe20; 103 | str_sta=['\Delta \delta_1=',num2str(delta0-delta,'%2.4f'),' rad']; 104 | str_p=['Pe_1=', num2str(Pe1,'%2.4f'), ' p.u.']; 105 | text(0.30,0.65,[str_sta]) 106 | text(0.31,0.60,[str_p]) 107 | 108 | line([x1,x1+r2*cos(delta1)],[y1,y1+r2*sin(delta1)],'linewidth',2,'color',[0,.41,0]) 109 | line([x1,x1+r2*cos(delta10)],[y1,y1+r2*sin(delta10)],'linewidth',3,'color',[0,0,255]/255) 110 | 111 | str_sta=['\Delta \delta_2=',num2str(delta10-delta1,'%2.4f'),' rad']; 112 | text(0.70,0.60,str_sta) 113 | str_p=['Pe_2=', num2str(Pe2,'%2.4f'), ' p.u.']; 114 | text(0.71,0.55,[str_p]) 115 | else 116 | Pe1 = B11*Ef1*sin(delta0); 117 | Pe2 = Pe20; 118 | str_sta = ['\Delta \delta_1=',num2str(delta0-delta,'%2.4f'),' rad']; 119 | str_p = ['Pe_1=', num2str(Pe1,'%2.4f'), ' p.u.']; 120 | text(0.30,0.65,[str_sta]) 121 | text(0.31,0.60,[str_p]) 122 | line([x1,x1+r2*cos(delta10)],[y1,y1+r2*sin(delta10)],'linewidth',3,'color',[0,0,255]/255) 123 | 124 | str_p = ['Pe_2=', num2str(Pe2,'%2.4f'), ' p.u.']; 125 | text(0.71,0.55,[str_p]) 126 | end 127 | 128 | 129 | if ifadp==0 130 | text(0.3,0.05,'Initial Control Law','fontsize',12,'color',[0,0,0]) 131 | end 132 | if ifadp==1 133 | text(0.3,0.05,'Online Learning','fontsize',12,'color',[.5,0,0]) 134 | end 135 | if ifadp==2 136 | text(0.3,0.05,'Post Learning','fontsize',12,'color',[0,.5,0]) 137 | end 138 | % polylogo=imread('c:\logo.jpg'); 139 | % imagesc([0.72 1],[0.08 0],polylogo); 140 | axis([0,1,0,1*.8]) 141 | axis off 142 | hold off 143 | drawnow 144 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_01.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_02.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_03.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter5_Example1/html/Ch5Ex1_main_04.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/paramMgr.m: -------------------------------------------------------------------------------- 1 | classdef (Sealed) paramMgr < handle 2 | % Singleton class to store parameters 3 | 4 | properties 5 | D1 = 1; 6 | T1 = 5; 7 | B12 = 0.06; 8 | B11 = 0.05; 9 | B22 = 0.01; 10 | w0 = 100*pi; 11 | H1 = 3; 12 | angle10 = 1; 13 | angle20 = 1.2; 14 | 15 | D2 = 2; 16 | T2 = 5; 17 | H2 = 3; 18 | Ef1 = 2; 19 | Ef2 = 3; 20 | 21 | K1 = [-1 -2 0]; 22 | KM = zeros(1,3); 23 | Q = 300*eye(3); 24 | x0 = [0.1;0;0]; 25 | z0 = [0.5;-1;0]; 26 | 27 | K2 = [-10 -10 -10]; 28 | 29 | A1 30 | B1 31 | A2 32 | B2 33 | 34 | % Initial gain 35 | K0 = [2.2361 0.2891]; 36 | 37 | % For exploration noise 38 | w = [-1.8902 0.2456 0.4173 -0.6776 -0.6973 -0.6715 0.1009 -0.4142 -1.2529 -1.2968]; 39 | oscTstart = 2; 40 | connectTstart = 5; 41 | 42 | % Learning 43 | T = 0.1; 44 | end 45 | 46 | methods (Access = private) 47 | function this = paramMgr() 48 | % disp('Creating a new parameter manager'); 49 | Initialize(this) 50 | end 51 | end 52 | 53 | methods (Static) 54 | function this = getInstance() 55 | persistent localObj 56 | if isempty(localObj) || isvalid(localObj) 57 | localObj = paramMgr; 58 | end 59 | this = localObj; 60 | end 61 | end 62 | end 63 | 64 | function Initialize(this) 65 | this.A1 = [0 1 0; 66 | 0 -this.D1/2/this.H1 this.w0/2/this.H1; 67 | 0 0 -1/this.T1]; 68 | this.B1 = [0; 0; 1/this.T1]; 69 | % this.K1 = lqr(this.A1,this.B1,this.Q,1); 70 | this.A2 = [0 1 0; 71 | 0 -this.D2/2/this.H2 this.w0/2/this.H2; 72 | 0 0 -1/this.T2]; 73 | 74 | this.B2 = [0; 0; 1/this.T2]; 75 | %this.K2 = lqr(this.A2,this.B2,0.5*[1 0 0;0 1 0;0 0 1],10); 76 | 77 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example1/syncMachine.m: -------------------------------------------------------------------------------- 1 | function dxx = syncMachine(t,xx, pmgr) 2 | 3 | xx = xx(:); 4 | 5 | % states of the physical machines 6 | x = xx(1:3); 7 | e = xx(4:6); 8 | 9 | % Power deviation 10 | Pd = pmgr.B11*pmgr.Ef1*pmgr.Ef2*(sin(x(1) + ... 11 | pmgr.angle10 - e(1) - pmgr.angle20) - ... 12 | sin(pmgr.angle10 - pmgr.angle20)); 13 | 14 | if t<3 15 | u = pmgr.K1*x + 0.1*sin(100*t); 16 | else 17 | u = -pmgr.KM*x; 18 | end 19 | 20 | dx = pmgr.A1*x + pmgr.B1*u - [0; Pd*pmgr.w0/2/pmgr.H1;0]; 21 | 22 | % System decomposition 23 | A = pmgr.A1(1:2,1:2); 24 | B = pmgr.A1(1:2,3); 25 | F = pmgr.A1(3,3); 26 | G = pmgr.B1(3); 27 | 28 | xi = xx(20); 29 | dxi = (pmgr.K0*(A-B*pmgr.K0)-F*pmgr.K0)*x(1:2) + (F + pmgr.K0*B)*xi + G*u; 30 | 31 | % Dynamics of the following machine 32 | de = (pmgr.A2 + pmgr.B2*pmgr.K2)*e + [0;Pd*pmgr.w0/2/pmgr.H2;0]; 33 | 34 | % Prepare the integrators for learning purpose 35 | dIxx = kron(x(1:2),x(1:2)); 36 | dIxu = x(1:2)*(u); 37 | dIzz = x(3)^2; 38 | dIxz = x(1:2)*x(3); 39 | dIzu = x(3)*(u); 40 | dIdx = x(1:2)*(-Pd); 41 | dIdz = x(3)*(-Pd); 42 | dIxiu = xi*u; 43 | dIxixi = xi*xi; 44 | dIxix = xi*x(1:2); 45 | xc = xx(25:27); 46 | ec = xx(28:30); 47 | 48 | % 49 | Pdc = pmgr.B11*pmgr.Ef1*pmgr.Ef2*(sin(xc(1) + pmgr.angle10 - ... 50 | ec(1) - pmgr.angle20) - sin(pmgr.angle10 - pmgr.angle20)); 51 | dxc = (pmgr.A1+pmgr.B1*pmgr.K1)*xc-[0;Pdc*pmgr.w0/2/pmgr.H1;0]; 52 | dec = (pmgr.A2+pmgr.B2*pmgr.K2)*ec+[0;Pdc*pmgr.w0/2/pmgr.H2;0]; 53 | 54 | 55 | dxx = [dx; 56 | de; 57 | dIxx; 58 | dIxu; 59 | dIxz; 60 | dIzz; 61 | dIzu; 62 | dIdx; 63 | dIdz; 64 | dxi; 65 | dIxiu; 66 | dIxixi; 67 | dIxix; 68 | dxc; 69 | dec]; 70 | 71 | %% Old implementation 72 | % x = xx(1:3); 73 | % z = xx(4:6); 74 | % 75 | % if t >= pmgr.oscTstart 76 | % u = sum(sin(pmgr.w*10*t))/5 - pmgr.K1*x; 77 | % else 78 | % u = -pmgr.K1*x; 79 | % end 80 | % 81 | % dIxx = kron(x,x); 82 | % dIxu = kron(x,u); 83 | % 84 | % if t >= pmgr.connectTstart 85 | % dx = (pmgr.A1 - pmgr.B1*pmgr.K1)*x + ... 86 | % [0;0;1]*(pmgr.B11*pmgr.Ef1*cos(x(1) - pmgr.angle10)*x(2) + pmgr.B12*pmgr.Ef1*pmgr.Ef2*cos(x(1)-z(1) - pmgr.angle10 + pmgr.angle20)*(x(2)-z(2))); 87 | % dz = (pmgr.A2 - pmgr.B2*pmgr.K2)*z + ... 88 | % [0;0;1]*(pmgr.B22*pmgr.Ef2*cos(z(1) - pmgr.angle20)*z(2) + pmgr.B12*pmgr.Ef1*pmgr.Ef2*cos(z(1)-x(1) + pmgr.angle10 - pmgr.angle20)*(z(2)-x(2))); 89 | % else 90 | % dx = pmgr.A1*x + pmgr.B1*u; 91 | % dz = zeros(3,1); 92 | % end 93 | % 94 | % dxx = [dx; 95 | % dz; 96 | % dIxx; 97 | % dIxu]; 98 | 99 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example2/Ch5Ex2_main.m: -------------------------------------------------------------------------------- 1 | %% Global Robust Adaptive Dynamic Programming 2 | global W W1 F Q noise_on rho 3 | rho = 0.5 ; % Robust Redesign Gain 4 | 5 | F = [0 -3/2 -1/2]; 6 | Q = [5 0 0;0 0 0;0 0 0]; 7 | W = [2 -1.4 -.45]; 8 | wsave = W; 9 | W1 = W; 10 | P = eye(2)*10; 11 | Pold = -100*eye(2); 12 | noise_on=1; 13 | 14 | Psave=[]; 15 | Qsave=[]; 16 | ua=[]; 17 | 18 | Trjsave=[]; 19 | Tsave=[]; 20 | 21 | T=0.005; 22 | xinit=-10; 23 | rinit=5; 24 | x=[xinit;zeros(9,1);rinit]'; 25 | for i=0:9 26 | %CXX=[]; 27 | C1=[]; 28 | C2=[]; 29 | C3=[]; 30 | CQ=[]; 31 | %CZZ=[]; 32 | %x=[1;zeros(9,1)]'; 33 | for j=0:49 34 | [t,x] = ode45(@polysys,[j*T,j*T+T]+50*i*T,[x(end,1) zeros(1,9) x(end,11)]'); 35 | %[t,x] = ode_yuri(j*T,j*T+T,[x(end,1) zeros(1,9)]',0.001); 36 | C1 = [C1; 1/2*(x(end,1)^2-x(1,1)^2) 1/3*(x(end,1)^3-x(1,1)^3) 1/4*(x(end,1)^4-x(1,1)^4)]; 37 | C2 = [C2; x(end,2:6)]; 38 | C3 = [C3; x(end,7:9)]; 39 | CQ = [CQ; x(end,10)]; 40 | Tsave=[Tsave;t]; 41 | Trjsave=[Trjsave;x(:,[1 11])]; 42 | for k=1:length(t) 43 | ua=[ua; W(:)'*x(k,1).^[1 2 3]'+(0.01*sin(10*t(k))+0.01*sin(3*t(k))+0.01*sin(100*t(k)))*noise_on]; 44 | end 45 | end 46 | 47 | if norm(P(:)-Pold(:))>0.1 48 | cvx_begin sdp 49 | variable Wn(3,1) 50 | variable dQs(3,3) symmetric 51 | Qv=-([C2 -C3]'*[C2 -C3])\[C2 -C3]'*(CQ+C1*Wn(:)); 52 | dQs(1,1)==Qv(1); 53 | dQs(1,2)+dQs(2,1)==Qv(2); 54 | dQs(1,3)+dQs(3,1)+dQs(2,2)==Qv(3); 55 | dQs(3,2)+dQs(2,3)==Qv(4); 56 | dQs(3,3)==Qv(5); 57 | dQs>=0; 58 | Pn = [1/2*(Wn(1)) 1/6*(Wn(2)); 1/6*(Wn(2)) 1/4*(Wn(3))]; 59 | Pn<=P; 60 | 61 | %minimize([-1 100]*Pn*[-1 ;100]+[1 100]*Pn*[1 ;100]) 62 | minimize(Pn(1,1)+Pn(2,2)) 63 | W=Qv(6:8); 64 | wsave=[wsave;W(:)' ]; 65 | cvx_end 66 | noise_on=1; 67 | Psave=[Psave;P(:)']; 68 | Qsave=[Qsave;dQs(:)']; 69 | Pold=P; 70 | P=Pn; 71 | else 72 | noise_on=0; 73 | disp(num2str(i)) 74 | end 75 | 76 | 77 | 78 | end 79 | Psave 80 | Qsave; 81 | %% 82 | figure(1) 83 | [t0,y0] = ode45(@polysys0,[0 Tsave(end)],[xinit, rinit]); 84 | for i=1:length(t0) 85 | u0(i) = W1*y0(i,1).^[1 2 3]'; 86 | end 87 | plot(Tsave,Trjsave(:,1), 'b-', t0,y0(:,1), 'r-.', 'linewidth', 2) 88 | legend('With GRADP-based controller', 'With initial controller') 89 | xlabel('time (sec)') 90 | ylabel('\phi') 91 | ylim([-12 5]) 92 | % Create textarrow 93 | annotation(figure(1),'textarrow',[0.267857142857143 0.228200808625336],... 94 | [0.245238095238095 0.433832086450543],'String',{'1st iteration'},... 95 | 'FontSize',12); 96 | 97 | % Create textarrow 98 | annotation(figure(1),'textarrow',[0.351785714285714 0.291071428571429],... 99 | [0.511904761904762 0.666666666666667],'String',{'2nd iteration'},... 100 | 'FontSize',12); 101 | 102 | % Create textarrow 103 | annotation(figure(1),'textarrow',[0.38409703504043 0.386738544474392],... 104 | [0.763163519772001 0.700619878874244],'String',{'3rd iteration'},... 105 | 'FontSize',12); 106 | 107 | % Create textarrow 108 | annotation(figure(1),'textarrow',[0.603571428571428 0.535714285714285],... 109 | [0.533333333333334 0.673809523809524],'String',{'5th (final) iteration'},... 110 | 'FontSize',12); 111 | 112 | % Create textarrow 113 | annotation(figure(1),'textarrow',[0.480357142857143 0.427966101694915],... 114 | [0.528571428571429 0.669064748201439],'String',{'4th iteration'},... 115 | 'FontSize',12); 116 | 117 | 118 | 119 | figure(2) 120 | plot(Tsave,Trjsave(:,2), 'b-', t0,y0(:,2), 'r-.', 'linewidth', 2) 121 | legend('With GRADP-based controller', 'With initial controller') 122 | xlabel('time (sec)') 123 | ylabel('r') 124 | ylim([-1 5]) 125 | % Create textarrow 126 | annotation(figure(2),'textarrow',[0.243684992570579 0.1996691805209],... 127 | [0.676982591876209 0.278255039384132],'String',{'1st iteration'},... 128 | 'FontSize',12); 129 | 130 | % Create textarrow 131 | annotation(figure(2),'textarrow',[0.325408618127786 0.287523619950097],... 132 | [0.560928433268859 0.281012459180867],'String',{'2nd iteration'},... 133 | 'FontSize',12); 134 | 135 | % Create textarrow 136 | annotation(figure(2),'textarrow',[0.407132243684993 0.373938714289719],... 137 | [0.502901353965184 0.289622365749069],'String',{'3rd iteration'},... 138 | 'FontSize',12); 139 | 140 | % Create textarrow 141 | annotation(figure(2),'textarrow',[0.473997028231798 0.450802097059071],... 142 | [0.433268858800774 0.291719058253785],'String',{'4th iteration'},... 143 | 'FontSize',12); 144 | 145 | % Create textarrow 146 | annotation(figure(2),'textarrow',[0.592867756315007 0.537890044576523],... 147 | [0.586073500967118 0.286266924564797],'String',{'5th (final) iteration'},... 148 | 'FontSize',12); 149 | 150 | 151 | 152 | % % 153 | syms v(y) 154 | %vsx=dsolve(diff(v)*(F(1)*y+F(2)*y^2+F(3)*y^3)+0.01*(y^2+y^4)-1/4*(diff(v))^2==0, v(0)==0) 155 | 156 | %x=-1.5:0.05:1.5; 157 | x=-2.5:.01:2.5; 158 | vn=[]; 159 | v1=[]; 160 | vs=[]; 161 | us=[]; 162 | u1=[]; 163 | un=[]; 164 | P1=[Psave(2,1) Psave(2,2);Psave(2,3) Psave(2,4)] ; 165 | 166 | vsxt=0; 167 | for i=1:length(x)-1 168 | y=x(i); 169 | vn=[vn [y y^2]*P*[y ;y^2]]; 170 | v1=[v1 [y y^2]*P1*[y ;y^2]]; 171 | %vsx=(y^2 + 2)^(3/2)/15 - (2*2^(1/2))/15 - y^2/10; 172 | 173 | vsx = 2.0*y*(0.25*y^4 + 1.5*y^3 + 2.25*y^2 + 5.0)^(1/2) - 3.0*y^2 - 1.0*y^3; 174 | vsxt = vsxt+vsx*(x(i+1)-x(i)); 175 | % vsx=y^3/150 + (101*y^2 + 100)^(3/2)/15150 - 20/303; 176 | vs=[vs vsxt]; 177 | end 178 | 179 | figure(3) 180 | plot(x(2:end),v1,'g:',x(2:end),vn,'r-.',x(2:end),vs+21.1238,'b','linewidth',2) 181 | legend('V_1 : Initial cost', 'V^5: Improved cost', 'V^o: Optimal cost') 182 | xlabel('\phi') 183 | 184 | % figure(4) 185 | % plot(x,u1,'g:',x,un,'r-.',x,us,'b','linewidth',2) 186 | % legend('u_1: Initial control policy', 'u^5: Improved control policy', 'u^o: Optimal control policy') -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example2/control_anno.m: -------------------------------------------------------------------------------- 1 | figure1=figure(2) 2 | % Create textarrow 3 | annotation(figure1,'textarrow',[0.239092495636998 0.2107082880569],... 4 | [0.221748400852878 0.320754616656652],'TextEdgeColor','none','FontSize',12,... 5 | 'String',{'1st iteration'}); 6 | 7 | % Create textarrow 8 | annotation(figure1,'textarrow',[0.396160558464223 0.361981626000198],... 9 | [0.176972281449893 0.27332776800004],'TextEdgeColor','none','FontSize',12,... 10 | 'String',{'3rd iteration'}); 11 | 12 | % Create textarrow 13 | annotation(figure1,'textarrow',[0.331588132635253 0.2999993414337],... 14 | [0.439232409381663 0.335385523398326],'TextEdgeColor','none','FontSize',12,... 15 | 'String',{'2nd iteration'}); 16 | 17 | % Create textarrow 18 | annotation(figure1,'textarrow',[0.471204188481675 0.443631993150911],... 19 | [0.37953091684435 0.304862789720793],'TextEdgeColor','none','FontSize',12,... 20 | 'String',{'4th iteration'}); 21 | 22 | % Create textarrow 23 | annotation(figure1,'textarrow',[0.598603839441536 0.527216569528138],... 24 | [0.388059701492537 0.306982330953],'TextEdgeColor','none','FontSize',12,... 25 | 'String',{'5th (final) iteration'}); 26 | 27 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example2/figures/Ch5_Ex2_u_curve.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: MATLAB, The MathWorks, Inc. Version 7.14.0.739 (R2012a). Operating System: Microsoft Windows 7. 3 | %%Title: C:\Users\Yuri\Dropbox\00 work\01 work archive\2013-08\scalar\Ex1_control_curve.eps 4 | %%CreationDate: 11/12/2013 15:00:48 5 | %%DocumentNeededFonts: Helvetica 6 | %%DocumentProcessColors: Cyan Magenta Yellow Black 7 | %%LanguageLevel: 2 8 | %%Pages: 1 9 | %%BoundingBox: 90 235 519 556 10 | %%EndComments 11 | 12 | %%BeginProlog 13 | % MathWorks dictionary 14 | /MathWorks 160 dict begin 15 | % definition operators 16 | /bdef {bind def} bind def 17 | /ldef {load def} bind def 18 | /xdef {exch def} bdef 19 | /xstore {exch store} bdef 20 | % operator abbreviations 21 | /c /clip ldef 22 | /cc /concat ldef 23 | /cp /closepath ldef 24 | /gr /grestore ldef 25 | /gs /gsave ldef 26 | /mt /moveto ldef 27 | /np /newpath ldef 28 | /cm /currentmatrix ldef 29 | /sm /setmatrix ldef 30 | /rm /rmoveto ldef 31 | /rl /rlineto ldef 32 | /s {show newpath} bdef 33 | /sc {setcmykcolor} bdef 34 | /sr /setrgbcolor ldef 35 | /sg /setgray ldef 36 | /w /setlinewidth ldef 37 | /j /setlinejoin ldef 38 | /cap /setlinecap ldef 39 | /rc {rectclip} bdef 40 | /rf {rectfill} bdef 41 | % page state control 42 | /pgsv () def 43 | /bpage {/pgsv save def} bdef 44 | /epage {pgsv restore} bdef 45 | /bplot /gsave ldef 46 | /eplot {stroke grestore} bdef 47 | % orientation switch 48 | /portraitMode 0 def /landscapeMode 1 def /rotateMode 2 def 49 | % coordinate system mappings 50 | /dpi2point 0 def 51 | % font control 52 | /FontSize 0 def 53 | /FMS {/FontSize xstore findfont [FontSize 0 0 FontSize neg 0 0] 54 | makefont setfont} bdef 55 | /ISOLatin1Encoding where {pop /WindowsLatin1Encoding 256 array bdef 56 | ISOLatin1Encoding WindowsLatin1Encoding copy pop 57 | /.notdef/.notdef/quotesinglbase/florin/quotedblbase/ellipsis/dagger 58 | /daggerdbl/circumflex/perthousand/Scaron/guilsinglleft/OE/.notdef/.notdef 59 | /.notdef/.notdef/quoteleft/quoteright/quotedblleft/quotedblright/bullet 60 | /endash/emdash/tilde/trademark/scaron/guilsinglright/oe/.notdef/.notdef 61 | /Ydieresis WindowsLatin1Encoding 128 32 getinterval astore pop} 62 | {/WindowsLatin1Encoding StandardEncoding bdef} ifelse 63 | /reencode {exch dup where {pop load} {pop StandardEncoding} ifelse 64 | exch dup 3 1 roll findfont dup length dict begin 65 | { 1 index /FID ne {def}{pop pop} ifelse } forall 66 | /Encoding exch def currentdict end definefont pop} bdef 67 | /isroman {findfont /CharStrings get /Agrave known} bdef 68 | /FMSR {3 1 roll 1 index dup isroman {reencode} {pop pop} ifelse 69 | exch FMS} bdef 70 | /csm {1 dpi2point div -1 dpi2point div scale neg translate 71 | dup landscapeMode eq {pop -90 rotate} 72 | {rotateMode eq {90 rotate} if} ifelse} bdef 73 | % line types: solid, dotted, dashed, dotdash 74 | /SO { [] 0 setdash } bdef 75 | /DO { [.5 dpi2point mul 4 dpi2point mul] 0 setdash } bdef 76 | /DA { [6 dpi2point mul] 0 setdash } bdef 77 | /DD { [.5 dpi2point mul 4 dpi2point mul 6 dpi2point mul 4 78 | dpi2point mul] 0 setdash } bdef 79 | % macros for lines and objects 80 | /L {lineto stroke} bdef 81 | /MP {3 1 roll moveto 1 sub {rlineto} repeat} bdef 82 | /AP {{rlineto} repeat} bdef 83 | /PDlw -1 def 84 | /W {/PDlw currentlinewidth def setlinewidth} def 85 | /PP {closepath eofill} bdef 86 | /DP {closepath stroke} bdef 87 | /MR {4 -2 roll moveto dup 0 exch rlineto exch 0 rlineto 88 | neg 0 exch rlineto closepath} bdef 89 | /FR {MR stroke} bdef 90 | /PR {MR fill} bdef 91 | /L1i {{currentfile picstr readhexstring pop} image} bdef 92 | /tMatrix matrix def 93 | /MakeOval {newpath tMatrix currentmatrix pop translate scale 94 | 0 0 1 0 360 arc tMatrix setmatrix} bdef 95 | /FO {MakeOval stroke} bdef 96 | /PO {MakeOval fill} bdef 97 | /PD {currentlinewidth 2 div 0 360 arc fill 98 | PDlw -1 eq not {PDlw w /PDlw -1 def} if} def 99 | /FA {newpath tMatrix currentmatrix pop translate scale 100 | 0 0 1 5 -2 roll arc tMatrix setmatrix stroke} bdef 101 | /PA {newpath tMatrix currentmatrix pop translate 0 0 moveto scale 102 | 0 0 1 5 -2 roll arc closepath tMatrix setmatrix fill} bdef 103 | /FAn {newpath tMatrix currentmatrix pop translate scale 104 | 0 0 1 5 -2 roll arcn tMatrix setmatrix stroke} bdef 105 | /PAn {newpath tMatrix currentmatrix pop translate 0 0 moveto scale 106 | 0 0 1 5 -2 roll arcn closepath tMatrix setmatrix fill} bdef 107 | /vradius 0 def /hradius 0 def /lry 0 def 108 | /lrx 0 def /uly 0 def /ulx 0 def /rad 0 def 109 | /MRR {/vradius xdef /hradius xdef /lry xdef /lrx xdef /uly xdef 110 | /ulx xdef newpath tMatrix currentmatrix pop ulx hradius add uly 111 | vradius add translate hradius vradius scale 0 0 1 180 270 arc 112 | tMatrix setmatrix lrx hradius sub uly vradius add translate 113 | hradius vradius scale 0 0 1 270 360 arc tMatrix setmatrix 114 | lrx hradius sub lry vradius sub translate hradius vradius scale 115 | 0 0 1 0 90 arc tMatrix setmatrix ulx hradius add lry vradius sub 116 | translate hradius vradius scale 0 0 1 90 180 arc tMatrix setmatrix 117 | closepath} bdef 118 | /FRR {MRR stroke } bdef 119 | /PRR {MRR fill } bdef 120 | /MlrRR {/lry xdef /lrx xdef /uly xdef /ulx xdef /rad lry uly sub 2 div def 121 | newpath tMatrix currentmatrix pop ulx rad add uly rad add translate 122 | rad rad scale 0 0 1 90 270 arc tMatrix setmatrix lrx rad sub lry rad 123 | sub translate rad rad scale 0 0 1 270 90 arc tMatrix setmatrix 124 | closepath} bdef 125 | /FlrRR {MlrRR stroke } bdef 126 | /PlrRR {MlrRR fill } bdef 127 | /MtbRR {/lry xdef /lrx xdef /uly xdef /ulx xdef /rad lrx ulx sub 2 div def 128 | newpath tMatrix currentmatrix pop ulx rad add uly rad add translate 129 | rad rad scale 0 0 1 180 360 arc tMatrix setmatrix lrx rad sub lry rad 130 | sub translate rad rad scale 0 0 1 0 180 arc tMatrix setmatrix 131 | closepath} bdef 132 | /FtbRR {MtbRR stroke } bdef 133 | /PtbRR {MtbRR fill } bdef 134 | /stri 6 array def /dtri 6 array def 135 | /smat 6 array def /dmat 6 array def 136 | /tmat1 6 array def /tmat2 6 array def /dif 3 array def 137 | /asub {/ind2 exch def /ind1 exch def dup dup 138 | ind1 get exch ind2 get sub exch } bdef 139 | /tri_to_matrix { 140 | 2 0 asub 3 1 asub 4 0 asub 5 1 asub 141 | dup 0 get exch 1 get 7 -1 roll astore } bdef 142 | /compute_transform { 143 | dmat dtri tri_to_matrix tmat1 invertmatrix 144 | smat stri tri_to_matrix tmat2 concatmatrix } bdef 145 | /ds {stri astore pop} bdef 146 | /dt {dtri astore pop} bdef 147 | /db {2 copy /cols xdef /rows xdef mul dup 3 mul string 148 | currentfile 149 | 3 index 0 eq {/ASCIIHexDecode filter} 150 | {/ASCII85Decode filter 3 index 2 eq {/RunLengthDecode filter} if } 151 | ifelse exch readstring pop 152 | dup 0 3 index getinterval /rbmap xdef 153 | dup 2 index dup getinterval /gbmap xdef 154 | 1 index dup 2 mul exch getinterval /bbmap xdef pop pop}bdef 155 | /it {gs np dtri aload pop moveto lineto lineto cp c 156 | cols rows 8 compute_transform 157 | rbmap gbmap bbmap true 3 colorimage gr}bdef 158 | /il {newpath moveto lineto stroke}bdef 159 | currentdict end def 160 | %%EndProlog 161 | 162 | %%BeginSetup 163 | MathWorks begin 164 | 165 | 0 cap 166 | 167 | end 168 | %%EndSetup 169 | 170 | %%Page: 1 1 171 | %%BeginPageSetup 172 | %%PageBoundingBox: 90 235 519 556 173 | MathWorks begin 174 | bpage 175 | %%EndPageSetup 176 | 177 | %%BeginObject: obj1 178 | bplot 179 | 180 | /dpi2point 12 def 181 | portraitMode 1080 6672 csm 182 | 183 | 0 0 5157 3851 rc 184 | 85 dict begin %Colortable dictionary 185 | /c0 { 0.000000 0.000000 0.000000 sr} bdef 186 | /c1 { 1.000000 1.000000 1.000000 sr} bdef 187 | /c2 { 0.900000 0.000000 0.000000 sr} bdef 188 | /c3 { 0.000000 0.820000 0.000000 sr} bdef 189 | /c4 { 0.000000 0.000000 0.800000 sr} bdef 190 | /c5 { 0.910000 0.820000 0.320000 sr} bdef 191 | /c6 { 1.000000 0.260000 0.820000 sr} bdef 192 | /c7 { 0.000000 0.820000 0.820000 sr} bdef 193 | c0 194 | 1 j 195 | 1 sg 196 | 0 0 5158 3852 rf 197 | 6 w 198 | 0 3138 3997 0 0 -3138 670 3427 4 MP 199 | PP 200 | -3997 0 0 3138 3997 0 0 -3138 670 3427 5 MP stroke 201 | 4 w 202 | DO 203 | SO 204 | 6 w 205 | 0 sg 206 | 670 289 mt 4667 289 L 207 | 670 3427 mt 4667 3427 L 208 | 4667 3427 mt 4667 289 L 209 | 670 3427 mt 670 289 L 210 | 670 3427 mt 4667 3427 L 211 | 670 3427 mt 670 289 L 212 | 670 3427 mt 670 3387 L 213 | 670 289 mt 670 328 L 214 | %%IncludeResource: font Helvetica 215 | /Helvetica /WindowsLatin1Encoding 120 FMSR 216 | 217 | 517 3572 mt 218 | (-2.5) s 219 | 1069 3427 mt 1069 3387 L 220 | 1069 289 mt 1069 328 L 221 | 966 3572 mt 222 | (-2) s 223 | 1469 3427 mt 1469 3387 L 224 | 1469 289 mt 1469 328 L 225 | 1316 3572 mt 226 | (-1.5) s 227 | 1869 3427 mt 1869 3387 L 228 | 1869 289 mt 1869 328 L 229 | 1766 3572 mt 230 | (-1) s 231 | 2268 3427 mt 2268 3387 L 232 | 2268 289 mt 2268 328 L 233 | 2115 3572 mt 234 | (-0.5) s 235 | 2668 3427 mt 2668 3387 L 236 | 2668 289 mt 2668 328 L 237 | 2635 3572 mt 238 | (0) s 239 | 3068 3427 mt 3068 3387 L 240 | 3068 289 mt 3068 328 L 241 | 2985 3572 mt 242 | (0.5) s 243 | 3467 3427 mt 3467 3387 L 244 | 3467 289 mt 3467 328 L 245 | 3434 3572 mt 246 | (1) s 247 | 3867 3427 mt 3867 3387 L 248 | 3867 289 mt 3867 328 L 249 | 3784 3572 mt 250 | (1.5) s 251 | 4267 3427 mt 4267 3387 L 252 | 4267 289 mt 4267 328 L 253 | 4234 3572 mt 254 | (2) s 255 | 4667 3427 mt 4667 3387 L 256 | 4667 289 mt 4667 328 L 257 | 4584 3572 mt 258 | (2.5) s 259 | 670 3427 mt 709 3427 L 260 | 4667 3427 mt 4627 3427 L 261 | 499 3471 mt 262 | (-1) s 263 | 670 3113 mt 709 3113 L 264 | 4667 3113 mt 4627 3113 L 265 | 399 3157 mt 266 | (-0.8) s 267 | 670 2799 mt 709 2799 L 268 | 4667 2799 mt 4627 2799 L 269 | 399 2843 mt 270 | (-0.6) s 271 | 670 2485 mt 709 2485 L 272 | 4667 2485 mt 4627 2485 L 273 | 399 2529 mt 274 | (-0.4) s 275 | 670 2171 mt 709 2171 L 276 | 4667 2171 mt 4627 2171 L 277 | 399 2215 mt 278 | (-0.2) s 279 | 670 1858 mt 709 1858 L 280 | 4667 1858 mt 4627 1858 L 281 | 569 1902 mt 282 | (0) s 283 | 670 1544 mt 709 1544 L 284 | 4667 1544 mt 4627 1544 L 285 | 469 1588 mt 286 | (0.2) s 287 | 670 1230 mt 709 1230 L 288 | 4667 1230 mt 4627 1230 L 289 | 469 1274 mt 290 | (0.4) s 291 | 670 916 mt 709 916 L 292 | 4667 916 mt 4627 916 L 293 | 469 960 mt 294 | (0.6) s 295 | 670 602 mt 709 602 L 296 | 4667 602 mt 4627 602 L 297 | 469 646 mt 298 | (0.8) s 299 | 670 289 mt 709 289 L 300 | 4667 289 mt 4627 289 L 301 | 569 333 mt 302 | (1) s 303 | 670 289 mt 4667 289 L 304 | 670 3427 mt 4667 3427 L 305 | 4667 3427 mt 4667 289 L 306 | 670 3427 mt 670 289 L 307 | gs 670 289 3998 3139 rc 308 | DO 309 | 24 w 310 | 8 2 8 2 8 3 8 2 8 2 8 2 8 2 8 2 311 | 8 3 8 2 8 2 8 2 8 2 8 2 8 2 8 2 312 | 8 2 8 3 8 2 8 2 8 2 8 2 8 2 8 2 313 | 8 2 8 2 8 2 8 2 8 1 8 2 8 2 8 2 314 | 8 2 8 2 8 2 8 2 8 2 8 1 8 2 8 2 315 | 8 2 8 2 8 2 8 1 8 2 8 2 8 2 8 1 316 | 8 2 8 2 8 2 8 1 8 2 8 2 8 1 8 2 317 | 8 2 8 1 8 2 8 2 8 1 8 2 8 1 8 2 318 | 8 2 8 1 8 2 8 1 8 2 8 2 8 1 8 2 319 | 8 1 8 2 8 1 8 2 8 1 8 2 8 1 8 2 320 | 8 1 8 2 8 1 8 1 8 2 8 1 8 2 8 1 321 | 8 1 8 2 8 1 8 2 8 1 8 1 8 2 8 1 322 | 8 1 8 2 8 1 8 1 8 2 8 1 8 1 8 2 323 | 8 1 8 1 8 1 8 2 8 1 8 1 8 1 8 2 324 | 8 1 8 1 8 1 8 2 8 1 8 1 8 1 8 1 325 | 8 1 8 2 8 1 8 1 8 1 8 1 8 1 8 2 326 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 327 | 8 2 8 1 8 1 8 1 8 1 8 1 8 1 8 1 328 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 329 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 330 | 8 1 8 1 8 1 8 1 8 1 8 1 7 1 8 1 331 | 8 1 8 1 8 1 8 1 8 1 8 0 8 1 8 1 332 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 0 333 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 0 334 | 8 1 8 1 8 1 8 1 8 1 8 1 8 0 8 1 335 | 8 1 8 1 8 1 8 1 8 0 8 1 8 1 8 1 336 | 8 1 8 1 8 0 8 1 8 1 8 1 8 1 8 1 337 | 8 0 8 1 8 1 8 1 8 1 8 0 8 1 8 1 338 | 8 1 8 1 8 0 8 1 8 1 8 1 8 1 8 0 339 | 8 1 8 1 8 1 8 0 8 1 8 1 8 1 8 1 340 | 8 0 8 1 8 1 8 1 8 1 8 0 8 1 8 1 341 | 8 1 8 0 8 1 8 1 8 1 8 1 8 0 8 1 342 | 8 1 8 1 8 1 8 0 8 1 8 1 8 1 8 1 343 | 8 0 8 1 8 1 8 1 8 0 8 1 8 1 8 1 344 | 8 1 8 0 8 1 8 1 8 1 8 1 8 0 8 1 345 | 8 1 8 1 8 1 8 0 8 1 8 1 8 1 8 1 346 | 8 1 8 0 8 1 8 1 8 1 8 1 8 1 8 0 347 | 8 1 8 1 8 1 2276 1818 300 MP stroke 348 | 8 1 8 1 8 0 8 1 8 1 8 1 8 1 8 1 349 | 8 1 8 0 8 1 8 1 8 1 8 1 8 1 8 1 350 | 8 1 8 0 8 1 8 1 8 1 8 1 8 1 8 1 351 | 8 1 8 1 8 1 8 0 8 1 8 1 8 1 8 1 352 | 8 1 8 1 7 1 8 1 8 1 8 1 8 1 8 1 353 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 354 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 355 | 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 356 | 8 2 8 1 8 1 8 1 8 1 8 1 8 1 8 1 357 | 8 1 8 2 8 1 8 1 8 1 8 1 8 1 8 2 358 | 8 1 8 1 8 1 8 1 8 1 8 2 8 1 8 1 359 | 8 1 8 2 8 1 8 1 8 1 8 2 8 1 8 1 360 | 8 1 8 2 8 1 8 1 8 2 8 1 8 1 8 2 361 | 8 1 8 1 8 2 8 1 8 1 8 2 8 1 8 2 362 | 8 1 8 1 8 2 8 1 8 2 8 1 8 1 8 2 363 | 8 1 8 2 8 1 8 2 8 1 8 2 8 1 8 2 364 | 8 1 8 2 8 1 8 2 8 2 8 1 8 2 8 1 365 | 8 2 8 2 8 1 8 2 8 1 8 2 8 2 8 1 366 | 8 2 8 2 8 1 8 2 8 2 8 1 8 2 8 2 367 | 8 2 8 1 8 2 8 2 8 2 8 1 8 2 8 2 368 | 8 2 8 2 8 2 8 1 8 2 8 2 8 2 8 2 369 | 8 2 8 2 8 2 8 2 8 1 8 2 8 2 8 2 370 | 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 3 371 | 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 372 | 8 3 8 2 8 2 8 2 8 2 8 2 8 3 8 2 373 | 7 2 670 1539 202 MP stroke 374 | DD 375 | /c8 { 1.000000 0.000000 0.000000 sr} bdef 376 | c8 377 | 8 14 8 15 8 14 8 14 8 14 8 14 8 14 8 14 378 | 8 14 8 13 8 14 8 13 8 14 8 13 8 13 8 13 379 | 8 13 8 13 8 13 8 12 8 13 8 13 8 12 8 12 380 | 8 13 8 12 8 12 8 12 8 12 8 11 8 12 8 12 381 | 8 11 8 12 8 11 8 11 8 11 8 11 8 11 8 11 382 | 8 11 8 11 8 10 8 11 8 10 8 11 8 10 8 10 383 | 8 11 8 10 8 10 8 10 8 9 8 10 8 10 8 9 384 | 8 10 8 9 8 10 8 9 8 9 8 9 8 9 8 9 385 | 8 9 8 9 8 9 8 8 8 9 8 9 8 8 8 8 386 | 8 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 387 | 8 7 8 8 8 8 8 7 8 8 8 7 8 7 8 8 388 | 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 6 389 | 8 7 8 7 8 6 8 7 8 6 8 7 8 6 8 6 390 | 8 6 8 6 8 7 8 6 8 5 8 6 8 6 8 6 391 | 8 6 8 5 8 6 8 6 8 5 8 5 8 6 8 5 392 | 8 5 8 6 8 5 8 5 8 5 8 5 8 5 8 5 393 | 8 5 8 5 8 4 8 5 8 5 8 4 8 5 8 4 394 | 8 5 8 4 8 5 8 4 8 4 8 5 8 4 8 4 395 | 8 4 8 4 8 4 8 4 8 4 8 4 8 4 8 3 396 | 8 4 8 4 8 4 8 3 8 4 8 3 8 4 8 3 397 | 8 4 8 3 8 4 8 3 8 3 8 4 7 3 8 3 398 | 8 3 8 3 8 3 8 3 8 3 8 3 8 3 8 3 399 | 8 3 8 3 8 3 8 3 8 2 8 3 8 3 8 2 400 | 8 3 8 3 8 2 8 3 8 2 8 3 8 2 8 3 401 | 8 2 8 3 8 2 8 2 8 3 8 2 8 2 8 2 402 | 8 3 8 2 8 2 8 2 8 2 8 3 8 2 8 2 403 | 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 404 | 8 2 8 2 8 1 8 2 8 2 8 2 8 2 8 2 405 | 8 2 8 1 8 2 8 2 8 2 8 1 8 2 8 2 406 | 8 2 8 1 8 2 8 2 8 1 8 2 8 2 8 1 407 | 8 2 8 2 8 1 8 2 8 1 8 2 8 2 8 1 408 | 8 2 8 1 8 2 8 2 8 1 8 2 8 1 8 2 409 | 8 2 8 1 8 2 8 1 8 2 8 2 8 1 8 2 410 | 8 1 8 2 8 2 8 1 8 2 8 1 8 2 8 2 411 | 8 1 8 2 8 2 8 1 8 2 8 1 8 2 8 2 412 | 8 2 8 1 8 2 8 2 8 1 8 2 8 2 8 2 413 | 8 1 8 2 8 2 8 2 8 2 8 1 8 2 8 2 414 | 8 2 8 2 8 2 2276 1775 300 MP stroke 415 | 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 416 | 8 2 8 2 8 2 8 2 8 2 8 2 8 3 8 2 417 | 8 2 8 2 8 2 8 3 8 2 8 2 8 3 8 2 418 | 8 3 8 2 8 3 8 2 8 3 8 2 8 3 8 2 419 | 8 3 8 3 7 2 8 3 8 3 8 3 8 2 8 3 420 | 8 3 8 3 8 3 8 3 8 3 8 3 8 3 8 3 421 | 8 3 8 4 8 3 8 3 8 3 8 4 8 3 8 3 422 | 8 4 8 3 8 4 8 3 8 4 8 4 8 3 8 4 423 | 8 4 8 4 8 3 8 4 8 4 8 4 8 4 8 4 424 | 8 4 8 5 8 4 8 4 8 4 8 5 8 4 8 4 425 | 8 5 8 4 8 5 8 4 8 5 8 5 8 5 8 4 426 | 8 5 8 5 8 5 8 5 8 5 8 5 8 5 8 6 427 | 8 5 8 5 8 6 8 5 8 6 8 5 8 6 8 5 428 | 8 6 8 6 8 6 8 6 8 6 8 6 8 6 8 6 429 | 8 6 8 6 8 6 8 7 8 6 8 7 8 6 8 7 430 | 8 7 8 6 8 7 8 7 8 7 8 7 8 7 8 7 431 | 8 7 8 7 8 8 8 7 8 8 8 7 8 8 8 7 432 | 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 433 | 8 8 8 9 8 8 8 9 8 8 8 9 8 9 8 9 434 | 8 9 8 8 8 10 8 9 8 9 8 9 8 9 8 10 435 | 8 9 8 10 8 10 8 9 8 10 8 10 8 10 8 10 436 | 8 10 8 10 8 11 8 10 8 11 8 10 8 11 8 11 437 | 8 10 8 11 8 11 8 11 8 11 8 12 8 11 8 11 438 | 8 12 8 12 8 11 8 12 8 12 8 12 8 12 8 12 439 | 8 12 8 12 8 13 8 12 8 13 8 13 8 12 8 13 440 | 7 13 670 540 202 MP stroke 441 | SO 442 | /c9 { 0.000000 0.000000 1.000000 sr} bdef 443 | c9 444 | 8 8 8 9 8 9 8 8 8 9 8 8 8 9 8 8 445 | 8 9 8 8 8 8 8 9 8 8 8 8 8 8 8 8 446 | 8 8 8 9 8 8 8 8 8 8 8 8 8 7 8 8 447 | 8 8 8 8 8 8 8 8 8 7 8 8 8 8 8 7 448 | 8 8 8 7 8 8 8 7 8 8 8 7 8 7 8 8 449 | 8 7 8 7 8 8 8 7 8 7 8 7 8 7 8 7 450 | 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 6 451 | 8 7 8 7 8 7 8 6 8 7 8 6 8 7 8 7 452 | 8 6 8 6 8 7 8 6 8 7 8 6 8 6 8 6 453 | 8 7 8 6 8 6 8 6 8 6 8 6 8 6 8 6 454 | 8 6 8 6 8 6 8 6 8 5 8 6 8 6 8 6 455 | 8 5 8 6 8 6 8 5 8 6 8 5 8 6 8 5 456 | 8 5 8 6 8 5 8 5 8 6 8 5 8 5 8 5 457 | 8 5 8 6 8 5 8 5 8 5 8 5 8 5 8 4 458 | 8 5 8 5 8 5 8 5 8 4 8 5 8 5 8 4 459 | 8 5 8 5 8 4 8 5 8 4 8 5 8 4 8 4 460 | 8 5 8 4 8 4 8 4 8 5 8 4 8 4 8 4 461 | 8 4 8 4 8 4 8 4 8 4 8 4 8 4 8 4 462 | 8 4 8 3 8 4 8 4 8 4 8 3 8 4 8 4 463 | 8 3 8 4 8 3 8 4 8 3 8 4 8 3 8 3 464 | 8 4 8 3 8 3 8 4 8 3 8 3 7 3 8 3 465 | 8 3 8 3 8 3 8 3 8 3 8 3 8 3 8 3 466 | 8 3 8 3 8 3 8 3 8 2 8 3 8 3 8 2 467 | 8 3 8 3 8 2 8 3 8 2 8 3 8 2 8 3 468 | 8 2 8 3 8 2 8 3 8 2 8 2 8 3 8 2 469 | 8 2 8 2 8 2 8 3 8 2 8 2 8 2 8 2 470 | 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 471 | 8 2 8 2 8 2 8 2 8 2 8 2 8 1 8 2 472 | 8 2 8 2 8 2 8 1 8 2 8 2 8 2 8 1 473 | 8 2 8 2 8 1 8 2 8 2 8 1 8 2 8 2 474 | 8 1 8 2 8 1 8 2 8 2 8 1 8 2 8 1 475 | 8 2 8 1 8 2 8 2 8 1 8 2 8 1 8 2 476 | 8 1 8 2 8 2 8 1 8 2 8 1 8 2 8 1 477 | 8 2 8 2 8 1 8 2 8 1 8 2 8 1 8 2 478 | 8 2 8 1 8 2 8 2 8 1 8 2 8 2 8 1 479 | 8 2 8 2 8 1 8 2 8 2 8 2 8 1 8 2 480 | 8 2 8 2 8 1 8 2 8 2 8 2 8 2 8 2 481 | 8 2 8 2 8 1 2276 1776 300 MP stroke 482 | 8 2 8 2 8 2 8 2 8 2 8 2 8 2 8 2 483 | 8 3 8 2 8 2 8 2 8 2 8 2 8 2 8 3 484 | 8 2 8 2 8 2 8 3 8 2 8 2 8 3 8 2 485 | 8 3 8 2 8 2 8 3 8 2 8 3 8 3 8 2 486 | 8 3 8 2 7 3 8 3 8 2 8 3 8 3 8 2 487 | 8 3 8 3 8 3 8 3 8 3 8 2 8 3 8 3 488 | 8 3 8 3 8 3 8 3 8 3 8 3 8 4 8 3 489 | 8 3 8 3 8 3 8 4 8 3 8 3 8 3 8 4 490 | 8 3 8 4 8 3 8 3 8 4 8 3 8 4 8 3 491 | 8 4 8 4 8 3 8 4 8 4 8 3 8 4 8 4 492 | 8 4 8 3 8 4 8 4 8 4 8 4 8 4 8 4 493 | 8 4 8 4 8 4 8 4 8 4 8 4 8 4 8 5 494 | 8 4 8 4 8 4 8 5 8 4 8 4 8 5 8 4 495 | 8 5 8 4 8 4 8 5 8 5 8 4 8 5 8 4 496 | 8 5 8 5 8 4 8 5 8 5 8 5 8 4 8 5 497 | 8 5 8 5 8 5 8 5 8 5 8 5 8 5 8 5 498 | 8 5 8 5 8 5 8 6 8 5 8 5 8 5 8 6 499 | 8 5 8 5 8 6 8 5 8 5 8 6 8 5 8 6 500 | 8 5 8 6 8 6 8 5 8 6 8 6 8 5 8 6 501 | 8 6 8 5 8 6 8 6 8 6 8 6 8 6 8 6 502 | 8 6 8 6 8 6 8 6 8 6 8 6 8 6 8 6 503 | 8 7 8 6 8 6 8 6 8 7 8 6 8 7 8 6 504 | 8 6 8 7 8 6 8 7 8 6 8 7 8 7 8 6 505 | 8 7 8 6 8 7 8 7 8 7 8 7 8 6 8 7 506 | 8 7 8 7 8 7 8 7 8 7 8 7 8 7 8 7 507 | 7 7 670 895 202 MP stroke 508 | gr 509 | 510 | 24 w 511 | c9 512 | 0 sg 513 | 2637 3715 mt 514 | (x) s 515 | 653 3470 mt 516 | ( ) s 517 | 4651 331 mt 518 | ( ) s 519 | 6 w 520 | 1 sg 521 | 0 626 1913 0 0 -626 2695 975 4 MP 522 | PP 523 | -1913 0 0 626 1913 0 0 -626 2695 975 5 MP stroke 524 | 4 w 525 | DO 526 | SO 527 | 6 w 528 | 0 sg 529 | 2695 349 mt 4608 349 L 530 | 2695 975 mt 4608 975 L 531 | 4608 975 mt 4608 349 L 532 | 2695 975 mt 2695 349 L 533 | 2695 975 mt 4608 975 L 534 | 2695 975 mt 2695 349 L 535 | 2695 349 mt 4608 349 L 536 | 2695 975 mt 4608 975 L 537 | 4608 975 mt 4608 349 L 538 | 2695 975 mt 2695 349 L 539 | 3167 484 mt 540 | (u) s 541 | %%IncludeResource: font Helvetica 542 | /Helvetica /WindowsLatin1Encoding 96 FMSR 543 | 544 | 3233 544 mt 545 | (1) s 546 | %%IncludeResource: font Helvetica 547 | /Helvetica /WindowsLatin1Encoding 120 FMSR 548 | 549 | 3286 484 mt 550 | (: Initial control policy) s 551 | gs 2695 349 1914 627 rc 552 | DO 553 | 24 w 554 | 363 0 2767 468 2 MP stroke 555 | SO 556 | gr 557 | 558 | 24 w 559 | 3167 686 mt 560 | (u) s 561 | %%IncludeResource: font Helvetica 562 | /Helvetica /WindowsLatin1Encoding 96 FMSR 563 | 564 | 3233 746 mt 565 | (5) s 566 | %%IncludeResource: font Helvetica 567 | /Helvetica /WindowsLatin1Encoding 120 FMSR 568 | 569 | 3286 686 mt 570 | (: Improved control policy) s 571 | gs 2695 349 1914 627 rc 572 | DD 573 | c8 574 | 363 0 2767 670 2 MP stroke 575 | SO 576 | gr 577 | 578 | c8 579 | 0 sg 580 | 3167 925 mt 581 | (u) s 582 | %%IncludeResource: font Helvetica 583 | /Helvetica /WindowsLatin1Encoding 96 FMSR 584 | 585 | 3233 865 mt 586 | (o) s 587 | %%IncludeResource: font Helvetica 588 | /Helvetica /WindowsLatin1Encoding 120 FMSR 589 | 590 | 3286 925 mt 591 | (: Optimal control policy) s 592 | gs 2695 349 1914 627 rc 593 | c9 594 | 363 0 2767 863 2 MP stroke 595 | 6 w 596 | gr 597 | 598 | 6 w 599 | c9 600 | 601 | end %%Color Dict 602 | 603 | eplot 604 | %%EndObject 605 | 606 | epage 607 | end 608 | 609 | showpage 610 | 611 | %%Trailer 612 | %%EOF 613 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example2/polysys.m: -------------------------------------------------------------------------------- 1 | function drx=polysys(t,x) 2 | global W F Q noise_on rho 3 | %F = -[1 0.1 1]; 4 | %W = [2 0 0]; 5 | x1 = x(1); 6 | r = x(11); 7 | sgm = x1.^[1 2 3]'; 8 | e = -rho*W(:)'*sgm+3*r*x(1)+3*r+2*(0.01*sin(10*t)+0.01*sin(1000*t)+0.01*sin(.3*t)+0.01*sin(.1*t))*noise_on; 9 | u = -1/2*W(:)'*sgm+e; 10 | dx = F * sgm + u; 11 | 12 | dZ = x1.^[2 3 4 5 6]'; 13 | deZ = sgm*e; 14 | dZZ = kron(sgm,sgm); 15 | Qk = Q+1/4*W(:)*W(:)'; 16 | dQ = sgm'*Qk*sgm; 17 | 18 | dr = - 0.3*r^2-0.3*r*(2*x(1)+x(1)*x(1)); 19 | 20 | drx = [dx; 21 | dZ; 22 | deZ; 23 | dQ; 24 | %dZZ 25 | dr]; % 1 + 3*3+3 =13 26 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example2/polysys0.m: -------------------------------------------------------------------------------- 1 | function drx=polysys0(t,x) 2 | global W F Q W1 rho 3 | sgm = x(1).^[1 2 3]'; 4 | r = x(end); 5 | %e = (0.01*sin(10*t)+0.01*sin(3*t)+0.01*sin(100*t))*noise_on; 6 | e = 3*r*x(1)+3*r; 7 | u = -1/2*W1(:)'*sgm-rho*W1(:)'*sgm+e; 8 | dx = F * sgm + u; 9 | dr = - 0.3*r^2-0.3*r*(2*x(1)+x(1)*x(1)); 10 | drx = [dx;dr]; 11 | 12 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter5_Example2/state_anno.m: -------------------------------------------------------------------------------- 1 | figure1=gcf; 2 | % Create textarrow 3 | annotation(figure1,'textarrow',[0.281132075471698 0.226415094339623],... 4 | [0.845386533665835 0.800498753117207],'TextEdgeColor','none','FontSize',12,... 5 | 'String',{'1st iteration'}); 6 | 7 | % Create textarrow 8 | annotation(figure1,'textarrow',[0.516981132075472 0.518490566037736],... 9 | [0.389027431421446 0.324039900249375],'TextEdgeColor','none','FontSize',12,... 10 | 'String',{'5th (final) iteration'}); 11 | 12 | % Create textarrow 13 | annotation(figure1,'textarrow',[0.443396226415094 0.44188679245283],... 14 | [0.244389027431421 0.309127182044887],'TextEdgeColor','none','FontSize',12,... 15 | 'String',{'4th iteration'}); 16 | 17 | % Create textarrow 18 | annotation(figure1,'textarrow',[0.369811320754717 0.372452830188679],... 19 | [0.448877805486284 0.386334164588527],'TextEdgeColor','none','FontSize',12,... 20 | 'String',{'3rd iteration'}); 21 | 22 | % Create textarrow 23 | annotation(figure1,'textarrow',[0.284905660377358 0.286037735849057],... 24 | [0.321695760598504 0.416408977556109],'TextEdgeColor','none','FontSize',12,... 25 | 'String',{'2nd iteration'}); 26 | 27 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/Ch6Ex1_main.m: -------------------------------------------------------------------------------- 1 | function Ch6Ex1_main() 2 | %% RADP for a ten-machine power system 3 | % This is the Matlab code used for the paper: 4 | % 5 | % Yu Jiang and Zhong-Ping Jiang, "Robust Adaptive Dynamic Programming for 6 | % Large-Scale Systems with an Application to Multimachine Power Systems," 7 | % IEEE Transactions on Circuits and Systems II: Params.Express Briefs, vol. 59, no. 8 | % 10, pp. 693-697, 2012. 9 | % 10 | % The code is free for everyone to use. Please cite the above paper in your 11 | % publication if you do use the code. 12 | % 13 | % Please contact yu.jiang@nyu.edu if you find 14 | % any bugs or have any suggestions on improving the code. Thanks! 15 | % 16 | 17 | %load the parameters 18 | Params = Local_load_params(); 19 | [Nm, pm, imxx, imuu] = deal(Params.Nm, Params.pm, Params.imxx, Params.imuu); 20 | 21 | % simulate the system until 4s 22 | % operating in steady-state from 0s to 1s 23 | % Kadp = zeros(1,3,Nm); % Preallocating. 24 | Kadp = repmat([10 50 0],[1,1,Nm-1]); 25 | disp('Simulating the system on steady state to 1s...') 26 | [t0,y0] = ode45(@(t,x) Local_mmsys_online_radp(t,x,Kadp),[0,1],zeros(15*(Nm-1),1)); 27 | 28 | % add an impulse disturbance at 1s 29 | disp('Adding an impulse disturbance at 1s and simulating to 4s...') 30 | [t1,y1]=ode45(@(t,x) Local_mmsys_online_radp(t,x,Kadp), ... 31 | [1,4],y0(end,:)'-[kron(pm(2:end),[0,0,1]),zeros(1,12*(Nm-1))]'); 32 | 33 | y = y1(end,:); 34 | N = 20; % # of learning intervals 35 | stop_tol = 0.01; % Stop criterion 36 | 37 | Ixx = zeros(N,9,Nm-1); 38 | Ixu = zeros(N,3,Nm-1); 39 | Dxx = zeros(N,6,Nm-1); 40 | 41 | yy = [y0;y1]; 42 | tt = [t0;t1]; 43 | 44 | % Simulate the system from 4s to 5s to collect enough online information 45 | % for later offpolicy learning 46 | for cti = 0:N-1 47 | disp(['simulating the ', num2str(cti+1),'-th interval...', ... 48 | num2str(N-cti), 'left']); 49 | % simulate the trajectories for learning 50 | [t,y]=ode45(@(t,x) Local_mmsys_online_radp(t,x,Kadp),[4+cti/N,4+(cti+1)/N],y(end,:)); 51 | for ctj = 1:Nm-1 52 | Ixx(cti+1,:,ctj) = y(end,imxx(ctj):imxx(ctj)+8)-y(1,imxx(ctj):imxx(ctj)+8); 53 | Ixu(cti+1,:,ctj) = y(end,imuu(ctj):imuu(ctj)+2)-y(1,imuu(ctj):imuu(ctj)+2); 54 | Dxx(cti+1,:,ctj) = [y(end,1+(ctj-1)*3)^2-y(1,1+(ctj-1)*3)^2 55 | y(end,1+(ctj-1)*3)*y(end,2+(ctj-1)*3)-y(1,1+(ctj-1)*3)*y(1,2+(ctj-1)*3) 56 | y(end,1+(ctj-1)*3)*y(end,3+(ctj-1)*3)-y(1,1+(ctj-1)*3)*y(1,3+(ctj-1)*3) 57 | y(end,2+(ctj-1)*3)^2-y(1,2+(ctj-1)*3)^2 58 | y(end,2+(ctj-1)*3)*y(end,3+(ctj-1)*3)-y(1,2+(ctj-1)*3)*y(1,3+(ctj-1)*3) 59 | y(end,3+(ctj-1)*3)^2-y(1,3+(ctj-1)*3)^2]'; 60 | end 61 | yy = [yy;y]; 62 | tt = [tt;t]; 63 | end 64 | 65 | % off-Policy learning for all Generators 66 | 67 | K = repmat([10 50 0],[1,1,Nm-1]); 68 | 69 | for ctj = 1:Nm-1 70 | Kprev = [100 100 100]; 71 | it=0; 72 | while (norm(K(:,:,ctj)-Kprev)>stop_tol) 73 | it = it+1; 74 | Kprev = K(:,:,ctj); 75 | Qk = 1000*eye(3)+K(:,:,ctj)'*K(:,:,ctj); 76 | Theta = [Dxx(:,:,ctj) -2*Ixx(:,:,ctj)*kron(eye(3),K(:,:,ctj)')-2*Ixu(:,:,ctj)*kron(eye(3),1)]; 77 | Psi = -Ixx(:,:,ctj)*Qk(:); 78 | % pv=inv(Theta'*Theta)*Theta'*Psi; 79 | pv = pinv(Theta)*Psi; 80 | K(:,:,ctj)=pv(end-2:end)'; 81 | end 82 | Kadp(:,:,ctj) = K(:,:,ctj); 83 | disp(['The' num2str(ctj+1) '-th machine stopped learning after' num2str(it) 'iterations']) 84 | end 85 | 86 | %% Simulate the post-learning performance 87 | [t,y]=ode45(@(t,x) Local_mmsys_online_radp(t,x,Kadp),[5,15],y(end,:)); 88 | y=[yy;y];t=[tt;t]; 89 | 90 | % Clean up 91 | clear Local_mmsys_online_radp 92 | 93 | % plot the angles 94 | Local_plot(t,y,Params.dlt0); 95 | end 96 | 97 | %% Local_mmsys_online_radp 98 | % Local function to simulat the dynamics of the 99 | % multimachine power system. 100 | function dxx = Local_mmsys_online_radp(t,xx, Kadp) 101 | 102 | persistent Params 103 | 104 | if isempty(Params) 105 | Params = Local_load_params(); 106 | end 107 | 108 | A = Params.A; 109 | B = Params.B; 110 | Nm = Params.Nm; 111 | 112 | x = zeros(3,Nm); 113 | for ct = 2:Nm 114 | id = (ct-2)*3 + 1:(ct-2)*3+3; 115 | x(:,ct) = xx(id); 116 | end 117 | 118 | % calculate angular differences in matrix form 119 | dlt=zeros(Nm);d=zeros(1,Nm); 120 | for i=1:Nm 121 | dlt(i,:)=x(1,i)+Params.dlt0(i)-x(1,:)-Params.dlt0'; 122 | d(i)= Params.E(i)*(Params.E.*(x(2,i)-x(2,:)))*(Params.BX(i,:).*cos(dlt(i,:))-Params.GX(i,:).*sin(dlt(i,:)))'; 123 | end 124 | u = zeros(Nm,1); 125 | for i=2:Nm 126 | if t>=4 && t<=5 % learning stage is between 4s and 5s 127 | u(i) = -Kadp(:,:,i-1)*x(:,i)+0.001*sin(100*t); 128 | else 129 | u(i) = -Kadp(:,:,i-1)*x(:,i); 130 | end 131 | end 132 | 133 | for i = 2:Nm 134 | dx(:,i-1) = A(:,:,i)*x(:,i)+B(:,:,i)*(u(i)-d(i)); 135 | end 136 | 137 | dIxxu=zeros(12,Nm-1); 138 | if t>=4 && t<=5 139 | for i=2:Nm 140 | dIxxu(:,i-1)=[kron(x(:,i),x(:,i));kron(x(:,i),u(i)-d(i))]; 141 | end 142 | end 143 | dxx = [dx(:); 144 | dIxxu(:)]; 145 | end 146 | 147 | %% Local_plot 148 | % Plot results 149 | function Local_plot(t,y,dlt0) 150 | %Plot the power angles of G2-G10 151 | figure(1) 152 | subplot(311) 153 | plot(t,(y(:,1)+dlt0(2))*180/pi,'b','linewidth',2) 154 | xlabel('Time(sec)', 'FontSize', 12) 155 | l = legend('Angle of G2 (dgree)'); 156 | set(l, 'FontSize', 12) 157 | axis([0 15 0 200]) 158 | subplot(312) 159 | plot(t,(y(:,4)+dlt0(3))*180/pi,'b','linewidth',2) 160 | xlabel('Time(sec)', 'FontSize', 12) 161 | l = legend('Angle of G3 (dgree)'); 162 | set(l, 'FontSize', 12) 163 | axis([0 15 0 200]) 164 | subplot(313) 165 | plot(t,(y(:,7)+dlt0(4))*180/pi,'b','linewidth',2) 166 | xlabel('Time(sec)', 'FontSize', 12) 167 | l = legend('Angle of G4 (dgree)'); 168 | set(l, 'FontSize', 12) 169 | axis([0 15 50 65]) 170 | annotation(figure(1),'textarrow',[0.424517593643587 0.398365782488103],... 171 | [0.16729088639201 0.189882327941137],'String',{'Controller Updated'},... 172 | 'FontSize',12); 173 | annotation(figure(1),'textarrow',[0.425440032308299 0.399288221152816],... 174 | [0.460015659616231 0.482607101165358],'String',{'Controller Updated'},... 175 | 'FontSize',12); 176 | annotation(figure(1),'textarrow',[0.426787741203178 0.400635930047695],... 177 | [0.762796504369538 0.785387945918666],'String',{'Controller Updated'},... 178 | 'FontSize',12); 179 | annotation(figure(1),'textarrow',[0.208516886930984 0.190650614335506],... 180 | [0.874592833876222 0.84401986774277],'String',{'Disturbance Injected'},... 181 | 'FontSize',12); 182 | annotation(figure(1),'textarrow',[0.204111600587371 0.186245327991894],... 183 | [0.570032573289903 0.539459607156451],'String',{'Disturbance Injected'},... 184 | 'FontSize',12); 185 | annotation(figure(1),'textarrow',[0.209985315712188 0.19211904311671],... 186 | [0.27198697068404 0.241414004550588],'String',{'Disturbance Injected'},... 187 | 'FontSize',12); 188 | 189 | 190 | 191 | figure(2) 192 | subplot(311) 193 | plot(t,(y(:,1+9)+dlt0(2+3))*180/pi,'b','linewidth',2) 194 | xlabel('Time(sec)') 195 | legend('Angle of G5 (dgree)') 196 | axis([0 15 40 100]) 197 | subplot(312) 198 | plot(t,(y(:,4+9)+dlt0(3+3))*180/pi,'b','linewidth',2) 199 | xlabel('Time(sec)') 200 | legend('Angle of G6 (dgree)') 201 | axis([0 15 60 90]) 202 | subplot(313) 203 | plot(t,(y(:,7+9)+dlt0(4+3))*180/pi,'b','linewidth',2) 204 | xlabel('Time(sec)') 205 | legend('Angle of G7 (dgree)') 206 | axis([0 15 20 80]) 207 | 208 | figure(3) 209 | subplot(311) 210 | plot(t,(y(:,1+9+9)+dlt0(2+6))*180/pi,'b','linewidth',2) 211 | xlabel('Time(sec)') 212 | legend('Angle of G8 (dgree)') 213 | axis([0 15 60 80]) 214 | subplot(312) 215 | plot(t,(y(:,4+9+9)+dlt0(3+6))*180/pi,'b','linewidth',2) 216 | xlabel('Time(sec)') 217 | legend('Angle of G9 (dgree)') 218 | axis([0 15 0 100]) 219 | subplot(313) 220 | % plot the angles 221 | plot(t,(y(:,7+9+9)+dlt0(4+6))*180/pi,'b','linewidth',2) 222 | xlabel('Time(sec)') 223 | legend('Angle of G10 (dgree)') 224 | axis([0 15 40 100]) 225 | 226 | 227 | % Plot the frequencies 228 | figure(4) 229 | subplot(311) 230 | plot(t,y(:,2)*2/pi+50,'b','linewidth',2) 231 | xlabel('Time(sec)', 'FontSize', 12) 232 | l = legend('Frequency of G2 (Hz)'); 233 | set(l, 'FontSize', 12) 234 | axis([0 15 -10+50 10+50]) 235 | subplot(312) 236 | plot(t,y(:,5)*2/pi+50,'b','linewidth',2) 237 | xlabel('Time(sec)', 'FontSize', 12) 238 | l = legend('Frequency of G3 (Hz)'); 239 | set(l, 'FontSize', 12) 240 | axis([0 15 -10+50 10+50]) 241 | subplot(313) 242 | % plot the angles 243 | plot(t,y(:,8)*2/pi+50,'b','linewidth',2) 244 | xlabel('Time(sec)', 'FontSize', 12) 245 | l = legend('Frequency of G4 (Hz)'); 246 | set(l, 'FontSize', 12) 247 | axis([0 15 -.5+50 .5+50]) 248 | annotation(figure(4),'textarrow',[0.219236209335219 0.182764994466165],... 249 | [0.285714285714286 0.238495847775444],'String',{'Disturbance Injected'},... 250 | 'FontSize',12); 251 | annotation(figure(4),'textarrow',[0.214449541284404 0.178980753001389],... 252 | [0.58403869407497 0.536862481813178],'String',{'Disturbance Injected'},... 253 | 'FontSize',12); 254 | annotation(figure(4),'textarrow',[0.198019801980198 0.18291746711841],... 255 | [0.866666666666667 0.840668550794581],'String',{'Disturbance Injected'},... 256 | 'FontSize',12); 257 | annotation(figure(4),'textarrow',[0.437057991513437 0.402604606212398],... 258 | [0.782539682539683 0.820868546955883],'String',{'Controller Updated'},... 259 | 'FontSize',12); 260 | annotation(figure(4),'textarrow',[0.427157001414427 0.401190179055397],... 261 | [0.477777777777778 0.518496231645235],'String',{'Controller Updated'},... 262 | 'FontSize',12); 263 | annotation(figure(4),'textarrow',[0.432814710042433 0.400311028230748],... 264 | [0.173015873015873 0.215895513808725],'String',{'Controller Updated'},... 265 | 'FontSize',12); 266 | 267 | figure(5) 268 | subplot(311) 269 | plot(t,y(:,2+9)*2/pi+50,'b','linewidth',2) 270 | xlabel('Time(sec)') 271 | legend('Frequency of G5 (Hz)') 272 | axis([0 15 -5+50 5+50]) 273 | subplot(312) 274 | plot(t,y(:,5+9)*2/pi+50,'b','linewidth',2) 275 | xlabel('Time(sec)') 276 | legend('Frequency of G6 (Hz)') 277 | axis([0 15 -3+50 3+50]) 278 | subplot(313) 279 | % plot the angles 280 | plot(t,y(:,8+9)*2/pi+50,'b','linewidth',2) 281 | xlabel('Time(sec)') 282 | legend('Frequency of G7 (Hz)') 283 | axis([0 15 -5+50 5+50]) 284 | 285 | 286 | figure(6) 287 | subplot(311) 288 | plot(t,y(:,2+9+9)*2/pi+50,'b','linewidth',2) 289 | xlabel('Time(sec)') 290 | legend('Frequency of G8 (Hz)') 291 | axis([0 15 -2+50 2+50]) 292 | subplot(312) 293 | plot(t,y(:,5+9+9)*2/pi+50,'b','linewidth',2) 294 | xlabel('Time(sec)') 295 | legend('Frequency of G9 (Hz)') 296 | axis([0 15 -3+50 3+50]) 297 | subplot(313) 298 | % plot the angles 299 | plot(t,y(:,8+9+9)*2/pi+50,'b','linewidth',2) 300 | xlabel('Time(sec)') 301 | legend('Frequency of G10 (Hz)') 302 | axis([0 15 -5+50 5+50]) 303 | end 304 | 305 | %% Local_load_params 306 | % Local parameters for simulation setting and for the 307 | % machine dynamics 308 | function Params = Local_load_params() 309 | omg0=314.159; %steady state frequency 310 | Nm=10; %# of machines 311 | 312 | H= [100 6.4 3 5.5 5.2 4.7 5.4 4.9 5.1 3.4]; 313 | D= [0 1 1.5 2 2.2 2.3 2.6 1.8 1.7 2.9]; 314 | T= [0 6 6.3 4.9 6.6 5.8 5.9 5.5 5.4 5.5]; 315 | E= [1 1.2 1.5 .8 1.3 0.9 1.1 .6 1.5 1]; 316 | dlt0=[0 1.9 1.7 1 1.2 1.3 .8 1.2 .7 1.1]'; 317 | 318 | imxx=(Nm-1)*3+1+[0:(Nm-2)]*12; 319 | imuu=imxx+9; 320 | 321 | BX=[0.2537 0.1875 0.0132 0.2967 0.2852 0.4848 0.2443 0.0908 0.2149 0.2335 322 | 0.1875 0.3927 0.2493 0.5291 0.2827 0.2909 0.3759 0.3272 0.2354 0.3819 323 | 0.0132 0.2493 0.0545 0.2712 0.2465 0.2230 0.2741 0.2147 0.3280 0.4937 324 | 0.2967 0.5291 0.2712 0.5746 0.3255 0.3301 0.1325 0.2878 0.4921 0.1255 325 | 0.2852 0.2827 0.2465 0.3255 0.2067 0.3724 0.3049 0.0294 0.2433 0.3146 326 | 0.4848 0.2909 0.2230 0.3301 0.3724 0.4621 0.2790 0.4083 0.3542 0.1356 327 | 0.2443 0.3759 0.2741 0.1325 0.3049 0.2790 0.1151 0.4265 0.1437 0.5278 328 | 0.0908 0.3272 0.2147 0.2878 0.0294 0.4083 0.4265 0.3280 0.1635 0.4432 329 | 0.2149 0.2354 0.3280 0.4921 0.2433 0.3542 0.1437 0.1635 0.3644 0.2120 330 | 0.2335 0.3819 0.4937 0.1255 0.3146 0.1356 0.5278 0.4432 0.2120 0.3681]; 331 | 332 | GX=0.1*[2.1043 0.5194 0.0047 1.3971 0.4052 -0.1143 0.0088 2.8105 -0.7849 -0.0019 333 | 0.5194 2.9397 0.3410 0.1829 1.2937 -1.7493 -0.0346 -0.0512 -1.0858 -0.3718 334 | 0.0047 0.3410 1.5196 1.7842 -2.6536 -0.9942 1.5418 -0.4936 2.2536 2.7643 335 | 1.3971 0.1829 1.7842 0.4805 -1.1049 -0.7318 2.2099 -1.1210 2.3378 -1.4679 336 | 0.4052 1.2937 -2.6536 -1.1049 0.8255 -2.0058 -0.7204 -1.9231 0.3224 -1.4969 337 | -0.1143 -1.7493 -0.9942 -0.7318 -2.0058 0.2316 -0.2891 0.3602 1.1842 -0.6656 338 | 0.0088 -0.0346 1.5418 2.2099 -0.7204 -0.2891 0.3899 0.6421 0.6078 -0.9809 339 | 2.8105 -0.0512 -0.4936 -1.1210 -1.9231 0.3602 0.6421 2.6875 1.3337 1.1306 340 | -0.7849 -1.0858 2.2536 2.3378 0.3224 1.1842 0.6078 1.3337 1.9344 -1.7285 341 | -0.0019 -0.3718 2.7643 -1.4679 -1.4969 -0.6656 -0.9809 1.1306 -1.7285 2.0532]; 342 | 343 | A=zeros(3,3,Nm); 344 | B=zeros(3,1,Nm); 345 | 346 | K00=[1 1.5 20]; 347 | 348 | Kstar=K00; 349 | pm=0; 350 | for i=2:Nm 351 | A(:,:,i)=[0 1 0; 0 -D(i)/2/H(i) omg0/2/H(i); 0 0 -1/T(i)]; 352 | B(:,:,i)=[0;0;1/T(i)]; 353 | pm(i)=E(i)*(E.*BX(i,:)*sin(dlt0(i)-dlt0)+E.*GX(i,:)*cos(dlt0(i)-dlt0)); 354 | Kstar(:,:,i-1)=lqr(A(:,:,i),B(:,:,i),1000*eye(3),1); 355 | end 356 | 357 | Params.Nm = Nm; 358 | Params.dlt0 = dlt0; 359 | Params.BX = BX; 360 | Params.GX = GX; 361 | Params.E = E; 362 | Params.A = A; 363 | Params.B = B; 364 | Params.pm = pm; 365 | Params.imxx = imxx; 366 | Params.imuu = imuu; 367 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/figures/Ch6_Ex1_Angle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/figures/Ch6_Ex1_Angle.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/figures/Ch6_Ex1_Freq.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/figures/Ch6_Ex1_Freq.pdf -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_01.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_02.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_03.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_04.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_05.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/html/RADP_MultiMachine_06.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter6_Example1/temp/LinearADPSimullink__new.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter6_Example1/temp/LinearADPSimullink__new.slx -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example1/AbstractSimulator.m: -------------------------------------------------------------------------------- 1 | classdef (Abstract) AbstractSimulator < handle 2 | % Abstract class for movement simulation. 3 | % Author: Yu Jiang 4 | % Contact: yu.jiang@nyu.edu 5 | % Copyright 2015 Yu Jiang 6 | 7 | properties (Constant) 8 | % Constant simulation parameters 9 | tau = 0.05; % Time constant 10 | m1 = 2; % mass on x direction 11 | m2 = 2; % mass on y direction 12 | 13 | c1 = 0.15/2; % noise scale 14 | c2 = 0.05/2; % noise scale 15 | dt_ = 0.005; % sample time for learning 16 | 17 | Q0 = [500 0; 0 1000]; % Initial weighting matrices 18 | R = diag([0.01,0.01]); % Initial weighting matrices 19 | 20 | % The null filed dynamics 21 | A0 = [zeros(2) eye(2) zeros(2); 22 | zeros(2,4) diag([1/AbstractSimulator.m1 1/AbstractSimulator.m2]) 23 | zeros(2,4) -diag([1/AbstractSimulator.tau 1/AbstractSimulator.tau])]; 24 | B = [zeros(4,2); diag([1/AbstractSimulator.tau 1/AbstractSimulator.tau])]; 25 | end 26 | 27 | properties 28 | % Variables 29 | dt % Sample time for simulation 30 | A % Dynamics with Force field 31 | end 32 | 33 | 34 | properties 35 | % Others 36 | fig1; 37 | fig2; 38 | fig3; 39 | end 40 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example1/Ch7Ex1_main.m: -------------------------------------------------------------------------------- 1 | %% ADP for sensorimotor control 2 | 3 | %% Simulate the DF 4 | MDF = DFSimulator(); 5 | simNF(MDF); 6 | simDF(MDF); 7 | simAL(MDF); 8 | simAE(MDF); 9 | showStiffness(MDF); 10 | %% Simulate the VF 11 | MVF = VFSimulator(); 12 | simNF(MVF); 13 | simVF(MVF); 14 | simAL(MVF); 15 | simAE(MVF); 16 | showStiffness(MVF); 17 | %% Valide Fitts Law 18 | %NF 19 | disp('Simulating the NF...') 20 | wdd = 2.2:0.1:6; 21 | r=0.5./(2.^wdd); 22 | T=r; 23 | for i=1:length(r) % generating each single trial 24 | disp(['Simulating the NF...', 'Trial: #', num2str(i), ' (', num2str(length(r)-i), 'trials left)']) 25 | % T(i) = fitts_movement_duration_NF(r(i)); 26 | MDF.reset(); 27 | T(i) = MDF.getMovementDuration(r(i)); 28 | end 29 | figure 30 | subplot(321) 31 | fit1l = polyfit(wdd,T,1); 32 | plot(wdd,T,'+',wdd,fit1l(2)+fit1l(1).*wdd,'linewidth',1.5); 33 | axis([1,7,0,0.8]); 34 | xlabel('\fontsize{12}log_2(2d/s)') 35 | ylabel('\fontsize{12}Movement time t_f (sec)') 36 | title('\fontsize{12}A'); 37 | legend('\fontsize{12}Movement duration of each trial', '\fontsize{12}Least-squares fit using the log law'); 38 | subplot(322) 39 | fit1p = polyfit(log(0.25./r),log(T),1); 40 | plot(log(0.25./r),log(T),'+',log(0.25./r),fit1p(2)+fit1p(1).*log(0.25./r),'linewidth',1.5); 41 | legend('\fontsize{12}Movement duration of each trial', '\fontsize{12}Least-squares fit using the power law'); 42 | axis([0,4,-2,0]); 43 | xlabel('\fontsize{12}ln(d/s)'); 44 | ylabel('\fontsize{12}ln(t_f)'); 45 | title('\fontsize{12}B'); 46 | % VF 47 | Tvf = zeros(size(r)); 48 | for i=1:length(r) 49 | disp(['Simulating the VF...', 'Trial: #', num2str(i), ' (', num2str(length(r)-i), 'trials left)']); 50 | % Tvf(i) = fitts_movement_duration_VF(r(i)); 51 | Tvf(i) = MVF.getPostLearningMovementDuration(r(i)); 52 | end 53 | %figure 54 | %subplot(121) 55 | subplot(323) 56 | fit2l = polyfit(wdd,Tvf,1); 57 | plot(wdd,Tvf,'+',wdd,fit2l(2)+fit2l(1).*wdd,'linewidth',1.5); 58 | axis([1,7,0,1.5]); 59 | xlabel('\fontsize{12}log_2(2d/s)'); 60 | ylabel('\fontsize{12}Movement time t_f (sec)'); 61 | title('\fontsize{12}C'); 62 | legend('\fontsize{12}Movement duration of each trial', '\fontsize{12}Least-squares fit using the log law'); 63 | %subplot(122) 64 | subplot(324) 65 | fit2p = polyfit(log(0.25./r),log(Tvf),1); 66 | plot(log(0.25./r),log(Tvf),'+',log(0.25./r),fit2p(2)+fit2p(1).*log(0.25./r),'linewidth',1.5); 67 | legend('\fontsize{12}Movement duration of each trial', '\fontsize{12}Least-squares fit using the power law'); 68 | axis([0,4,-2,0.7]); 69 | xlabel('\fontsize{12}ln(d/s)'); 70 | ylabel('\fontsize{12}ln(t_f)'); 71 | title('\fontsize{12}D'); 72 | % DF 73 | Tdf = zeros(size(r)); 74 | for i=1:length(r) 75 | disp(['Simulating the DF...', 'Trial: #', num2str(i), ' (', num2str(length(r)-i), 'trials left)']); 76 | MDF.K = MDF.Ko; 77 | Tdf(i) = MDF.getMovementDuration(r(i)); 78 | end 79 | % 80 | %figure 81 | %subplot(121); 82 | subplot(325) 83 | fit3l = polyfit(wdd,Tdf,1); 84 | plot(wdd,Tdf,'+',wdd,fit3l(2)+fit3l(1).*wdd,'linewidth',1.5); 85 | axis([1,7,0,0.8]); 86 | xlabel('\fontsize{12}log_2(2d/s)'); 87 | ylabel('\fontsize{12}Movement time t_f (sec)'); 88 | title('\fontsize{12}E'); 89 | legend('\fontsize{12}Movement duration of each trial', '\fontsize{12}Least-squares fit using the log law'); 90 | %subplot(122); 91 | subplot(326) 92 | fit3p = polyfit(log(0.25./r),log(Tdf),1); 93 | plot(log(0.25./r),log(Tdf),'+',log(0.25./r),fit3p(2)+fit3p(1).*log(0.25./r),'linewidth',1.5); 94 | legend('\fontsize{12}Movement duration of each trial', '\fontsize{12}Least-squares fit using the power law'); 95 | axis([0,4,-2,0]); 96 | xlabel('\fontsize{12}ln(d/s)'); 97 | ylabel('\fontsize{12}ln(t_f)'); 98 | title('\fontsize{12}F'); 99 | % Display the fitted parameters 100 | disp('Fitting results:') 101 | disp(['NF Log Law:', 'a=',num2str(fit1l(1)), ' b=', num2str(fit1l(2))]); 102 | disp(['NF Power Law:', 'a=',num2str(fit1p(1)), ' b=', num2str(fit1p(2))]); 103 | disp(['VF Log Law:', 'a=',num2str(fit2l(1)), ' b=', num2str(fit2l(2))]); 104 | disp(['VF Power Law:', 'a=',num2str(fit2p(1)), ' b=', num2str(fit2p(2))]); 105 | disp(['DF Log Law:', 'a=',num2str(fit3l(1)), ' b=', num2str(fit3l(2))]); 106 | disp(['DF Power Law:', 'a=',num2str(fit3p(1)), ' b=', num2str(fit3p(2))]); 107 | 108 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/Ch7Ex2_main.m: -------------------------------------------------------------------------------- 1 | %% RADP for Sensorimotor Control 2 | 3 | figure(1) 4 | subplot(221) 5 | draw_bg 6 | x0=[0,.1];plotTimecourse(x0, 'NF', 1); 7 | x0=[0,-.1];plotTimecourse(x0, 'NF',3); 8 | x0=[.1,0];plotTimecourse(x0, 'NF', 5); 9 | x0=[-.1,0];plotTimecourse(x0, 'NF',7); 10 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF', 2); 11 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF',4); 12 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF', 6); 13 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF', 8); 14 | ylabel('y-position (m)') 15 | xlabel('x-position (m)') 16 | title('A', 'fontsize', 12) 17 | hold off 18 | 19 | %% 20 | figure(1) 21 | subplot(222) 22 | draw_bg 23 | x0=[0,.1];plotTimecourse(x0, 'VF', 1); 24 | x0=[0,-.1];plotTimecourse(x0, 'VF',3); 25 | x0=[.1,0];plotTimecourse(x0, 'VF', 5); 26 | x0=[-.1,0];plotTimecourse(x0, 'VF',7); 27 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF', 2); 28 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF',4); 29 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF', 6); 30 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF', 8); 31 | xlabel('x-position (m)') 32 | ylabel('y-position (m)') 33 | title('B', 'fontsize', 12) 34 | hold off 35 | 36 | %% 37 | figure(1) 38 | subplot(223) 39 | draw_bg 40 | x0=[0,.1];plotTimecourse(x0, 'AE', 1); 41 | x0=[0,-.1];plotTimecourse(x0, 'AE',3); 42 | x0=[.1,0];plotTimecourse(x0, 'AE', 5); 43 | x0=[-.1,0];plotTimecourse(x0, 'AE',7); 44 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE', 2); 45 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE',4); 46 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE', 6); 47 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE', 8); 48 | xlabel('x-position (m)') 49 | ylabel('y-position (m)') 50 | title('C', 'fontsize', 12) 51 | hold off 52 | 53 | 54 | %% 55 | figure(1) 56 | subplot(224) 57 | draw_bg 58 | x0=[0,.1];plotTimecourse(x0, 'AL', 1); 59 | x0=[0,-.1];plotTimecourse(x0, 'AL',3); 60 | x0=[.1,0];plotTimecourse(x0, 'AL', 5); 61 | x0=[-.1,0];plotTimecourse(x0, 'AL',7); 62 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL', 2); 63 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL',4); 64 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL', 6); 65 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL', 8); 66 | xlabel('x-position (m)') 67 | ylabel('y-position (m)') 68 | title('D', 'fontsize', 12) 69 | hold off 70 | 71 | % %% 72 | % figure(2) 73 | % xlabel('time (s)') 74 | % ylabel('velocity (m/s)') 75 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/LocalSDESolver.m: -------------------------------------------------------------------------------- 1 | function [t,Y] = LocalSDESolver(t0,tf,x0,dt, K, isForceField) 2 | h=dt; 3 | t=t0:dt:tf; 4 | y=x0; 5 | Y=[]; 6 | for clock = t 7 | %clock 8 | y = y + Motor2D(y,K,isForceField)*h; 9 | Y = [Y y]; 10 | end 11 | Y=Y'; 12 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/Motor2D.m: -------------------------------------------------------------------------------- 1 | function dX = Motor2D(X,K,isForceField) 2 | 3 | % Parameters 4 | m = 2;%1; % mass 5 | b = 10; % viscosity 6 | c1 = 0.15/2; 7 | c2 = 0.05/2; 8 | dt = 0.005; 9 | tau = 0.05; 10 | A = [ 0 0 1 0; 11 | 0 0 0 1; 12 | 0 0 -b/m 0; 13 | 0 0 0 -b/m]; 14 | B = [0 0; 15 | 0 0; 16 | 1/m 0; 17 | 0 1/m]; 18 | B1 = [1/tau 0; 19 | 0 1/tau]; 20 | 21 | x = X(1:6); 22 | z = X(7:8); 23 | 24 | dx = x; 25 | x = x(:); 26 | u = -K*x; 27 | 28 | w = randn(2,1)*sqrt(dt); 29 | M = [c1*u(1) c2*u(2); -c2*u(1) c1*u(2)]; 30 | 31 | VF=[-10.1 -11.2; -11.2 11.1]; 32 | 33 | v = M*w; % control dependent noise 34 | f = z; 35 | 36 | dx(1:4) = A * x(1:4)+B*(x(5:6)+f); 37 | dx(5:6) = B1 * (-x(5:6)+u+v./dt); 38 | 39 | if isForceField 40 | dz = -1/0.01*(z-VF*[x(3);x(4)]); 41 | else 42 | dz=[0;0]; 43 | end 44 | 45 | dX=[dx;dz]; 46 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/draw_bg.m: -------------------------------------------------------------------------------- 1 | % main 2 | filledCircle([0,-0.1],0.0075,1000,'r'); 3 | hold on 4 | filledCircle([0,0.1],0.0075,1000,'r'); 5 | filledCircle([-0.1,0],0.0075,1000,'r'); 6 | filledCircle([0.1,0],0.0075,1000,'r'); 7 | filledCircle([0.1,.1]*sqrt(2)/2,0.0075,1000,'r'); 8 | filledCircle([0.1,-.1]*sqrt(2)/2,0.0075,1000,'r'); 9 | filledCircle([-0.1,.1]*sqrt(2)/2,0.0075,1000,'r'); 10 | filledCircle(-[0.1,.1]*sqrt(2)/2,0.0075,1000,'r'); 11 | axis([-1 1 -1 1]*.175); -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/filledCircle.m: -------------------------------------------------------------------------------- 1 | function h = filledCircle(center,r,N,color) 2 | %--------------------------------------------------------------------------------------------- 3 | % FILLEDCIRCLE Filled circle drawing 4 | % 5 | % filledCircle(CENTER,R,N,COLOR) draws a circle filled with COLOR that 6 | % has CENTER as its center and R as its radius, by using N points on the 7 | % periphery. 8 | % 9 | % Usage Examples, 10 | % 11 | % filledCircle([1,3],3,1000,'b'); 12 | % filledCircle([2,4],2,1000,'r'); 13 | % 14 | % Sadik Hava 15 | % May, 2010 16 | % 17 | % Inspired by: circle.m [Author: Zhenhai Wang] 18 | %--------------------------------------------------------------------------------------------- 19 | 20 | THETA=linspace(0,2*pi,N); 21 | RHO=ones(1,N)*r; 22 | [X,Y] = pol2cart(THETA,RHO); 23 | X=X+center(1); 24 | Y=Y+center(2); 25 | h=fill(X,Y,color); 26 | axis square; 27 | 28 | 29 | % COPYRIGHT STUFF... :D (Since I am modifying Zhenhai's code.) 30 | % 31 | % Copyright (c) 2002, Zhenhai Wang 32 | % All rights reserved. 33 | % 34 | % Redistribution and use in source and binary forms, with or without 35 | % modification, are permitted provided that the following conditions are 36 | % met: 37 | % 38 | % * Redistributions of source code must retain the above copyright 39 | % notice, this list of conditions and the following disclaimer. 40 | % * Redistributions in binary form must reproduce the above copyright 41 | % notice, this list of conditions and the following disclaimer in 42 | % the documentation and/or other materials provided with the distribution 43 | % 44 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 45 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 48 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 | % POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Ch7Ex2_main
figure(1)
 70 | subplot(221)
 71 | draw_bg
 72 | x0=[0,.1];plotTimecourse(x0, 'NF', 1);
 73 | x0=[0,-.1];plotTimecourse(x0, 'NF',3);
 74 | x0=[.1,0];plotTimecourse(x0, 'NF', 5);
 75 | x0=[-.1,0];plotTimecourse(x0, 'NF',7);
 76 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF', 2);
 77 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF',4);
 78 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF', 6);
 79 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'NF', 8);
 80 | ylabel('y-position (m)')
 81 | xlabel('x-position (m)')
 82 | title('A', 'fontsize', 12)
 83 | hold off
 84 | 
figure(1)
 85 | subplot(222)
 86 | draw_bg
 87 | x0=[0,.1];plotTimecourse(x0, 'VF', 1);
 88 | x0=[0,-.1];plotTimecourse(x0, 'VF',3);
 89 | x0=[.1,0];plotTimecourse(x0, 'VF', 5);
 90 | x0=[-.1,0];plotTimecourse(x0, 'VF',7);
 91 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF', 2);
 92 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF',4);
 93 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF', 6);
 94 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'VF', 8);
 95 | xlabel('x-position (m)')
 96 | ylabel('y-position (m)')
 97 | title('B', 'fontsize', 12)
 98 | hold off
 99 | 
figure(1)
100 | subplot(223)
101 | draw_bg
102 | x0=[0,.1];plotTimecourse(x0, 'AE', 1);
103 | x0=[0,-.1];plotTimecourse(x0, 'AE',3);
104 | x0=[.1,0];plotTimecourse(x0, 'AE', 5);
105 | x0=[-.1,0];plotTimecourse(x0, 'AE',7);
106 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE', 2);
107 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE',4);
108 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE', 6);
109 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AE', 8);
110 | xlabel('x-position (m)')
111 | ylabel('y-position (m)')
112 | title('C', 'fontsize', 12)
113 | hold off
114 | 
figure(1)
115 | subplot(224)
116 | draw_bg
117 | x0=[0,.1];plotTimecourse(x0, 'AL', 1);
118 | x0=[0,-.1];plotTimecourse(x0, 'AL',3);
119 | x0=[.1,0];plotTimecourse(x0, 'AL', 5);
120 | x0=[-.1,0];plotTimecourse(x0, 'AL',7);
121 | x0=[1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL', 2);
122 | x0=[-1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL',4);
123 | x0=[-1,1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL', 6);
124 | x0=[1,-1]/10*sqrt(2)/2;plotTimecourse(x0, 'AL', 8);
125 | xlabel('x-position (m)')
126 | ylabel('y-position (m)')
127 | title('D', 'fontsize', 12)
128 | hold off
129 | 
130 | % %%
131 | % figure(2)
132 | % xlabel('time (s)')
133 | % ylabel('velocity (m/s)')
134 | 
-------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_01.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_02.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_03.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_04.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_05.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_06.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/Robust-ADP/Chapter7_Example2/html/Ch7Ex2_main_07.png -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/draw_bg.m: -------------------------------------------------------------------------------- 1 | % main 2 | filledCircle([0,-0.1],0.0075,1000,'r'); 3 | hold on 4 | filledCircle([0,0.1],0.0075,1000,'r'); 5 | filledCircle([-0.1,0],0.0075,1000,'r'); 6 | filledCircle([0.1,0],0.0075,1000,'r'); 7 | filledCircle([0.1,.1]*sqrt(2)/2,0.0075,1000,'r'); 8 | filledCircle([0.1,-.1]*sqrt(2)/2,0.0075,1000,'r'); 9 | filledCircle([-0.1,.1]*sqrt(2)/2,0.0075,1000,'r'); 10 | filledCircle(-[0.1,.1]*sqrt(2)/2,0.0075,1000,'r'); 11 | axis([-1 1 -1 1]*.175); -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/filledCircle.m: -------------------------------------------------------------------------------- 1 | function h = filledCircle(center,r,N,color) 2 | %--------------------------------------------------------------------------------------------- 3 | % FILLEDCIRCLE Filled circle drawing 4 | % 5 | % filledCircle(CENTER,R,N,COLOR) draws a circle filled with COLOR that 6 | % has CENTER as its center and R as its radius, by using N points on the 7 | % periphery. 8 | % 9 | % Usage Examples, 10 | % 11 | % filledCircle([1,3],3,1000,'b'); 12 | % filledCircle([2,4],2,1000,'r'); 13 | % 14 | % Sadik Hava 15 | % May, 2010 16 | % 17 | % Inspired by: circle.m [Author: Zhenhai Wang] 18 | %--------------------------------------------------------------------------------------------- 19 | 20 | THETA=linspace(0,2*pi,N); 21 | RHO=ones(1,N)*r; 22 | [X,Y] = pol2cart(THETA,RHO); 23 | X=X+center(1); 24 | Y=Y+center(2); 25 | h=fill(X,Y,color); 26 | axis square; 27 | 28 | 29 | % COPYRIGHT STUFF... :D (Since I am modifying Zhenhai's code.) 30 | % 31 | % Copyright (c) 2002, Zhenhai Wang 32 | % All rights reserved. 33 | % 34 | % Redistribution and use in source and binary forms, with or without 35 | % modification, are permitted provided that the following conditions are 36 | % met: 37 | % 38 | % * Redistributions of source code must retain the above copyright 39 | % notice, this list of conditions and the following disclaimer. 40 | % * Redistributions in binary form must reproduce the above copyright 41 | % notice, this list of conditions and the following disclaimer in 42 | % the documentation and/or other materials provided with the distribution 43 | % 44 | % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 45 | % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 | % IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 | % ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 48 | % LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49 | % CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 | % POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/main.m: -------------------------------------------------------------------------------- 1 | figure(1) 2 | subplot(221) 3 | draw_bg 4 | x0=[0, 0.1];timecourse_NF(x0,1);disp('1') 5 | x0=[0,-0.1];timecourse_NF(x0,5);disp('2') 6 | x0=[0.1, 0];timecourse_NF(x0,3);disp('3') 7 | x0=[-.1, 0];timecourse_NF(x0,7);disp('4') 8 | 9 | x0=[1,1]/10*sqrt(2)/2;timecourse_NF(x0,2); disp('5') 10 | x0=[-1,-1]/10*sqrt(2)/2;timecourse_NF(x0,6);disp('6') 11 | x0=[-1,1]/10*sqrt(2)/2;timecourse_NF(x0,8); disp('7') 12 | x0=[1,-1]/10*sqrt(2)/2;timecourse_NF(x0,4); disp('8') 13 | 14 | xlabel('x-position (m)') 15 | ylabel('y-position (m)') 16 | title('A', 'fontsize', 12) 17 | hold off 18 | 19 | %% 20 | figure(1) 21 | subplot(222) 22 | draw_bg 23 | hold on 24 | x0=[0,.1];timecourse_VF(x0,1);disp('1') 25 | x0=[0,-.1];timecourse_VF(x0,5);disp('2') 26 | x0=[.1,0];timecourse_VF(x0,3);disp('3') 27 | x0=[-.1,0];timecourse_VF(x0,7);disp('4') 28 | x0=[1,1]/10*sqrt(2)/2;timecourse_VF(x0,2);disp('5') 29 | x0=[-1,-1]/10*sqrt(2)/2;timecourse_VF(x0,6);disp('6') 30 | x0=[-1,1]/10*sqrt(2)/2;timecourse_VF(x0,8);disp('7') 31 | x0=[1,-1]/10*sqrt(2)/2;timecourse_VF(x0,4);disp('8') 32 | xlabel('x-position (m)') 33 | ylabel('y-position (m)') 34 | title('B', 'fontsize', 12) 35 | hold off 36 | 37 | %% 38 | figure(1) 39 | subplot(223) 40 | draw_bg 41 | x0=[0,.1];timecourse_AL(x0,1);disp('1') 42 | x0=[0,-.1];timecourse_AL(x0,5);disp('2') 43 | x0=[.1,0];timecourse_AL(x0,3);disp('3') 44 | x0=[-.1,0];timecourse_AL(x0,7);disp('4') 45 | x0=[1,1]/10*sqrt(2)/2;timecourse_AL(x0,2);disp('5') 46 | x0=[-1,-1]/10*sqrt(2)/2;timecourse_AL(x0,6);disp('6') 47 | x0=[-1,1]/10*sqrt(2)/2;timecourse_AL(x0,8);disp('7') 48 | x0=[1,-1]/10*sqrt(2)/2;timecourse_AL(x0,4);disp('8') 49 | xlabel('x-position (m)') 50 | ylabel('y-position (m)') 51 | title('C', 'fontsize', 12) 52 | hold off 53 | 54 | 55 | %% 56 | figure(1) 57 | subplot(224) 58 | draw_bg 59 | x0=[0,.1];timecourse_AE(x0);disp('1') 60 | x0=[0,-.1];timecourse_AE(x0);disp('2') 61 | x0=[.1,0];timecourse_AE(x0);disp('3') 62 | x0=[-.1,0];timecourse_AE(x0);disp('4') 63 | x0=[1,1]/10*sqrt(2)/2;timecourse_AE(x0);disp('5') 64 | x0=[-1,-1]/10*sqrt(2)/2;timecourse_AE(x0);disp('6') 65 | x0=[-1,1]/10*sqrt(2)/2;timecourse_AE(x0);disp('7') 66 | x0=[1,-1]/10*sqrt(2)/2;timecourse_AE(x0);disp('8') 67 | xlabel('x-position (m)') 68 | ylabel('y-position (m)') 69 | title('D', 'fontsize', 12) 70 | hold off 71 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/ode_yu_AE.m: -------------------------------------------------------------------------------- 1 | function [t,Y]=ode_yu_AE(t0,tf,x0,dt) 2 | h=dt; % stepsize % step numbers, 100 is the final time 3 | t=t0:dt:tf; % initial time 4 | y=x0; 5 | Y=[]; 6 | for clock=t 7 | %clock 8 | y = y + motor2DAE(clock,y)*h; 9 | Y = [Y y]; 10 | end 11 | Y=Y'; 12 | end 13 | 14 | 15 | function dX = motor2DAE(t,X) 16 | 17 | para2; 18 | 19 | x=X(1:6); 20 | z=X(7:8); 21 | 22 | 23 | dx=x; 24 | 25 | x=x(:); 26 | 27 | u=-K*x; 28 | 29 | w=randn(2,1)*sqrt(dt); 30 | 31 | M=[c1*u(1) c2*u(2); -c2*u(1) c1*u(2)]; 32 | 33 | v=M*w; % control dependent noise 34 | 35 | f=z; 36 | 37 | dx(1:4)=A*x(1:4)+B*(x(5:6)+f); 38 | dx(5:6)=B1*(-x(5:6)+u+v./dt); 39 | dz=[0;0];%-1/0.01*(z-VF*[x(3);x(4)]); 40 | dX=[dx;dz]; 41 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/ode_yu_AL.m: -------------------------------------------------------------------------------- 1 | function [t,Y]=ode_yu_AL(t0,tf,x0,dt) 2 | h=dt; % stepsize % step numbers, 100 is the final time 3 | t=t0:dt:tf; % initial time 4 | y=x0; 5 | Y=[]; 6 | for clock=t 7 | %clock 8 | y=y+motor2DVF(clock,y)*h; 9 | Y=[Y y]; 10 | end 11 | Y=Y'; 12 | end 13 | 14 | 15 | function dX=motor2DVF(t,X) 16 | 17 | para2; 18 | 19 | x=X(1:6); 20 | z=X(7:8); 21 | 22 | 23 | dx=x; 24 | 25 | x=x(:); 26 | 27 | u=-K*x; 28 | 29 | w=randn(2,1)*sqrt(dt); 30 | 31 | M=[c1*u(1) c2*u(2); -c2*u(1) c1*u(2)]; 32 | 33 | v=M*w; % control dependent noise 34 | 35 | f=z; 36 | 37 | VF=[-10.1 -11.2; -11.2 11.1]; 38 | 39 | dx(1:4)=A*x(1:4)+B*(x(5:6)+f); 40 | dx(5:6)=B1*(-x(5:6)+u+v./dt); 41 | dz=-1/0.01*(z-VF*[x(3);x(4)]); 42 | dX=[dx;dz]; 43 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/ode_yu_NF.m: -------------------------------------------------------------------------------- 1 | function [t,Y]=ode_yu_NF(t0,tf,x0,dt) 2 | h=dt; % stepsize % step numbers, 100 is the final time 3 | t=t0:dt:tf; % initial time 4 | y=x0; 5 | Y=[]; 6 | for clock=t 7 | %clock 8 | y=y+motor2DNF(clock,y)*h; 9 | Y=[Y y]; 10 | end 11 | Y=Y'; 12 | end 13 | 14 | 15 | function dX=motor2DNF(t,X) 16 | 17 | para; 18 | 19 | x=X(1:6); 20 | z=X(7:8); 21 | 22 | 23 | dx=x; 24 | 25 | x=x(:); 26 | 27 | u=-K*x; 28 | 29 | w=randn(2,1)*sqrt(dt); 30 | 31 | M=[c1*u(1) c2*u(2); -c2*u(1) c1*u(2)]; 32 | 33 | v=M*w; % control dependent noise 34 | 35 | f=z; 36 | 37 | VF=[-10.1 -11.2; -11.2 11.1]; 38 | 39 | dx(1:4)=A*x(1:4)+B*(x(5:6)+f); 40 | dx(5:6)=B1*(-x(5:6)+u+v./dt); 41 | dz=[0;0]; 42 | dX=[dx;dz]; 43 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/ode_yu_VF.m: -------------------------------------------------------------------------------- 1 | function [t,Y]=ode_yu_VF(t0,tf,x0,dt) 2 | h=dt; % stepsize % step numbers, 100 is the final time 3 | t=t0:dt:tf; % initial time 4 | y=x0; 5 | Y=[]; 6 | for clock=t 7 | %clock 8 | y=y+motor2DVF(clock,y)*h; 9 | Y=[Y y]; 10 | end 11 | Y=Y'; 12 | end 13 | 14 | 15 | function dX=motor2DVF(t,X) 16 | 17 | para; 18 | 19 | x=X(1:6); 20 | z=X(7:8); 21 | 22 | 23 | dx=x; 24 | 25 | x=x(:); 26 | 27 | u=-K*x; 28 | 29 | w=randn(2,1)*sqrt(dt); 30 | 31 | M=[c1*u(1) c2*u(2); -c2*u(1) c1*u(2)]; 32 | 33 | v=M*w; % control dependent noise 34 | 35 | f=z; 36 | 37 | VF=[-10.1 -11.2; -11.2 11.1]; 38 | 39 | dx(1:4)=A*x(1:4)+B*(x(5:6)+f); 40 | dx(5:6)=B1*(-x(5:6)+u+v./dt); 41 | dz=-1/0.01*(z-VF*[x(3);x(4)]); 42 | dX=[dx;dz]; 43 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/para.m: -------------------------------------------------------------------------------- 1 | %para.m 2 | 3 | m = 2;%1; % mass 4 | b = 10; % viscosity 5 | c1 = 0.15/1.5; 6 | c2 = 0.05/1.5; 7 | dt = 0.005; 8 | tau = 0.05; 9 | 10 | A =[0 0 1 0; 11 | 0 0 0 1; 12 | 0 0 -b/m 0; 13 | 0 0 0 -b/m]; 14 | 15 | A0=[0 0 1 0; 16 | 0 0 0 1; 17 | 0 0 -b/m 0; 18 | 0 0 0 -b/m]; 19 | 20 | 21 | B=[0 0; 22 | 0 0; 23 | 1/m 0; 24 | 0 1/m]; 25 | B1=[1/tau 0; 26 | 0 1/tau]; 27 | 28 | A12=[A B; 29 | zeros(2,4) -B1]; 30 | B12=[zeros(4,2); 31 | B1]; 32 | 33 | 34 | %Q=10*eye(4); 35 | Q1=diag([1000*4,1000*4,10,10]); R1=0.1*eye(2); 36 | 37 | %Q1=diag([1000,1000,25,25]); R1=0.01*eye(2); % after learning 38 | Q1(1,2)=0; 39 | Q1(2,1)=Q1(1,2); 40 | 41 | 42 | K1=lqr(A,B,Q1,R1); 43 | 44 | Q2=1*eye(2); 45 | R2=0.1*eye(2); 46 | 47 | K2=lqr(zeros(2),B1,Q2,R2); 48 | 49 | R=0.01*eye(2); 50 | 51 | K=K2*[K1,eye(2)]; 52 | 53 | 54 | %disp(['check if it is very close to zero:', num2str(norm(P*A+A'*P-P*B*inv(R+D1'*P*D1+D2'*P*D2)*B'*P+Q))]) 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/para2.m: -------------------------------------------------------------------------------- 1 | %para.m 2 | 3 | m = 2;%1; % mass 4 | b = 10; % viscosity 5 | c1 = 0.15/2; 6 | c2 = 0.05/2; 7 | dt = 0.005; 8 | tau = 0.05; 9 | 10 | A =[0 0 1 0; 11 | 0 0 0 1; 12 | 0 0 -b/m 0; 13 | 0 0 0 -b/m]; 14 | 15 | A0=[0 0 1 0; 16 | 0 0 0 1; 17 | 0 0 -b/m 0; 18 | 0 0 0 -b/m]; 19 | 20 | 21 | B=[0 0; 22 | 0 0; 23 | 1/m 0; 24 | 0 1/m]; 25 | B1=[1/tau 0; 26 | 0 1/tau]; 27 | 28 | A12=[A B; 29 | zeros(2,4) -B1]; 30 | B12=[zeros(4,2); 31 | B1]; 32 | 33 | R1=0.01*eye(2); % after learning 34 | Q1=diag([300,200,10,10]); Q1(3,4)=-5;Q1(4,3)=Q1(3,4); 35 | Q1(1,2)=0;Q1(2,1)=Q1(1,2); 36 | 37 | K1=lqr(A,B,Q1,R1); 38 | 39 | Q2=1*eye(2); 40 | R2=0.1*eye(2); 41 | 42 | K2=lqr(zeros(2),B1,Q2,R2); 43 | 44 | R=0.01*eye(2); 45 | 46 | K=K2*[K1,eye(2)]; 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/timecourse_AE.m: -------------------------------------------------------------------------------- 1 | %SimuNF_nl.m 2 | %tic 3 | function []=timecourse_AE(x0) 4 | 5 | 6 | dt = 0.005; 7 | tf = 2; 8 | K = [547.6615 -6.6753 100.8891 -19.1842 3.1623 0; 9 | 8.1756 447.1638 -19.1842 96.0024 0 3.1623]; 10 | [t1,y1] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, false); 11 | [t2,y2] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, false); 12 | [t3,y3] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, false); 13 | [t4,y4] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, false); 14 | [t5,y5] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, false); 15 | 16 | plot(y1(:,1)+x0(1),y1(:,2)+x0(2), 'b-', ... 17 | y2(:,1)+x0(1),y2(:,2)+x0(2), 'b-', ... 18 | y3(:,1)+x0(1),y3(:,2)+x0(2), 'b-', ... 19 | y4(:,1)+x0(1),y4(:,2)+x0(2), 'b-', ... 20 | y5(:,1)+x0(1),y5(:,2)+x0(2), 'b-', ... 21 | 'Linewidth', 1.2) 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/timecourse_AL.m: -------------------------------------------------------------------------------- 1 | %SimuNF_nl.m 2 | %tic 3 | function []=timecourse_AL(x0,i) 4 | para 5 | tf=1.5; 6 | [t1,y1]=ode_yu_AL(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 7 | [t2,y2]=ode_yu_AL(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 8 | [t3,y3]=ode_yu_AL(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 9 | [t4,y4]=ode_yu_AL(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 10 | [t5,y5]=ode_yu_AL(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 11 | 12 | 13 | figure(1) 14 | subplot(223) 15 | % 16 | % hold on 17 | % draw_bg 18 | % line([-0.03 -0.03],[-0.2 0.01], 'linewidth', 2, 'color', [0,0,0]) 19 | % line([ 0.03 0.03],[-0.2 0.01], 'linewidth', 2, 'color', [0,0,0]) 20 | plot(y1(:,1)+x0(1),y1(:,2)+x0(2), 'b-', ... 21 | y2(:,1)+x0(1),y2(:,2)+x0(2), 'b-', ... 22 | y3(:,1)+x0(1),y3(:,2)+x0(2), 'b-', ... 23 | y4(:,1)+x0(1),y4(:,2)+x0(2), 'b-', ... 24 | y5(:,1)+x0(1),y5(:,2)+x0(2), 'b-', ... 25 | 'Linewidth', 1.2) 26 | 27 | 28 | figure(2) 29 | subplot(8,3,(i-1)*3+3) 30 | plot(t1,sqrt(y1(:,3).^2+y1(:,4).^2), 'b-', ... 31 | t2,sqrt(y2(:,3).^2+y2(:,4).^2), 'b-', ... 32 | t3,sqrt(y3(:,3).^2+y3(:,4).^2), 'b-', ... 33 | t4,sqrt(y4(:,3).^2+y4(:,4).^2), 'b-', ... 34 | t5,sqrt(y5(:,3).^2+y5(:,4).^2), 'b-', ... 35 | 'Linewidth', 1.2) 36 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/timecourse_NF.m: -------------------------------------------------------------------------------- 1 | %SimuNF_nl.m 2 | %tic 3 | function []=timecourse_NF(x0,i) 4 | para 5 | tf=1.5; 6 | [t1,y1]=ode_yu_NF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 7 | [t2,y2]=ode_yu_NF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 8 | [t3,y3]=ode_yu_NF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 9 | [t4,y4]=ode_yu_NF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 10 | [t5,y5]=ode_yu_NF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 11 | 12 | 13 | figure(1) 14 | subplot(221) 15 | % 16 | % hold on 17 | % draw_bg 18 | % line([-0.03 -0.03],[-0.2 0.01], 'linewidth', 2, 'color', [0,0,0]) 19 | % line([ 0.03 0.03],[-0.2 0.01], 'linewidth', 2, 'color', [0,0,0]) 20 | plot(y1(:,1)+x0(1),y1(:,2)+x0(2), 'b-', ... 21 | y2(:,1)+x0(1),y2(:,2)+x0(2), 'b-', ... 22 | y3(:,1)+x0(1),y3(:,2)+x0(2), 'b-', ... 23 | y4(:,1)+x0(1),y4(:,2)+x0(2), 'b-', ... 24 | y5(:,1)+x0(1),y5(:,2)+x0(2), 'b-', ... 25 | 'Linewidth', 1.2) 26 | 27 | 28 | figure(2) 29 | subplot(8,3,(i-1)*3+1) 30 | plot(t1,sqrt(y1(:,3).^2+y1(:,4).^2), 'b-', ... 31 | t2,sqrt(y2(:,3).^2+y2(:,4).^2), 'b-', ... 32 | t3,sqrt(y3(:,3).^2+y3(:,4).^2), 'b-', ... 33 | t4,sqrt(y4(:,3).^2+y4(:,4).^2), 'b-', ... 34 | t5,sqrt(y5(:,3).^2+y5(:,4).^2), 'b-', ... 35 | 'Linewidth', 1.2) 36 | 37 | figure(1) 38 | end 39 | 40 | -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/old/timecourse_VF.m: -------------------------------------------------------------------------------- 1 | %SimuNF_nl.m 2 | %tic 3 | function []=timecourse_VF(x0,i) 4 | para 5 | tf=1.5; 6 | [t1,y1]=ode_yu_VF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 7 | [t2,y2]=ode_yu_VF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 8 | [t3,y3]=ode_yu_VF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 9 | [t4,y4]=ode_yu_VF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 10 | [t5,y5]=ode_yu_VF(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt); 11 | 12 | 13 | %% 14 | figure(1) 15 | subplot(222) 16 | % 17 | % hold on 18 | % draw_bg 19 | % line([-0.03 -0.03],[-0.2 0.01], 'linewidth', 2, 'color', [0,0,0]) 20 | % line([ 0.03 0.03],[-0.2 0.01], 'linewidth', 2, 'color', [0,0,0]) 21 | plot(y1(:,1)+x0(1),y1(:,2)+x0(2), 'b-', ... 22 | y2(:,1)+x0(1),y2(:,2)+x0(2), 'b-', ... 23 | y3(:,1)+x0(1),y3(:,2)+x0(2), 'b-', ... 24 | y4(:,1)+x0(1),y4(:,2)+x0(2), 'b-', ... 25 | y5(:,1)+x0(1),y5(:,2)+x0(2), 'b-', ... 26 | 'Linewidth', 1.2) 27 | 28 | 29 | figure(2) 30 | subplot(8,3,(i-1)*3+2) 31 | plot(t1,sqrt(y1(:,3).^2+y1(:,4).^2), 'b-', ... 32 | t2,sqrt(y2(:,3).^2+y2(:,4).^2), 'b-', ... 33 | t3,sqrt(y3(:,3).^2+y3(:,4).^2), 'b-', ... 34 | t4,sqrt(y4(:,3).^2+y4(:,4).^2), 'b-', ... 35 | t5,sqrt(y5(:,3).^2+y5(:,4).^2), 'b-', ... 36 | 'Linewidth', 1.2) 37 | 38 | figure(1) 39 | %hold on 40 | %hold off 41 | %axis equal 42 | %axis([-0.075 0.075 -0.3 .075]) 43 | 44 | 45 | end -------------------------------------------------------------------------------- /Robust-ADP/Chapter7_Example2/plotTimecourse.m: -------------------------------------------------------------------------------- 1 | %SimuNF_nl.m 2 | %tic 3 | function [] = plotTimecourse(x0, str, i) 4 | 5 | 6 | dt = 0.005; 7 | tf = 2; 8 | switch str 9 | case 'NF' 10 | isField = false; 11 | offset = 1; 12 | K = [632.4555 0 68.3772 0 3.1623 0 13 | 0 632.4555 0 68.3772 0 3.1623]; 14 | case 'VF' 15 | isField = true; 16 | offset = 2; 17 | K = [632.4555 0 68.3772 0 3.1623 0 18 | 0 632.4555 0 68.3772 0 3.1623]; 19 | case 'AL' 20 | isField = true; 21 | offset = 3; 22 | K = [547.6615 -6.6753 100.8891 -19.1842 3.1623 0; 23 | 8.1756 447.1638 -19.1842 96.0024 0 3.1623]; 24 | case 'AE' 25 | offset = nan; 26 | isField = false; 27 | K = [547.6615 -6.6753 100.8891 -19.1842 3.1623 0; 28 | 8.1756 447.1638 -19.1842 96.0024 0 3.1623]; 29 | end 30 | 31 | [t1,y1] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, isField); 32 | [t2,y2] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, isField); 33 | [t3,y3] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, isField); 34 | [t4,y4] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, isField); 35 | [t5,y5] = LocalSDESolver(0,tf,[-x0(1),-x0(2),0,0,0,0,0,0]',dt, K, isField); 36 | 37 | figure(1) 38 | plot(y1(:,1)+x0(1),y1(:,2)+x0(2), 'b-', ... 39 | y2(:,1)+x0(1),y2(:,2)+x0(2), 'b-', ... 40 | y3(:,1)+x0(1),y3(:,2)+x0(2), 'b-', ... 41 | y4(:,1)+x0(1),y4(:,2)+x0(2), 'b-', ... 42 | y5(:,1)+x0(1),y5(:,2)+x0(2), 'b-', ... 43 | 'Linewidth', 1.2) 44 | 45 | if ~isnan(offset) 46 | figure(2) 47 | subplot(8,3,(i-1)*3 + offset) 48 | plot(t1,sqrt(y1(:,3).^2+y1(:,4).^2), 'b-', ... 49 | t2,sqrt(y2(:,3).^2+y2(:,4).^2), 'b-', ... 50 | t3,sqrt(y3(:,3).^2+y3(:,4).^2), 'b-', ... 51 | t4,sqrt(y4(:,3).^2+y4(:,4).^2), 'b-', ... 52 | t5,sqrt(y5(:,3).^2+y5(:,4).^2), 'b-', ... 53 | 'Linewidth', 1.2) 54 | figure(1) 55 | end 56 | end 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Robust-ADP/Readme: -------------------------------------------------------------------------------- 1 | This code is from http://yu-jiang.github.io/radpbook/ 2 | 3 | https://github.com/yu-jiang/RADPBook 4 | 5 | Welcome to the webpage of the book "Robust Adaptive Dynamic Programming", written by Yu Jiang and Zhong-Ping Jiang. This webpage is created to provide lastest news and supplementary materials related to the book, such as source code that can reproduce the numerical examples covered in the book. 6 | -------------------------------------------------------------------------------- /Robust-ADP/publishandpack.m: -------------------------------------------------------------------------------- 1 | % Publish and pack all examples 2 | 3 | %% Publish all examples 4 | % Clean up before start 5 | clear; bdclose all; close all; clc 6 | % Clean up the PUBLISH folder 7 | pubdir = [pwd '\publish\']; 8 | if exist('publish', 'dir') 9 | rmdir(pubdir,'s'); 10 | end 11 | mkdir(pubdir); 12 | 13 | %% Publish Example 2.1 14 | disp('-->Publishing Example 2.1') 15 | cpath = pwd; % Save the root level path 16 | options = struct('outputDir',[cpath '\publish\Ch2Ex1\']); 17 | cd('Chapter2_Example1') 18 | publish('Ch2Ex1_main.m', options); 19 | movefile([cpath '\publish\Ch2Ex1\Ch2Ex1_main.html'], [cpath '\publish\Ch2Ex1\index.html']); 20 | cd(cpath) 21 | 22 | %% Publish Example 2.2 23 | disp('-->Publishing Example 2.2') 24 | cpath = pwd; % Save the root level path 25 | options = struct('outputDir',[cpath '\publish\Ch2Ex2\']); 26 | cd('Chapter2_Example2') 27 | publish('Ch2Ex2_main.m', options); 28 | movefile([cpath '\publish\Ch2Ex2\Ch2Ex2_main.html'], [cpath '\publish\Ch2Ex2\index.html']); 29 | cd(cpath) 30 | clear; close all; % clean up 31 | 32 | %% Publish Example 3.1 33 | disp('-->Publishing Example 3.1') 34 | cpath = pwd; % Save the root level path 35 | options = struct('outputDir',[cpath '\publish\Ch3Ex1\']); 36 | cd('Chapter3_Example1') 37 | publish('Ch3Ex1_main.m', options); 38 | movefile([cpath '\publish\Ch3Ex1\Ch3Ex1_main.html'], [cpath '\publish\Ch3Ex1\index.html']); 39 | cd(cpath) 40 | clear; close all; % clean up 41 | 42 | %% Chapter 4 43 | % Setup CVX 44 | addpath('tools'); 45 | run .\tools\setuptools.m 46 | %% Publish Example 4.1 47 | disp('-->Publishing Example 4.1') 48 | cpath = pwd; % Save the root level path 49 | options = struct('outputDir',[cpath '\publish\Ch4Ex1\']); 50 | cd('Chapter4_Example1') 51 | publish('Ch4Ex1_main.m', options); 52 | movefile([cpath '\publish\Ch4Ex1\Ch4Ex1_main.html'], [cpath '\publish\Ch4Ex1\index.html']); 53 | cd(cpath) 54 | clear; close all; % clean up 55 | 56 | 57 | %% Publish Example 4.2 58 | disp('-->Publishing Example 4.2') 59 | cpath = pwd; % Save the root level path 60 | options = struct('outputDir',[cpath '\publish\Ch4Ex2\']); 61 | cd('Chapter4_Example2') 62 | publish('Ch4Ex2_main.m', options); 63 | movefile([cpath '\publish\Ch4Ex2\Ch4Ex2_main.html'], [cpath '\publish\Ch4Ex2\index.html']); 64 | cd(cpath) 65 | clear; close all; % clean up 66 | 67 | %% Publish Example 4.3 68 | disp('-->Publishing Example 4.3') 69 | cpath = pwd; % Save the root level path 70 | options = struct('outputDir',[cpath '\publish\Ch4Ex3\']); 71 | cd('Chapter4_Example3') 72 | publish('Ch4Ex3_main.m', options); 73 | movefile([cpath '\publish\Ch4Ex3\Ch4Ex3_main.html'], [cpath '\publish\Ch4Ex3\index.html']); 74 | cd(cpath) 75 | clear; close all; % clean up 76 | 77 | %% Publish Example 4.4 78 | disp('-->Publishing Example 4.4') 79 | cpath = pwd; % Save the root level path 80 | options = struct('outputDir',[cpath '\publish\Ch4Ex4\']); 81 | cd('Chapter4_Example4') 82 | publish('Ch4Ex4_main.m', options); 83 | movefile([cpath '\publish\Ch4Ex4\Ch4Ex4_main.html'], [cpath '\publish\Ch4Ex4\index.html']); 84 | cd(cpath) 85 | clear; close all; % clean up 86 | 87 | 88 | %% Publish Example 5.1 89 | disp('-->Publishing Example 5.1') 90 | cpath = pwd; % Save the root level path 91 | options = struct('outputDir',[cpath '\publish\Ch5Ex1\']); 92 | cd('Chapter5_Example1') 93 | publish('Ch5Ex1_main.m', options); 94 | movefile([cpath '\publish\Ch5Ex1\Ch5Ex1_main.html'], [cpath '\publish\Ch5Ex1\index.html']); 95 | cd(cpath) 96 | clear; close all; % clean up 97 | 98 | %% Publish Example 5.2 99 | disp('-->Publishing Example 5.2') 100 | cpath = pwd; % Save the root level path 101 | options = struct('outputDir',[cpath '\publish\Ch5Ex2\']); 102 | cd('Chapter5_Example2') 103 | publish('Ch5Ex2_main.m', options); 104 | movefile([cpath '\publish\Ch5Ex2\Ch5Ex2_main.html'], [cpath '\publish\Ch5Ex2\index.html']); 105 | cd(cpath) 106 | clear; close all; % clean up 107 | 108 | 109 | %% Publish Example 6.1 110 | disp('-->Publishing Example 6.1') 111 | cpath = pwd; % Save the root level path 112 | options = struct('outputDir',[cpath '\publish\Ch6Ex1\']); 113 | cd('Chapter6_Example1') 114 | publish('Ch6Ex1_main.m', options); 115 | movefile([cpath '\publish\Ch6Ex1\Ch6Ex1_main.html'], [cpath '\publish\Ch6Ex1\index.html']); 116 | cd(cpath) 117 | clear; close all; % clean up 118 | 119 | %% Publish Example 7.1 120 | disp('-->Publishing Example 7.1') 121 | cpath = pwd; % Save the root level path 122 | options = struct('outputDir',[cpath '\publish\Ch7Ex1\']); 123 | cd('Chapter7_Example1') 124 | publish('Ch7Ex1_main.m', options); 125 | movefile([cpath '\publish\Ch7Ex1\Ch7Ex1_main.html'], [cpath '\publish\Ch7Ex1\index.html']); 126 | cd(cpath) 127 | clear; close all; % clean up 128 | 129 | %% Publish Example 7.2 130 | disp('-->Publishing Example 7.2') 131 | cpath = pwd; % Save the root level path 132 | options = struct('outputDir',[cpath '\publish\Ch7Ex2\']); 133 | cd('Chapter7_Example2') 134 | publish('Ch7Ex2_main.m', options); 135 | movefile([cpath '\publish\Ch7Ex2\Ch7Ex2_main.html'], [cpath '\publish\Ch7Ex2\index.html']); 136 | cd(cpath) 137 | clear; close all; % clean up 138 | 139 | %% Pack all examples 140 | % Create zip files for each example 141 | %% Publish all examples 142 | % Clean up before start 143 | clear; bdclose all; close all; clc 144 | % Clean up the PUBLISH folder 145 | pubdir = [pwd '\publish\']; 146 | if exist('publish', 'dir') 147 | delete([pubdir, '*.zip']) 148 | else 149 | mkdir(pubdir); 150 | end 151 | 152 | cpath = pwd; % Save the root level path 153 | %% Packing Example 2.1 154 | disp('-->Packing Example 2.1') 155 | cd('Chapter2_Example1') 156 | myfile = fullfile(cpath,'publish','RADP_Ch2Ex1.zip'); 157 | zip(myfile, {'*.m', '*.slx'}); 158 | cd(cpath) 159 | 160 | %% Packing Example 2.2 161 | disp('-->Packing Example 2.2') 162 | cd('Chapter2_Example2') 163 | myfile = fullfile(cpath,'publish','RADP_Ch2Ex2.zip'); 164 | zip(myfile, {'*.m'}); 165 | cd(cpath) 166 | 167 | %% Packing Example 3.1 168 | disp('-->Packing Example 3.1') 169 | cd('Chapter3_Example1') 170 | myfile = fullfile(cpath,'publish','RADP_Ch3Ex1.zip'); 171 | zip(myfile, {'*.m'}); 172 | cd(cpath) 173 | 174 | %% Packing Example 4.1 175 | disp('-->Packing Example 4.1') 176 | cd('Chapter4_Example1') 177 | myfile = fullfile(cpath,'publish','RADP_Ch4Ex1.zip'); 178 | zip(myfile, {'*.m'}); 179 | cd(cpath) 180 | 181 | %% Packing Example 4.2 182 | disp('-->Packing Example 4.2') 183 | cd('Chapter4_Example2') 184 | myfile = fullfile(cpath,'publish','RADP_Ch4Ex2.zip'); 185 | zip(myfile, {'*.m'}); 186 | cd(cpath) 187 | 188 | %% Packing Example 4.3 189 | disp('-->Packing Example 4.3') 190 | cd('Chapter4_Example3') 191 | myfile = fullfile(cpath,'publish','RADP_Ch4Ex3.zip'); 192 | zip(myfile, {'*.m'}); 193 | cd(cpath) 194 | 195 | %% Packing Example 4.4 196 | disp('-->Packing Example 4.4') 197 | cd('Chapter4_Example4') 198 | myfile = fullfile(cpath,'publish','RADP_Ch4Ex4.zip'); 199 | zip(myfile, {'*.m'}); 200 | cd(cpath) 201 | 202 | %% Packing Example 5.1 203 | disp('-->Packing Example 5.1') 204 | cd('Chapter5_Example1') 205 | myfile = fullfile(cpath,'publish','RADP_Ch5Ex1.zip'); 206 | zip(myfile, {'*.m'}); 207 | cd(cpath) 208 | 209 | %% Packing Example 5.2 210 | disp('-->Packing Example 5.2') 211 | cd('Chapter5_Example2') 212 | myfile = fullfile(cpath,'publish','RADP_Ch5Ex2.zip'); 213 | zip(myfile, {'*.m'}); 214 | cd(cpath) 215 | 216 | %% Packing Example 6.1 217 | disp('-->Packing Example 6.1') 218 | cd('Chapter6_Example1') 219 | myfile = fullfile(cpath,'publish','RADP_Ch6Ex1.zip'); 220 | zip(myfile, {'*.m'}); 221 | cd(cpath) 222 | 223 | %% Packing Example 7.1 224 | disp('-->Packing Example 7.1') 225 | cd('Chapter7_Example1') 226 | myfile = fullfile(cpath,'publish','RADP_Ch7Ex1.zip'); 227 | zip(myfile, {'*.m'}); 228 | cd(cpath) 229 | 230 | %% Packing Example 7.2 231 | disp('-->Packing Example 7.2') 232 | cd('Chapter7_Example2') 233 | myfile = fullfile(cpath,'publish','RADP_Ch7Ex2.zip'); 234 | zip(myfile, {'*.m'}); 235 | cd(cpath) 236 | 237 | %% Packing Tools 238 | disp('-->Packing Tools') 239 | cd(cpath) 240 | myfile = fullfile(cpath,'publish','tools.zip'); 241 | zip(myfile, 'tools'); 242 | 243 | 244 | -------------------------------------------------------------------------------- /Robust-ADP/tRADP_Examples.m: -------------------------------------------------------------------------------- 1 | % Test examples -------------------------------------------------------------------------------- /code MAK HJB.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/code MAK HJB.zip -------------------------------------------------------------------------------- /code MAK HJI.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/code MAK HJI.zip -------------------------------------------------------------------------------- /constrained input/Readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /constrained input/code MAK HJB.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/constrained input/code MAK HJB.zip -------------------------------------------------------------------------------- /constrained input/code MAK HJI.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/constrained input/code MAK HJI.zip -------------------------------------------------------------------------------- /cooperative game/Cooperative game.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/cooperative game/Cooperative game.rar -------------------------------------------------------------------------------- /cooperative game/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /experience replay/concurrent learning_.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/experience replay/concurrent learning_.zip -------------------------------------------------------------------------------- /experience replay/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /game theory ctrl in DC microgrid.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/game theory ctrl in DC microgrid.zip -------------------------------------------------------------------------------- /multi-agent game/CT graph games.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/multi-agent game/CT graph games.zip -------------------------------------------------------------------------------- /multi-agent game/DT GG Q.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/multi-agent game/DT GG Q.zip -------------------------------------------------------------------------------- /multi-agent game/DT GG.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/multi-agent game/DT GG.zip -------------------------------------------------------------------------------- /multi-agent game/game theory ctrl in DC microgrid.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/multi-agent game/game theory ctrl in DC microgrid.zip -------------------------------------------------------------------------------- /multi-agent game/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /nonzero-sum game/nonlinear.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/nonzero-sum game/nonlinear.rar -------------------------------------------------------------------------------- /nonzero-sum game/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /nonzero-sum game/连续linear system.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/nonzero-sum game/连续linear system.rar -------------------------------------------------------------------------------- /online synch Hinf.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/online synch Hinf.zip -------------------------------------------------------------------------------- /online synch opt ctrl.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/online synch opt ctrl.zip -------------------------------------------------------------------------------- /zero-sum game/Readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /zero-sum game/code MAK HJI.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/zero-sum game/code MAK HJI.zip -------------------------------------------------------------------------------- /zero-sum game/online synch Hinf.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tbyo/Collected-ADP-algorithm/dbd56e8f40a160e0f6a5525c1aacb692fe173ac9/zero-sum game/online synch Hinf.zip --------------------------------------------------------------------------------