
function demo_exp

x=10*pi;

m1=x+1;
m2=x+5;
m3=x^2+1;

sol=exp(x);

format long e
sol

nv=5:5:100;

fprintf('\n \t %5.0f %5.0f %5.0f',m1,m2,m3)

for ii=1:length(nv)
    n=nv(ii);
    
    r1=local_sum(x,n);
    r2=(local_sum(x/m1,n))^m1;
    r3=(local_sum(x/m2,n))^m2;
    r4=(local_sum(x/m3,n))^m3;
    
    e1=abs(r1-sol)/sol;
    e2=abs(r2-sol)/sol;
    e3=abs(r3-sol)/sol;
    e4=abs(r4-sol)/sol;
    
    fprintf('\n \t $%3.0f$ & $%1.1e$ & $%1.1e$ & $%1.1e$ & $%1.1e$ \\\\',...
        n,e1,e2,e3,e4);
    
end

fprintf('\n \n');


function fx=local_sum(x,n)

% v=0:n;
% nx=x.^v;
% dx=factorial(v);
% fx=sum(nx./dx);
fx=1;
for k=1:n
    nums=x*ones(1,k);
    dens=1:k;
    loc=prod(nums./dens);
    fx=fx+loc;
end
