% Magnitude Optimum controller parameters for Pp_t1ex4_sim.slx
% plant and book parameters: PID Controller Tuning Using the Magnitude 
% Optimum Criterion, by K.G. Papadopoulos, Springer 2015, example page 51,
% equation (3.81), (3.82a/c) and idea page 75, equation (3.146)in turn

Vs=1;
nump=conv([1.6  1],[1.2  1]);
denop=conv([1 1],conv([0.9 1],conv([0.8 1],conv([0.2 1],[0.1 1]))));
denopF=conv(denop,[1.3  1]);
denopFq=conv(conv(denop,[1.5  1]),[1.5  1]);

REGu0            =bo_u_gen(11,Vs,nump,denopF),
REGu1            =bo_u_gen(12,Vs,nump,denopF),
REGu2            =bo_u_gen(13,Vs,nump,denopFq),

disp('For comparison Papadopoulos equations:') %see book page 46, table 3.1
Td=0;
Reg=Pp_type1(Vs,nump,denopF,Td), %rows: I,PI,PID; elements: [x y ti]
Pp_PI_samepar=[Reg(2,1)/Reg(2,3) Reg(2,1) Reg(2,3)]%wie bo_u_gen: VR TN TR0
Reg=Pp_type1(Vs,nump,denopFq,Td),
Pp_PID_samepar=[Reg(3,1)/Reg(3,3) Reg(3,1) Reg(3,3)  Reg(3,2)/Reg(3,1)],
% results are same as above with bo_u_gen

[REGd1,A11,F11]=bo_d_gen(12,Vs,nump,denopF),
[REGd2,A12,F12]=bo_d_gen(13,Vs,nump,denopFq),

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