Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How do I increase the precision of MATLAB?
Date: Sun, 11 Jan 2009 00:43:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 33
Message-ID: <gkbfam$s9r$1@fred.mathworks.com>
References: <gkb7mu$4r$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1231634582 28987 172.30.248.38 (11 Jan 2009 00:43:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 11 Jan 2009 00:43:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:510807

"Thiago " <thiago@mathworks.com> wrote in message <gkb7mu$4r$1@fred.mathworks.com>...
> ......
> z =  2.225167162095353e+003 -9.020383145678592e+002i
> >> exp( i*z )
> ans =   Inf +              Infi
> .......

  What you have asked for is impossible with the IEEE 754 binary double precision floating point (double) numbers that matlab uses.  However, it is possible to represent the value of 'exp' for large arguments in terms of an integer power of ten and mantissa separately.  For this purpose I will just use a real example.

  Suppose we want to find exp(7.0873e002).  This will be a large number indeed but still just barely within matlab's capability of direct calculation.  However, we can find the separate exponent and mantissa without calling on 'exp' as follows;

 a = 7.0873e2;
 x = a/log(10);
 D = floor(x); % D will be an integer
 F = 10^(x-D); % F will lie in 1 <= F < 10

Then D will be the power of ten and F the mantissa

 F = 6.27376373225551  % The mantissa
 D = 307               % The exponent (power of ten)

Compare that with the direct answer:

 exp(a) = 6.273763732256170e+307

  The same trick works for larger numbers which can't be evaluated directly.

  Your problem with complex numbers is a little more complicated but the same principle applies.  One difficulty you will have is that the sine and cosine of very large numbers like 2.225167162095353e+003 which you will encounter begins to lose accuracy because that represents over three hundreds periods.  You will lose perhaps six or so decimal digits of accuracy out of sixteen in the process.

  Another possibility for you is using the Symbolic Toolbox for which you can set whatever accuracy you desire, though at the cost of computational speed.

Roger Stafford