
function [] = lab3P2 ()
    fprintf('For K=0: x=%2.3f, y=%2.3f, z=%2.3f\n',findXall(0));

    figure(1)
    fplot(@findX1, [0 12]); % Doesn't work with Octave
    title('findX1 with fplot');
    xlabel('K');
    ylabel('x1');
    grid on;

    figure(2)
    xVals = linspace(0, 12);
    yVals = arrayfun(@findX1,xVals);
    plot(xVals,yVals);
    grid on;
    title('findX1 with plot');
    xlabel('K');
    ylabel('x1');
end

function [x1] = findX1(K)
    % FINDX1 Finds the first element of the vector x for a given K
    % Inputs
    %   K - a constant
    % Outputs
    %   x1 - the first element of x
    x = findXall(K);
    x1 = x(1);

end

function [x] = findXall(K)
    % FINDXALL Finds the vector x for a given K
    % Inputs
    %   K - a constant
    % Outputs
    %   x - a vector
    A = [5-K -2 4;
         -5 4+K 3;
         5 2 1+K];

    b = [10; 4; -1];

    x = A\b;

end
