
% Mário Budzeľ, 318654, I., II., 3ZIH1A.

function semestralna_praca_3_Mario_Budzel_318654(f,a,b,h,y0)
    clc

    % Preddefinované hodnoty ak je vstup prázdny
    if nargin == 0
        f = @ (x,y) [exp(x)*y(1)+x^2*y(1)+5*y(2)+sin(x);x*y(1)-y(2)+2*y(1)+cos(x)];
        y0 = [1;0];
        a = 0;
        b = 0.5;
        h = 0.1;
    end

    x = a:h:b;

    % Definícia vektora riešení y
    y = zeros(length(x), length(y0));
    for i = 1:length(y0)
        y(1,i) = y0(i);
    end

    % Modifikovaná Eulerova metóda - Runge-Kutta 4. rádu
    k(1,:) = f(x(1),y(1,:));
    k(2,:) = f(x(1) + h/2, y(1,:) + h/2*k(1,:));
    k(3,:) = f(x(1) + h/2, y(1,:) + h/2*k(2,:));
    k(4,:) = f(x(1) + h, y(1,:) + h*k(3,:));
    y(2,:) = y(1,:) + h*(k(1,:) + 2*k(2,:) + 2*k(3,:) + k(4,:))/6;
    
    % Formátovanie výstupu
    fprintf('<strong>\t\ti\t\t\t\t%s\t\t\t\t\t%s</strong>\n', ['x' char(hex2dec('1D62'))], ['y' char(hex2dec('1D62'))]);
    fprintf('<strong>-------------------------------------------------------</strong>\n');
    for i = 1:2
        fprintf('%9s %15s ', num2str(i-1), num2str(x(i)));
        for j = 1:length(y0)
            fprintf('%12s ', num2str(y(i,j)));
        end
        fprintf('\n')
    end

    % Dvojkroká Adam-Bashforth metóda
    for i = 2:length(x)-1
        adam_Bash_trans = ((3/2)*h*f(x(i),y(i,:)) - .5*h*f(x(i-1),y(i-1,:)))'; %Transponovanie výsledku pre korektnosť vektorového súčtu
        y(i+1,:) = y(i,:) + adam_Bash_trans;

        % Formátovanie výstupu 
        if i == length(x) - 1
            fprintf('<strong>%9s %15s</strong> ', num2str(i), num2str(x(i+1)));
        else
            fprintf('%9s %15s ', num2str(i), num2str(x(i+1)));
        end
    
        for j = 1:length(y0)
            if i == length(x) - 1
                fprintf('<strong>%12s</strong> ', num2str(y(i+1,j)));
            else
                fprintf('%12s ', num2str(y(i+1,j)));
            end
        end
        fprintf('\n');

    end

