function s=expseries(x,n); % EXPSERIES: function calculates the sum % 1+x+(x^2)/2!+(x^3)/3!+...+(x^n)/n! (up to nth power). % Call syntax: % s=expseries(x,n); % where x is real and n nonnegative integer. k = 0:n; % create a vector from 0 to n series = (x.^k)./factorial(k); % create a vector of terms in the series s = sum(series); % sum all terms of the vector 'series'.