% Computes e using the Taylor's series for e^x % Inputs: N - the number of terms + 1 that is summed in the series. % Outputs: e - an approximation of e function e = compute_e(n) % Initialize the variable used for the partial sums. e = 0; % This is the slow way to implement the sum in MATLAB. for j = 0:n % Note that MATLAB has no built in function for factorial, so we use the % result that gamma(n+1) = n!. e = e + 1/gamma(j+1); end % The fast way to implement the sum is as follows (note: just uncomment out % the following two lines. % k = 0:n; % e = sum(1./(gamma(k+1)));