## Contents

- inAuto03decAlpha
- Decision

## inAuto03decAlpha

Internal function of autoparam3, autoparam3alpha.

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

## Decision

        % 1. and 2.: Find an $\alpha$ called |a| that fulfills the discrepancy principle
        %            and a higher $\alpha$ called |b| that does not.

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

        if startbis == 0
            if dpfirst == 1
                if dp == 1
                    alpha(i+1) = 10*alpha(i);
                    fprintf('-- Try a bigger alpha: %g\n',alpha(i+1));
                else % dp == 0
                    a = alpha(i-1); da = disAlphaBeta(i-1); % discrepancy of chosen start a
                    b = alpha(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 alpha in the middle of a and b
                    alpha(i+1) = c;
                    % Result: a < c < b (This statement is always true.)
                end
            else % dpfirst == 0
                if dp == 0
                    alpha(i+1) = alpha(i)/10;
                    fprintf('-- Try a smaller alpha: %g\n',alpha(i+1));
                else % dp == 1
                    a = alpha(i); da = disAlphaBeta(i); % discrepancy of chosen start a
                    b = alpha(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 alpha in the middle of a and b
                    alpha(i+1) = c;
                    % Result: a < c < b (This statement is always true.)
                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
                alpha(i+1) = c;
            end
        end

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