function [f1, f2, err] = exp_approx(x, n)
%% exp_approx: calculates an aproximation of exp(x)
% [f1, f2, err] = exp_approx(x,n)
% x  ... function argument, n  ... order of approximation
% f1 ... calculated value
% f2 ... „exact“ value (given by built-in function)
% err ... relativ. error
% example: [fa, fp] = exp_approx(4, 30);

N   = 0:n;
f   = (x.^N)./factorial(N);   % it is vectorized
f1  = sum(f);                 % approximative value
f2  = exp(x);                 % exact value
err = 100*abs(1 - f1/f2);        % absolute error (in [%])
end