Path: news.mathworks.com!not-for-mail
From: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: To display big number in all digits form.
Date: Thu, 19 Mar 2009 14:19:02 +0000 (UTC)
Organization: Ricardo UK Ltd
Lines: 77
Message-ID: <gptk8m$8jd$1@fred.mathworks.com>
References: <gps84r$1e2$1@news.onet.pl> <gptja9$hml$1@news.onet.pl>
Reply-To: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1237472342 8813 172.30.248.35 (19 Mar 2009 14:19:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 19 Mar 2009 14:19:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 43398
Xref: news.mathworks.com comp.soft-sys.matlab:526135


ZikO <zebik@op.pl> wrote in message <gptja9$hml$1@news.onet.pl>...
> ZikO wrote:
> > Hi
> > 
> > I am afraid I have very unusual problem. I need to show a very very big 
> > number, a Fibonacci(n) series when when n = 1476. It is number of 
> > 1.3e308 range. I would like to see this number with all digits. Is it 
> > somehow possible in MATLAB.
> > 
> > Thanks you.
> 
> I am not sure if I did it correctly. There is a code which calculates 
> Fibonacci series. I used Symbolic Math Toolbox. When i run these 
> commands below:
> 
> A = sym(fib(1476));
> vpa(A,1000);
> 
> I got the number:
> 130698922376339873754511593703999304853661815941920982715896371280424691495866567130509827216117625177952738381240755518030797439683443697785696230802473309617042775347304891963181519627287463521203531259388682404883801028462229399345567884825464934136563115441584430300333788777345438315116223032518554681344
> 
> On one of the other groups someone has provided different result:
> 130698922376339931803631155380271983098392443907412640726006659460192793070479231740288681087777017721095463154979012276234322246936939647185366706368489362660844147449941348462800922755818969634743348982916424954062744135969865615407276492410653721774590669544801490837649161732095972658064630033793347171632
> 
> which one is correct and how to check it?
> 
> Thanks
> 
> 
> % code
> function out = fib(n)
> 
> N = length(n);
> if N == 1
>      tab = [1;1;2];
>      if n<3
>          out = 1;
>      else
>          n = n - 3;
>          for indx = 0:n
>              tab(1) = tab(2);
>              tab(2) = tab(3);
>              tab(3) = tab(1) + tab(2);
>          end
>          out = tab(2);
>      end
> else
>      out = zeros(N,1);
>      for indx_i = 1:N
>          tab = [1;1;2];
>          if n(indx_i)<3
>              out(indx_i) = 1;
>          else
>              for indx_j = 0:(n(indx_i)-3)
>                  tab(1) = tab(2);
>                  tab(2) = tab(3);
>                  tab(3) = tab(1) + tab(2);
>              end
>              out(indx_i) = tab(3);
>          end
>      end
> end
> % end of code

Can't you do something recursive like you can with Miaxima?  This is one of their examples...

fib[0]:0;
fib[1]:1;
fib[n]:=fib[n-1]+fib[n-2];

fib(1476);

13069892237633993180363115538027198309839244390741264072600665946019279\
307047923174028868108777701772109546315497901227623432224693693964718536670636\
848936266084414744994134846280092275581896963474334898291642495406274413596986\
561540727649241065372177459066954480149083764916173209597265806463003379334717\
1632