Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
To display big number in all digits form.

Subject: To display big number in all digits form.

From: ZikO

Date: 19 Mar, 2009 01:46:02

Message: 1 of 15

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.

Subject: To display big number in all digits form.

From: Steven Lord

Date: 19 Mar, 2009 02:32:12

Message: 2 of 15


"ZikO" <zebik@op.pl> wrote in message news:gps84r$1e2$1@news.onet.pl...
> 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.

No, when numbers become that large, the spacing between adjacent numbers is
greater than 1, and so the same double-precision number will represent
multiple "numbers with all digits". Try:

x = 1.3e308;
thesame = false(1, 1000);
for k = 1:1000
    z = x+k;
    thesame(k) = isequal(x, z); % should return true
end
all(thesame)

This article talks about eps and the spacing between numbers, albeit dealing
with small numbers.

http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf

--
Steve Lord
slord@mathworks.com

Subject: To display big number in all digits form.

From: Darren Rowland

Date: 19 Mar, 2009 02:38:01

Message: 3 of 15

ZikO <zebik@op.pl> wrote in message <gps84r$1e2$1@news.onet.pl>...
> 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.

To display large integers use either:
the symbolic toolbox
or
download the John D'Erico 'variable precision integer' files from the file exchange
http://blogs.mathworks.com/pick/2009/03/13/variable-precision-arithmetic-without-the-symbolic-toolbox/

Darren

Subject: To display big number in all digits form.

From: ZikO

Date: 19 Mar, 2009 03:17:11

Message: 4 of 15

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.
Thank you =)) I found the way to do so in Symbolic Math Toolbox. thanks
  for suggestions =)

Subject: To display big number in all digits form.

From: ZikO

Date: 19 Mar, 2009 14:02:47

Message: 5 of 15

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

Subject: To display big number in all digits form.

From: Steve Amphlett

Date: 19 Mar, 2009 14:19:02

Message: 6 of 15

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

Subject: To display big number in all digits form.

From: ZikO

Date: 19 Mar, 2009 14:24:13

Message: 7 of 15

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

I don't understand it.

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

is this still MATLAB code?

> fib(1476);
>
> 13069892237633993180363115538027198309839244390741264072600665946019279\
> 307047923174028868108777701772109546315497901227623432224693693964718536670636\
> 848936266084414744994134846280092275581896963474334898291642495406274413596986\
> 561540727649241065372177459066954480149083764916173209597265806463003379334717\
> 1632

and how did u obtain that?

Subject: To display big number in all digits form.

From: John D'Errico

Date: 19 Mar, 2009 14:38:01

Message: 8 of 15

ZikO <zebik@op.pl> wrote in message <gptkie$kcq$1@news.onet.pl>...
> > Can't you do something recursive like you can with Miaxima? This is one of their examples...
>
> I don't understand it.
>
> > fib[0]:0;
> > fib[1]:1;
> > fib[n]:=fib[n-1]+fib[n-2];
>
> is this still MATLAB code?
>
> > fib(1476);
> >
> > 13069892237633993180363115538027198309839244390741264072600665946019279\
> > 307047923174028868108777701772109546315497901227623432224693693964718536670636\
> > 848936266084414744994134846280092275581896963474334898291642495406274413596986\
> > 561540727649241065372177459066954480149083764916173209597265806463003379334717\
> > 1632
>
> and how did u obtain that?

Just do it in matlab.

http://www.mathworks.com/matlabcentral/fileexchange/22725

fib = vpi(zeros(1,1476));
fib(1) = 1;
fib(2) = 1;

for i = 3:1476
   fib(i) = fib(i-1) + fib(i-2);
end

fib(end)
ans =
130698922376339931803631155380271983098392443907
412640726006659460192793070479231740288681087777
017721095463154979012276234322246936939647185366
706368489362660844147449941348462800922755818969
634743348982916424954062744135969865615407276492
410653721774590669544801490837649161732095972658
064630033793347171632

John

Subject: To display big number in all digits form.

From: Steve Amphlett

Date: 19 Mar, 2009 15:29:01

Message: 9 of 15

