Title: Fill in the blanks

Licence: CC BY-SA 4.0

Q: Let's solve the equation $$x - e^{-x} = 0$$ on the interval $$[0;1]$$ with an accuracy of $$\epsilon = 0.001$$ using the bisection method. Let's do this with a loop in MATLAB code.

Below is a sample, but it needs improvements (you must fill in the corresponding places).

Check your code in MatLab.

MatLab code:

% Define function, endpoints of the interval, and accuracy

f = @(x) x - [...](-x);

a = [...];

b =  [...];

epsilon = [...];

% Endpoints of the decreasing interval an and bn

an = a;

bn = b;

% Loop that decreases the interval. The loop is executed
% until the length of the interval bn-an has corresponding length

while bn - an >= [...]

    % Calculation of function values at three points

    fa = f(an);

    midpoint = [...]/2;

    fb = f(bn);

    % The if statement selects out two special cases

    if sign(fa) [...] sign(f(midpoint))

        % In this case, the f values at the midpoint and the left
         % endpoint are of the same sign. The midpoint
         % is taken as the new left endpoint.

        [...] = [...];

    else

        % In this case, the f values at the midpoint and the left
         % endpoint have different signs. The midpoint
         % is taken as the new right endpoint.

        [...] = [...];

    end

end

answer = [...]/2;

disp(answer);
A: exp; 0; 1; 0.001; 0.002/0,002; (an+bn)/(bn+an); ==; an; midpoint; bn; midpoint; (an+bn)/(bn+an)