function fun_function
%Using Matlab, write a function 'calculate the sum of squares of all even numbers 
%between 2 and n. hints, the shortest version
%is with a for-loop; but you may try while and if combinations as well; 
%define a variable 'result' to which you add 
%the squared numbers at each step.


% another try and catch example -- we hand (intentionally) wrong input
% to our function, but the program will continue to execute and we can tell
% ourselves how dumb we were :)
try
    sum_of_even_squares('I am a naughty string!');
catch my_error
    disp('that''s dumb! you cannot use characters as limits for arrrays')
    disp('here is the error message: ')
    disp(my_error.message)
end

disp('But even though there was an error, we can continue our program.')
    
%initialize counter variable
N=1;

%some fancy visualization stuff -- open a figure
figure
%make sure plotted values will not be erased by new call of 'plot'
hold on

% first version: while loop -- count N to 15, get sum_of_even_squares
% for each N, display it, plot it (b=color blue, x=maker is a cross), 
% increment N by one

figure_handles = [0 0];

while(N<15)
    y = sum_of_even_squares(N);
    disp(y);

    % don't worry too much about this, here I plot a value y over N and get a 
    % handle (something like an ID) to the graphic symbol that has 
    % been plotted. I save this once in the vector figure_handles
    % so that I can hand this to the 'legend' function later on
    % which associates the symbols with the strings I give it.
    graphic_handle = plot(N,y, 'bx');
    if(N == 1)
        figure_handles(1) = graphic_handle;
    end
    N=N+1;
end

% second version: for loop -- count N from 1 to 14 (for loop ends when
% N > last value. rest is same as above
for N=1:14
    y = sum_of_even_squares(N);
    disp(y);    
    
    %see above ...
    graphic_handle = plot(N,y, 'ro');
    if(N == 1)
        figure_handles(2) = graphic_handle;
    end
end

% posh figure needs title, labled axes, and a legend
title('sum of even squares for N<15')
xlabel('N')
ylabel('sum of even squares')
% legend can include an option for location here I place it to the north
% west ... read documentation!
legend(figure_handles, 'while', 'for', 'Location', 'NorthWest');

% turn of the hold button ... another 'plot' would erase all the values
% that exist in the figure
hold off

return