function table_g_d = run_MOPB07_example_3()
%function table_g_d = run_MOPB07_example_3()
% execute Example 3 presented in the paper for g=1:4 and d=0:3 using Theorem 4 with (40)-(42) and
% Theorem 4 with (43)-(45).

table_g_d = [];
load data_AC5_COMPleib.mat;

lower = 900;
for method=1:2
    if method == 1
        upper = 2000; 
    else
        upper = 6000;
    end
    for g=1:1
        for d=0:1
            tic
            h2 = bisection_synth_h2(method,Ai,B1i,B2i,Ci,D1i,D2i,g,d,upper,lower,1e-2);            
            t=toc;
            table_g_d{method}(g+1,d+1) = h2;            
            fprintf('(g=%d,d=%d) -> %.4f -> %.2f sec\n',g,d,h2,t);
        end
    end
end

%___________________________________________________________________________________________________
function last = bisection_synth_h2(method,Ai,B1i,B2i,Ci,D1i,D2i,deg,d,h2_upper,h2_lower,ep)

a = h2_lower;
b = h2_upper;
g = abs(a-b);
last = (a+b)/2;

while g > ep
    n = (a+b)/2;
    param.h2 = n;
    if method == 1
        Info = synth_h2_P_MOPB07_IET_T4_yal(Ai,B1i,B2i,Ci,D1i,D2i,deg,d,param);
    else
        Info = synth_h2_D_MOPB07_IET_T4_yal(Ai,B1i,B2i,Ci,D1i,D2i,deg,d,param);
    end    
    if Info.h2 ~= 0 & Info.delta >= 0
        b = n;
        last = n;
    else
        a = n;
    end
    g = abs(a-b);
    %fprintf('(%d,%d) %.4f -> \t\t %e\n',deg,d,n,Info.delta);    
end