N = 1000; % number of vector elements
v1 = 100 * rand(N, 1); % make vector with random elements between 0 - 100
v2 = 100 * rand(N, 1);
[m1, m2] = examplefun(v1, v2)

% if statement
if m1 > m2
    display('m1 > m2');
elseif m1 < m2
    display('m1 < m2');
else
    display('m1 = m2');
end

% for loop
% find the norm of v1
sum = 0;
for k = 1:N
    % calculate sum of squares
    sum = sum + v1(k)^2;
end
v1_norm = sqrt(sum)
% compare with matlab's built-in function
norm(v1);

% while loop
% use Leibniz formula for approximating pi
PI = 0;
k = 0;
errors = [];
while abs(PI - pi) > 1e-5
    PI = PI + 4 * (-1)^k / (2*k + 1);
    errors(k+1) = PI - pi;
    k = k + 1;
end
k
PI

%%% Plotting %%%
plot(1:k, errors)

% logarithmic scale 
figure; loglog(1:k, abs(errors), 'o-')
xlabel('Iteration')
ylabel('|Error|')
title('Approximating pi')

    