ZikO <zebik@op.pl> wrote in message <gptkie$kcq$1@news.onet.pl>...
> > Can't you do something recursive like you can with Miaxima? This is one of their examples...
>
> I don't understand it.
>
> > fib[0]:0;
> > fib[1]:1;
> > fib[n]:=fib[n-1]+fib[n-2];
>
> is this still MATLAB code?
>
> > fib(1476);

<snip>
 
> and how did u obtain that?

Someone mentioned the symbolic toolbox, so I thought I'd have a fiddle with Maxima (a free equivalent and fun to play with). The 4 lines above are all it takes.

John's FEX posting is awsome though if you just want to use big numbers.

Subject: To display big number in all digits form.

From: Steven Lord

Date: 19 Mar, 2009 17:37:23

Message: 10 of 15


"ZikO" <zebik@op.pl> wrote in message news: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));

This is not correct, unless internally your fib function performs its
calculations symbolically. If it doesn't, this will compute fib(1476) in
double precision and then take that double precision result and convert it
into a symbolic variable. That's _not_ the same as computing fib(1476)
using symbolic calculations.

--
Steve Lord
slord@mathworks.com

Subject: To display big number in all digits form.

From: Derek O'Connor

Date: 19 Mar, 2009 19:40:18

Message: 11 of 15

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gptlc9$ra8
>
> http://www.mathworks.com/matlabcentral/fileexchange/22725
>
> fib = vpi(zeros(1,1476));
> fib(1) = 1;
> fib(2) = 1;
>
> for i = 3:1476
> fib(i) = fib(i-1) + fib(i-2);
> end
>
> fib(end)
> ans =
> 130698922376339931803631155380271983098392443907
> 412640726006659460192793070479231740288681087777
> 017721095463154979012276234322246936939647185366
> 706368489362660844147449941348462800922755818969
> 634743348982916424954062744135969865615407276492
> 410653721774590669544801490837649161732095972658
> 064630033793347171632
>
> John

John,

Your VP toolbox is a great addition to Matlab.

As a check I used GP/Pari which gave me the same result. The factorization took about 10 mins on a 2x4 Xeon 5345 at 2.33GHz.


                                 GP/PARI CALCULATOR Version 2.3.4 (released)
                          i686 running cygwin (ix86/GMP-4.2.1 kernel) 32-bit version
                compiled: Jul 12 2008, gcc-3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
                               (readline v5.2 enabled, extended help available)

                                    Copyright (C) 2000-2006 The PARI Group


>>fibonacci(1476)
%1 =
130698922376339931803631155380271983098392443907
412640726006659460192793070479231740288681087777
017721095463154979012276234322246936939647185366
706368489362660844147449941348462800922755818969
634743348982916424954062744135969865615407276492
410653721774590669544801490837649161732095972658
064630033793347171632
>>factor(%1)
%2 =
[2 4]

[3 3]

[17 1]

[19 1]

[107 1]

[163 1]

[739 1]

[2789 1]

[8117 1]

[59369 1]

[199261 1]

[800483 1]

[3291481 1]

[4767481 1]

[32417387 1]

[350207569 1]

[370248451 1]

[7188487771 1]

[26024651929 1]

[67031206681 1]

[84738793193 1]

[9382599520669 1]

[18736753266019 1]

[55555922972483 1]

[68541957733949701 1]

[117838518633351469 1]

[46724505421882309671121 1]

[376254926106165750813409 1]

[3487500233390486612275910188300422239895080976898933124460035512511514601 1]

>>

Would anybody like to check the factorization?

Regards,

Derek O'Connor

Subject: To display big number in all digits form.

From: Derek O'Connor

Date: 19 Mar, 2009 19:41:01

Message: 12 of 15

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gptlc9$ra8
>
> http://www.mathworks.com/matlabcentral/fileexchange/22725
>
> fib = vpi(zeros(1,1476));
> fib(1) = 1;
> fib(2) = 1;
>
> for i = 3:1476
> fib(i) = fib(i-1) + fib(i-2);
> end
>
> fib(end)
> ans =
> 130698922376339931803631155380271983098392443907
> 412640726006659460192793070479231740288681087777
> 017721095463154979012276234322246936939647185366
> 706368489362660844147449941348462800922755818969
> 634743348982916424954062744135969865615407276492
> 410653721774590669544801490837649161732095972658
> 064630033793347171632
>
> John

John,

