# Convergence issue of a Taylor series expansion of an exponential function in MATLAB

I am writing the following Taylor series expansion for the exponential function: where $\xi, r$, and $\alpha$ are real positive numbers and $k$ is either +1 or -1.

I used the matlab codes to verify that my expansion is correct. The series converges generally for values of "r" around 1. For $k=-1$ and $r<1$, the series does not converge for values values of z greater than 1 . The series also diverges for $z<1$ when $k=1$ and $r>1$.

MATLAB codes:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc; clear all; close all; tic;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

N      = 200;       SS     = 1e-1;      z = 0:SS:5;
alpha  = 2;         xi     = 5;         r = 3.3;           sign = 1;

expr1 = exp(-(xi.*r^(sign).*z.^(-sign/alpha)));
expr2 = zeros(1,length(expr1));

for i=1:1:length(z)

for L=0:1:N

[i L]

cnst = ((-xi.*r^(sign)).^L)./factorial(L);

SUM  = z(i).^(-sign*L./alpha);

expr2(i) = expr2(i)+cnst.*SUM;

end

end

loglog(z,expr1,z,expr2,'ro');

toc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Is this convergence issue is related to the numerical computation in matlab, or are there any convergence conditions that I am missing?

Many thanks

Looking at the case where $z=0.5$, the values of your variable expr2 go up to values of ~$10^8$, where the floating point precision is about ~$10^{-8}$. The overall sum you are trying to get is on the order of ~$10^{-11}$, so you definitely do not have the required numerical precision as you lost all the digits past $10^{-8}$ during summation.