4.11.1 Computation of Special Functions

Octave implements computation of the following special functions (see the maxima and gp interfaces for even more special functions):

airy 
    Airy functions of the first and second kind, and their derivatives.
    airy(0,x) = Ai(x), airy(1,x) = Ai'(x), airy(2,x) = Bi(x), airy(3,x) = Bi'(x)
besselj
    Bessel functions of the first kind.
bessely
    Bessel functions of the second kind.
besseli
    Modified Bessel functions of the first kind.
besselk
    Modified Bessel functions of the second kind.
besselh
    Compute Hankel functions of the first (k = 1) or second (k = 2) kind.
beta 
    The Beta function,
          beta (a, b) = gamma (a) * gamma (b) / gamma (a + b).
betainc 
    The incomplete Beta function,
erf 
    The error function,
erfinv 
    The inverse of the error function. 
gamma 
    The Gamma function,
gammainc 
    The incomplete gamma function,

For example,

sage: octave("airy(3,2)")
4.10068
sage: octave("beta(2,2)")
0.166667
sage: octave("betainc(0.2,2,2)")
0.104
sage: octave("besselh(0,2)")
(0.223891,0.510376)
sage: octave("besselh(0,1)")
(0.765198,0.088257)
sage: octave("besseli(1,2)")
1.59064
sage: octave("besselj(1,2)")
0.576725
sage: octave("besselk(1,2)")
0.139866
sage: octave("erf(0)")
0
sage: octave("erf(1)")
0.842701
sage: octave("erfinv(0.842)")
0.998315
sage: octave("gamma(1.5)")
0.886227
sage: octave("gammainc(1.5,1)")
0.77687

The Octave interface reads in even very long input (using files) in a robust manner:

sage: t = '"%s"'%10^10000   # ten thousand character string.
sage: a = octave.eval(t)      # < 1/100th of a second
sage: a = octave(t)

Module-level Functions

octave_console( )

This requires that the optional octave program be installed and in your PATH, but no optional SAGE packages need be installed.

sage: octave_console()
GNU Octave, version 2.1.71 (x86_64-suse-linux).
Copyright (C) 2005 John W. Eaton.
...
Additional information about Octave is available at http://www.octave.org.

octave:1> 2+3 ans = 5 octave:2> [ctl-d]

ctl-d exits the octave console and returns you to SAGE. octave, like SAGE, remembers its history from one session to another.

octave_version( )

Return the version of Octave installed.

sage: octave_version()    # optional octave package; random-ish output
'2.1.72'

reduce_load_Octave( )

Class: Octave

class Octave
Interface to the Octave interpreter.

sage: octave.eval("a = [ 1, 1, 2; 3, 5, 8; 13, 21, 33 ]")    # optional
'a =

1 1 2 3 5 8 13 21 33

'

sage: octave.eval("b = [ 1; 3; 13]")                         # optional
'b =

1 3 13

'

sage: octave.eval("c=a \ b") # solves linear equation: a*c = b  # optional
'c =

1 7.21645e-16 -7.21645e-16

'

sage: print octave.eval("c")                                 # optional
c =

 1
 7.21645e-16
 -7.21645e-16
Octave( self, [maxread=None], [script_subdirectory=None], [logfile=], [server=100])

Functions: console,$  $ de_system_plot,$  $ get,$  $ get_via_file,$  $ quit,$  $ sage2octave_matrix_string,$  $ set,$  $ set_via_file,$  $ solve_linear_system,$  $ version

de_system_plot( self, f, ics, trange)

Plots (using octave's interface to gnuplot) the solution to a $ 2\times 2$ system of differential equations.

INPUT:
    f -- a pair of strings representing the differential equations;
         The independent variable must be called x and the dependent
         variable must be called y.
    ics -- a pair [x0,y0] such that x(t0) = x0, y(t0) = y0
    trange -- a pair [t0,t1]

OUTPUT:
    a gnuplot window appears

sage: octave.de_system_plot(['x+y','x-y'], [1,-1], [0,2])

This yields the two plots $ (t,x(t)), (t,y(t))$ on the same graph (the $ t$ -axis is the horizonal axis) of the system of ODEs

$\displaystyle x' = x+y, x(0) = 1;\qquad y' = x-y, y(0) = -1,$   for$\displaystyle \quad 0 < t < 2.
$

get( self, var)

Get the value of the variable var.

sage2octave_matrix_string( self, A)

Return an octave matrix from a SAGE matrix.

INPUT:
    A SAGE matrix with entries in the rationals or reals.

OUTPUT:
    A string that evaluates to an Octave matrix.

sage: M33 = MatrixSpace(QQ,3,3)
sage: A = M33([1,2,3,4,5,6,7,8,0])
sage: octave.sage2octave_matrix_string(A)   # requires optional octave
'[1, 2, 3; 4, 5, 6; 7, 8, 0]'

Author: David Joyner and William Stein

set( self, var, value)

Set the variable var to the given value.

solve_linear_system( self, A, b)

Use octave to compute a solution x to A*x = b, as a list.

INPUT:
    A -- mxn matrix A with entries in QQ or RR
    b -- m-vector b entries in QQ or RR (resp)

OUTPUT:
    An list x (if it exists) which solves M*x = b

sage: M33 = MatrixSpace(QQ,3,3)
sage: A   = M33([1,2,3,4,5,6,7,8,0])
sage: V3  = VectorSpace(QQ,3)
sage: b   = V3([1,2,3])
sage: octave.solve_linear_system(A,b)    # requires optional octave
[-0.33333299999999999, 0.66666700000000001, -3.5236600000000002e-18]

Author: David Joyner and William Stein

Special Functions: __reduce__,$  $ _object_class,$  $ _quit_string,$  $ _read_in_file_command,$  $ _start

Class: OctaveElement

class OctaveElement

Special Functions: _matrix_

_matrix_( self, R)

Return SAGE matrix from this octave element.

sage: A = octave('[1,2;3,4]')       # optional octave package
sage: matrix(A, ZZ)
[1 2]
[3 4]
sage: A = octave('[1,2;3,4.5]')     # optional octave package
sage: matrix(A, RR)
[1.0000000000000000 2.0000000000000000]
[3.0000000000000000 4.5000000000000000]

See About this document... for information on suggesting changes.