% easy examples - Magnitude Optimum: use of bo_d_pltgen

% plant example: one third-order and one first-order time-delay element, 
Vs=1.5;  T1=5.1; T2=0.35;
plt_num=Vs;
plt_den=conv(conv(conv([T1  1],[T1  1]),[T1  1]),[T2  1]);
PLT=tf(plt_num,plt_den);  % LTI plant

% PID controller and pre-filter for delayed inputs:
[REG3,FIL3,A23,FLAG3]=bo_d_pltgen(3,PLT),
% PID2 controller and pre-filter for delayed inputs:
[REG4,FIL4,A24,FLAG4]=bo_d_pltgen(4,PLT),

Ru3=bo_u_gen(3,Vs,1,plt_den);
REGu3=tf([ Ru3(4)*Ru3(2)  Ru3(2)   1 ],[ 0  0  Ru3(3)  0 ]),
Ru4=bo_u_gen(4,Vs,1,plt_den);
REGu4=tf([ Ru4(5)*Ru4(2)  Ru4(4)*Ru4(2)  Ru4(2)   1 ],[ 0  0  Ru4(3)  0 ]),

%optimized pre-filter for delayed inputs:
FIL_OP3=bo_prefi_op(PLT,REGu3,REG3,FIL3,2),
FIL_OP4=bo_prefi_op(PLT,REGu4,REG4,FIL4,3),

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