Your VP toolbox is a great addition to Matlab.

As a check I used GP/Pari which gave me the same result. The factorization took about 10 mins on a 2x4 Xeon 5345 at 2.33GHz.


                                 GP/PARI CALCULATOR Version 2.3.4 (released)
                          i686 running cygwin (ix86/GMP-4.2.1 kernel) 32-bit version
                compiled: Jul 12 2008, gcc-3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
                               (readline v5.2 enabled, extended help available)

                                    Copyright (C) 2000-2006 The PARI Group


>>fibonacci(1476)
%1 =
130698922376339931803631155380271983098392443907
412640726006659460192793070479231740288681087777
017721095463154979012276234322246936939647185366
706368489362660844147449941348462800922755818969
634743348982916424954062744135969865615407276492
410653721774590669544801490837649161732095972658
064630033793347171632
>>factor(%1)
%2 =
[2 4]

[3 3]

[17 1]

[19 1]

[107 1]

[163 1]

[739 1]

[2789 1]

[8117 1]

[59369 1]

[199261 1]

[800483 1]

[3291481 1]

[4767481 1]

[32417387 1]

[350207569 1]

[370248451 1]

[7188487771 1]

[26024651929 1]

[67031206681 1]

[84738793193 1]

[9382599520669 1]

[18736753266019 1]

[55555922972483 1]

[68541957733949701 1]

[117838518633351469 1]

[46724505421882309671121 1]

[376254926106165750813409 1]

[3487500233390486612275910188300422239895080976898933124460035512511514601 1]

>>

Would anybody like to check the factorization?

Regards,

Derek O'Connor

Subject: To display big number in all digits form.

From: ZikO

Date: 19 Mar, 2009 22:23:27

Message: 13 of 15

> Just do it in matlab.
>
> http://www.mathworks.com/matlabcentral/fileexchange/22725
>
> fib = vpi(zeros(1,1476));
> fib(1) = 1;
> fib(2) = 1;
>
> for i = 3:1476
> fib(i) = fib(i-1) + fib(i-2);
> end
>
> fib(end)
> ans =
> 130698922376339931803631155380271983098392443907
> 412640726006659460192793070479231740288681087777
> 017721095463154979012276234322246936939647185366
> 706368489362660844147449941348462800922755818969
> 634743348982916424954062744135969865615407276492
> 410653721774590669544801490837649161732095972658
> 064630033793347171632
>
> John

Thank you for this toolbox =)

Best

Subject: To display big number in all digits form.

From: ZikO

Date: 19 Mar, 2009 22:40:27

Message: 14 of 15

>> A = sym(fib(1476));
>
> This is not correct, unless internally your fib function performs its
> calculations symbolically. If it doesn't, this will compute fib(1476) in
> double precision and then take that double precision result and convert it
> into a symbolic variable. That's _not_ the same as computing fib(1476)
> using symbolic calculations.
>

Thanks Steve.

Would you like to show me how to do that correctly?

Regards

Subject: To display big number in all digits form.

From: Steven Lord

Date: 23 Mar, 2009 14:25:01

Message: 15 of 15


"ZikO" <zebik@op.pl> wrote in message news:gpuhks$27v$1@news.onet.pl...
>>> A = sym(fib(1476));
>>
>> This is not correct, unless internally your fib function performs its
>> calculations symbolically. If it doesn't, this will compute fib(1476) in
>> double precision and then take that double precision result and convert
>> it into a symbolic variable. That's _not_ the same as computing
>> fib(1476) using symbolic calculations.
>>
>
> Thanks Steve.
>
> Would you like to show me how to do that correctly?


function y = fib(n)
% Error checking required, not included
% Note that this is just one way to implement Fibonacci symbolically
% I can think of at least three additional methods off the top of my head.
% These other implementations left as an exercise for the reader.
xm1 = sym(1);
xm2 = sym(1);
if n < 3
    y = xm1;
else
    for k = 3:n
        y = xm1+xm2;
        xm2 = xm1;
        xm1 = y;
    end
end


Note that because all the addition operations are performed on sym objects,
the result is symbolic. In this case, n must be numeric (since < isn't
defined for sym objects, for reasons that have been discussed on CSSM in the
past) but the result is symbolic.

--
Steve Lord
slord@mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us