% Magnitude Optimum controller parameters for Pp_t3ex2plus_sim.slx;
% plant example according to K.G. Papadopoulos, PID Controller Tuning Using
% the Magnitude Optimum Criterion, Springer 2015, pp. 130/131,
% equations (5.43),(5.45) 
% here: ideal PID structure, no consideration of non-ideal D-terms
%       - in contrast to simulation 

%plant parameters 5.2.3.3 "Non minimum phase process":
%special feature: real plant integrator(s)
Vs=1.58;
nump=conv([-0.7  1],[-0.3  1]);
denop=conv([1  0],...
      conv([1  1],conv([0.9 1],conv([0.8 1],conv([0.1 1],[0.05 1])))));

[REGd1,A1,F1]=bo_d_gen(13,Vs,nump,denop);
[REGd2,A2,F2]=bo_d_gen(04,Vs,nump,denop);

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

% special features: real plant integrator, in contrast to book
% AND controller with double integrator modelled HERE via second plant
% integrator - see book page 130
denop1=conv([1  0],conv([1  0],...
       conv([1  1],conv([0.9 1],conv([0.8 1],conv([0.1 1],[0.05 1]))))));

[REGd12,A12,F12]=bo_d_gen(13,Vs,nump,denop1);
[REGd22,A22,F22]=bo_d_gen(04,Vs,nump,denop1);

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

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