0
$\begingroup$

I am writing the following Taylor series expansion for the exponential function:

enter image description here

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

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ So do you think this has nothing to do with the Taylor series but it is related to the numerical precision in matlab? Can you suggest a way to resolve this issue? $\endgroup$ – kazekage Sep 17 '16 at 14:55
  • $\begingroup$ I do not see anything wrong with your Taylor series and plotting max(expr2(i)) * eps is pretty convincing that the numerical error is your problem. You can try going to higher numerical precision (more than 64bit wide floating point numbers) but that won't help you much as calculating the exponential directly will be faster. $\endgroup$ – MGirard Sep 19 '16 at 23:11
  • $\begingroup$ I am actually trying to use this Taylor series as part of another expression (for further manipulations). I tried to increase the precision using matlab vpa "mathworks.com/help/symbolic/…" but it seems that even this did not help. $\endgroup$ – kazekage Sep 20 '16 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.