% Magnitude Optimum controller parameters for Pp_t3ex1plus_sim.slx;
% plant example according to K.G. Papadopoulos, PID Controller Tuning Using
% the Magnitude Optimum Criterion, Springer 2015, pp. 127/128,
% equations (5.36)/(5.37), (5.38)/(5.39), (5.53) 
% here: ideal PID structure, no consideration of non-ideal D-terms
%       - in contrast to simulation

%plant parameters: 5.2.3.1 "Process with dominant time constants":
% special feature: real plant integrator
Vs=0.254; nump=1;
denop=conv([1 0],conv([1 1],conv([1 1],conv([1 1],conv([1 1],[1 1])))));

% NOTE: "bo_u_gen(13,Vs,nump,denop)" would NOT be applicable
%                                    beause of plant integrator
[REGd1,A1,F1]=bo_d_gen(13,Vs,nump,denop);
[REGd2,A2,F2]=bo_d_gen(04,Vs,nump,denop);

REG127(2  , : )=REGd2;            %length=5
REG127(1  ,1:4)=REGd1,            %length=4

% special features: real plant integrator
% AND controller with double integrator modelled HERE via second plant
% integrator - see book page 128
denop1=conv([1  0],conv([1  0],conv([1 1],conv([1 1],conv([1 1],...
       conv([1 1],[1 1]))))));
% NOTE: "bo_u_gen(13,Vs,nump,denop1)" would NOT be applicable
%                                     beause of plant integrators
[REGd12,A12,F12]=bo_d_gen(13,Vs,nump,denop1);
[REGd22,A22,F22]=bo_d_gen(04,Vs,nump,denop1);

REG128(2  , : )=REGd22;             %length=5
REG128(1  ,1:4)=REGd12,             %length=4

disp('"Pp_t3ex1plus_sim.slx" will be called - compare parameters')
Pp_t3ex1plus_sim; sim('Pp_t3ex1plus_sim',350),
disp('Repeat bo_d_gen call at MATLAB promt, if search algorithm fails')
