0

In Octave

octave.exe:4> asin(1/2)
ans =  0.52360

is it possible to get the result in form of:

ans = pi/6

It seems not possible with format function, but may be there are any tricks.

3 Answers3

2

An alternative might be to convert into units of $\pi$ explicitly, and then seek a rational approximation:

> rats(asin(1/2) / pi)                                                                                                                                    
ans =       1/6
A. Donda
  • 1,466
1

I assume it's the same as with Matlab, where you would do sym(asin(1/2)).

Cocopuffs
  • 10,445
  • 1
    This relies on the symbolic toolbox in matlab, so probably you will need a package like described here: http://math.stackexchange.com/questions/128812/is-there-a-symbolic-math-package-for-octave – Dennis Jaheruddin Nov 21 '12 at 12:31
0

Try using "format rat". "rat" stands for rational, which puts answers in fractional terms. Using "format rat" puts ALL terms in fractional terms (unless you switch back to a different format such as "format g"), as opposed to rats([expression]), which (I assume - I've never used that) only puts [expression] in rational terms.