function [f g] = emx(x,n) f = 1; % the first approximation 1 - x + x^2/2 - x^3/6 + ... p = 1; % the first approximation for the denominator (1 + x + x^2/2 + x^3/6 + ...) for i=1:n s = x^i/factorial(i); f = f +(-1)^i*s; p = p + s; g = 1 / p; end end