% easy examples - Magnitude Optimum for delayed inputs
%case 4: : PID controller plus PT1 / oscillating element and integrator 

% definition of additional controller part "first-order time-delay element"
% featuring fixed time constant T4=Tau: 
Vs=2; Tau=1; D=0.5; T3=0.1; T4=Tau; Case4_bo_d_gen=[]; Case4_bo_d_speso=[];
     % approximation for use of bo_d_speso case 4 necessary, s^3 neglected:
     TauNeu=sqrt(Tau^2+T4*2*D*Tau); DNeu=(2*D*Tau+T4)/(2*TauNeu);
for i=1:3 k=10^(i-1);
   Reg=bo_d_gen(13,Vs,1,conv(conv([Tau^2  2*D*Tau  1],[k*T3  0]),[T4  1]));
         % bo_d_gen: code 13 or 3 means PID controller
         %           code 13: switch off for display commands
    Case4_bo_d_gen(i,:)=[Reg(1,1:2),Reg(1,4),Reg(1,4)*Reg(1,2),Reg(1,2)];
    [Reg1,Reg2] = bo_d_speso(14,Vs,DNeu,TauNeu,k*T3);  % OE and Int only
         % bo_d_speso: code 14 or 4 means case 4 regarding plant structure
         %             code 14: switch off for display commands
    Case4_bo_d_speso(i,:)=...
           [Reg1(1,1:2),Reg1(1,4),Reg2(1,1)*Reg2(1,2),Reg2(1,1)+Reg2(1,2)];
end
disp('Sequence of parameters VR, TN, TV, TFi2, TFi1:')
   format long,
   Case4_bo_d_gen, Tau_Approx_D_Approx=[TauNeu  DNeu], Case4_bo_d_speso
   format short,
disp('"bo_d_case4_02nae_sim.slx" will be called - compare parameters')
bo_d_case4_02nae_sim; sim('bo_d_case4_02nae_sim',100),
disp('Repeat bo_d_gen call at MATLAB promt, if search algorithm fails')
