% plant example according to K.G. Papadopoulos, PID Controller Tuning 
% Using the Magnitude Optimum Criterion, Springer, 2015, p. 106
% here: ideal PID structure, no consideration of non-ideal D-terms

Vs4=1; nump4=1; Td4=5;
denop4=conv([1  0],conv([1 1],conv([1 1],conv([1 1],conv([1 1],[1 1])))));
FSdefault=optimset('fsolve');
OPT=optimset(FSdefault,'Display','off','Diagnostics','off','TolFun',1e-24,...
                 'Algorithm','trust-region-reflective','FinDiffType','forward',...
                 'TolX',1e-24);
% Algorithm for fsolve must be: 'trust-region-reflective',
%  'levenberg-marquardt', 'trust-region-dogleg',
% FinDiffType: must be 'forward' or 'central'

A2=1;i=0;
while (A2(1)>1.0e-16)
      [Rdex4PID,A2,Flag]=bo_d_gen(13,Vs4,nump4,denop4,Td4,39,[],OPT);
      i=i+1;
end
Rdex4PID, A2, Flag, i

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