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.
"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.
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.
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.
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.
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...
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?
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.
"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.
>> 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.
"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.
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.