Contents

inAuto03decBeta

Internal function of autoparam3beta. This routine is very similar to inAuto03decAlpha varying beta instead of alpha. (It should be combined and written in functions.)

breakfor = 0; % breakfor is used because it is only allowed in the same file as its corresponding FOR or WHILE statement.

Decision

    if i == 1
        if dp == 1
            dpfirst = 1;
        else
            dpfirst = 0;
        end
    end

    if startbis == 0
        if dpfirst == 1
            if dp == 1
                beta(i+1) = 10*beta(i);
                fprintf('-- Try a bigger beta: %g\n',beta(i+1));
            else % dp == 0
                a = beta(i-1); da = disAlphaBeta(i-1); % discrepancy of chosen start a
                b = beta(i); db = disAlphaBeta(i); % discrepancy of chosen start b
                fprintf('-- Start a and b was found: a = %g, b = %g\n',a,b);
                disp('-- Start Bisection method')
                startbis = 1;
                c = a + (b-a)/2; % new beta in the middle of a and b
                beta(i+1) = c;
                % Result: a < c < b (this is always the same)
            end
        else % dpfirst == 0
            if dp == 0
                beta(i+1) = beta(i)/10;
                fprintf('-- Try a smaller beta: %g\n',beta(i+1));
            else % dp == 1
                a = beta(i); da = disAlphaBeta(i); % discrepancy of chosen start a
                b = beta(i-1); db = disAlphaBeta(i-1); % discrepancy of chosen start b
                fprintf('-- Start a and b was found: a = %g, b = %g\n',a,b);
                disp('-- Start Bisection method')
                startbis = 1;
                c = a + (b-a)/2; % new beta in the middle of a and b
                beta(i+1) = c;
                % Result: a < c < b (this is always the same)
            end
        end

    % 3. Bisection method
    elseif startbis == 1
        dc = disAlphaBeta(i);
        % acb = [a c b; da dc db] % only for output
        disp(' ')
        fprintf('a = %g, c = %g, b = %g\n',a,c,b);
        fprintf('da = %g, dc = %g, db = %g\n',da,dc,db);
        disp(' ')
        if dp == 1 % discrepancy principle fulfilled
            a = c; da = dc; % Choose c as new a to be with new a UNDER the discrepancy principle border
        else
            b = c; db = dc; % Choose c as new b to be with new b OVER the discrepancy principle border
            if abs(dc-da) <= 1/10*delta
                fprintf('Automatic parameter choice stopped after %0d iterations.\n',i)
                fprintf('Reason: |dis(c)-dis(a)| <= 1/10*delta.\n')
                stopind = i;
                % Result is 'a' because it fulfills the discrepancy principle
                breakfor = 1; % was: break;
            elseif (c-a)/a <= 0.01
                fprintf('Automatic parameter choice stopped after %0d iterations.\n',i)
                fprintf('Reason: (c-a)/a <= 0.01.\n')
                stopind = i;
                % Result is 'a' because it fulfills the discrepancy principle
                breakfor = 1; % was: break;
            end
        end
        if breakfor == 0
            c = a + (b-a)/2; % new alpha in the middle of a and b
            beta(i+1) = c;
        end
    end

    if i == N
        fprintf('Automatic parameter choice stopped after %0d iterations (max. number reached).\n',i)
        stopind = N;
    end