format long not working as expected

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

format long not working as expected

Jeff Sadowski
I'm using octave 4.0.0 on ubuntu 16.04
when I do

>> format long
>> h=10.^(-15:-1)
h =

 Columns 1 through 6:

   1.00000000000000e-15   1.00000000000000e-14   1.00000000000000e-13   1.00000000000000e-12   1.00000000000000e-11   1.00000000000000e-10

 Columns 7 through 12:

   1.00000000000000e-09   1.00000000000000e-08   1.00000000000000e-07   1.00000000000000e-06   1.00000000000000e-05   1.00000000000000e-04

 Columns 13 through 15:

   1.00000000000000e-03   1.00000000000000e-02   1.00000000000000e-01

>> arrayfun(@(x) ((exp(x)-1)/x)-1,h)
ans =

 Columns 1 through 6:

   1.10223024625156e-01  -7.99277837359891e-04  -7.99277837359780e-04   8.89005823403455e-05   8.27403703329566e-08   8.27403705550012e-08

 Columns 7 through 12:

   8.27403705550012e-08  -6.07747152603366e-09   4.94336798162465e-08   4.99962183209135e-07   5.00000696446179e-06   5.00016671407533e-05

 Columns 13 through 15:

   5.00166708384375e-04   5.01670841679469e-03   5.17091807564771e-02

>>

The expected is like matlabs

>> format long
>>  h=10.^(-15:-1)

h =

  Columns 1 through 4

   0.000000000000001   0.000000000000010   0.000000000000100   0.000000000001000

  Columns 5 through 8

   0.000000000010000   0.000000000100000   0.000000001000000   0.000000010000000

  Columns 9 through 12

   0.000000100000000   0.000001000000000   0.000010000000000   0.000100000000000

  Columns 13 through 15

   0.001000000000000   0.010000000000000   0.100000000000000

>> arrayfun(@(x) ((exp(x)-1)/x)-1,h)

ans =

  Columns 1 through 4

   0.110223024625157  -0.000799277837359  -0.000799277837359   0.000088900582341

  Columns 5 through 8

   0.000000082740371   0.000000082740371   0.000000082740371  -0.000000006077471

  Columns 9 through 12

   0.000000049433680   0.000000499962184   0.000005000006965   0.000050001667141

  Columns 13 through 15

   0.000500166708385   0.005016708416795   0.051709180756477

>> 

reading the help in octave
     'long'
          Fixed point format with 15 significant figures in a field that
          is a maximum of 20 characters wide.

          As with the 'short' format, Octave will switch to an
          exponential 'e' format if it is unable to format a matrix
          properly using the current format.




_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: format long not working as expected

siko1056
Jeff Sadowski wrote

> I'm using octave 4.0.0 on ubuntu 16.04
> when I do
>
>>> format long
>>> h=10.^(-15:-1)
> h =
>
>  Columns 1 through 6:
>
>    1.00000000000000e-15   1.00000000000000e-14   1.00000000000000e-13
>  1.00000000000000e-12   1.00000000000000e-11   1.00000000000000e-10
>
> [...]
>
> The expected is like matlabs
>
>>> format long
>>>  h=10.^(-15:-1)
>
> h =
>
>   Columns 1 through 4
>
>    0.000000000000001   0.000000000000010   0.000000000000100
>  0.000000000001000
>
> [...]

Maybe you give `fixed_point_format` [1] a try:

>> format long
>> fixed_point_format (true)
>> h=10.^(-15:-1)

HTH,
Kai

[1]:
https://www.gnu.org/software/octave/doc/v4.0.0/XREFfixed_005fpoint_005fformat



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: format long not working as expected

Jeff Sadowski
Thank you

On Wed, Oct 4, 2017 at 3:02 PM, siko1056 <[hidden email]> wrote:
Jeff Sadowski wrote
> I'm using octave 4.0.0 on ubuntu 16.04
> when I do
>
>>> format long
>>> h=10.^(-15:-1)
> h =
>
>  Columns 1 through 6:
>
>    1.00000000000000e-15   1.00000000000000e-14   1.00000000000000e-13
>  1.00000000000000e-12   1.00000000000000e-11   1.00000000000000e-10
>
> [...]
>
> The expected is like matlabs
>
>>> format long
>>>  h=10.^(-15:-1)
>
> h =
>
>   Columns 1 through 4
>
>    0.000000000000001   0.000000000000010   0.000000000000100
>  0.000000000001000
>
> [...]

Maybe you give `fixed_point_format` [1] a try:

>> format long
>> fixed_point_format (true)
>> h=10.^(-15:-1)

HTH,
Kai

[1]:
https://www.gnu.org/software/octave/doc/v4.0.0/XREFfixed_005fpoint_005fformat



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave