Ask Your Question

More digits from octave

asked 2016-07-22 05:37:53 -0500

Marco Caliari gravatar image

Hi, how can I get all the 15/16 digits from a command like pi = octave('pi')?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2016-07-29 07:04:51 -0500

Marco Caliari gravatar image

Hi, I found myself a solution, for instance:

a=Matrix(RR,octave('sprintf("%.16e ",rand(1,4))'))
edit flag offensive delete link more

answered 2016-07-22 13:12:46 -0500

nbruin gravatar image

As far as I know, the "octave" command really just gets you an interface that allows you to pass strings as "typed in to octave" and get you back strings as printed by octave. So:

  octave:1> 0.123456789
  ans =  0.12346

suggests octave is naturally stingy with printing digits. In order to get more digits back via the octave interface, you should do whatever you do to normally coerce octave to print more digits. Perhaps helps.

edit flag offensive delete link more

answered 2016-07-22 06:45:42 -0500

Starting Octave just to get a numerical value of pi is unnecessarily slow.

If you need a floating-point approximation to pi, I would suggest:

sage: pi = RDF.pi()
sage: pi

But maybe you have other reasons to use Octave?

edit flag offensive delete link more


Sorry, try this instead a=octave('0.123456789'). I chose pi just to be short. I get a=0.123457, lost two digits.

Marco Caliari gravatar imageMarco Caliari ( 2016-07-22 07:56:39 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2016-07-22 05:37:53 -0500

Seen: 112 times

Last updated: Jul 29 '16