<TeXmacs|1.0.7.11>

<style|<tuple|tmdoc|maxima>>

<\body>
  <\tmdoc-title>
    Example <name|Octave> session
  </tmdoc-title>

  An <name|Octave> session is started using <menu|Insert|Session|Octave>.
  Below, it is shown how to do linear algebra operations with <name|Octave>,
  such as matrix multiplication, inversion and diagonalization. Notice that
  you need to use the <verbatim|tmdisp> command (at the moment) in order to
  display the output in mathematical form.

  <\session|octave|default>
    <\output>
      GNU Octave, version 2.1.40 (i386-redhat-linux-gnu).

      Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 John W. Eaton.

      This is free software; see the source code for copying conditions.

      There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or

      FITNESS FOR A PARTICULAR PURPOSE.

      \;

      Report bugs to \<less\>bug-octave@bevo.che.wisc.edu\<gtr\>.

      \;
    </output>

    <\unfolded-io|octave\<gtr\> >
      A=[1 0 0 0;2 2 0 0;-1 0 2 0;0 -1 2 2]
    <|unfolded-io>
      A =

      \;

      \ \ \ 1 \ \ 0 \ \ 0 \ \ 0

      \ \ \ 2 \ \ 2 \ \ 0 \ \ 0

      \ \ -1 \ \ 0 \ \ 2 \ \ 0

      \ \ \ 0 \ -1 \ \ 2 \ \ 2

      \;

      \;
    </unfolded-io>

    <\unfolded-io|octave\<gtr\> >
      tmdisp(A^2)
    <|unfolded-io>
      <math|<with|math-display|true|<matrix|<tformat|<table|<row|<cell|1>|<cell|0>|<cell|0>|<cell|0>>|<row|<cell|6>|<cell|4>|<cell|0>|<cell|0>>|<row|<cell|-3>|<cell|0>|<cell|4>|<cell|0>>|<row|<cell|-4>|<cell|-4>|<cell|8>|<cell|4>>>>>>>

      \;
    </unfolded-io>

    <\unfolded-io|octave\<gtr\> >
      tmdisp(A.^2)
    <|unfolded-io>
      <math|<with|math-display|true|<matrix|<tformat|<table|<row|<cell|1>|<cell|0>|<cell|0>|<cell|0>>|<row|<cell|4>|<cell|4>|<cell|0>|<cell|0>>|<row|<cell|1>|<cell|0>|<cell|4>|<cell|0>>|<row|<cell|0>|<cell|1>|<cell|4>|<cell|4>>>>>>>

      \;
    </unfolded-io>

    <\unfolded-io|octave\<gtr\> >
      [u,v]=eig(A)
    <|unfolded-io>
      u =

      \;

      \ \ \ 0.00000 \ \ 0.00000 \ \ 0.00000 \ \ 0.21320

      \ \ \ 0.00000 \ \ 0.00000 \ \ 0.00000 \ -0.42640

      \ \ \ 0.00000 \ \ 0.00000 \ \ 0.00000 \ \ 0.21320

      \ \ \ 1.00000 \ \ 1.00000 \ -1.00000 \ -0.85280

      \;

      v =

      \;

      \ \ 2 \ 0 \ 0 \ 0

      \ \ 0 \ 2 \ 0 \ 0

      \ \ 0 \ 0 \ 2 \ 0

      \ \ 0 \ 0 \ 0 \ 1

      \;

      \;
    </unfolded-io>

    <\unfolded-io|octave\<gtr\> >
      Q=[1 0 0 0;-2 2 1 0;1 1 0 0;-4 0 0 -1]
    <|unfolded-io>
      Q =

      \;

      \ \ \ 1 \ \ 0 \ \ 0 \ \ 0

      \ \ -2 \ \ 2 \ \ 1 \ \ 0

      \ \ \ 1 \ \ 1 \ \ 0 \ \ 0

      \ \ -4 \ \ 0 \ \ 0 \ -1

      \;

      \;
    </unfolded-io>

    <\unfolded-io|octave\<gtr\> >
      P=inv(Q)
    <|unfolded-io>
      P =

      \;

      \ \ \ 1 \ -0 \ \ 0 \ \ 0

      \ \ -1 \ \ 0 \ \ 1 \ \ 0

      \ \ \ 4 \ \ 1 \ -2 \ \ 0

      \ \ -4 \ \ 0 \ \ 0 \ -1

      \;

      \;
    </unfolded-io>

    <\unfolded-io|octave\<gtr\> >
      P*A*Q
    <|unfolded-io>
      ans =

      \;

      \ \ 1 \ 0 \ 0 \ 0

      \ \ 0 \ 2 \ 0 \ 0

      \ \ 0 \ 0 \ 2 \ 0

      \ \ 0 \ 0 \ 1 \ 2

      \;

      \;
    </unfolded-io>

    <\input|octave\<gtr\> >
      \;
    </input>
  </session>

  The second part shows the graph capacity of Octave, 2D and 3D graphs. 2D
  graphs can be automatically embedded into the worksheet but 3D graphs are
  not yet.

  <\session|octave|default>
    <\input|octave\<gtr\> >
      x=linspace(-10,10,1000);
    </input>

    <\input|octave\<gtr\> >
      y=x+sin(x);
    </input>

    <\unfolded-io|octave\<gtr\> >
      plot(x,y,";Function y=x+sin(x);");
    <|unfolded-io>
      \;

      \;

      <image|<tuple|<#[encoded data, 38174 characters]>|ps>||||>

      \;
    </unfolded-io>

    <\input|octave\<gtr\> >
      x0=[2;5;10];
    </input>

    <\input|octave\<gtr\> >
      t = linspace (0,10,800);
    </input>

    <\input|octave\<gtr\> >
      function dx = butter (x ,t) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dx(1)
      = -10.0*(x(1)-x(2)); \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dx(2)
      = 28.0*x(1)-x(2)-x(1)*x(3); \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dx(3)
      = 8.0/3.0*( x(1)*x(2) -x(3) ); \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ end;
    </input>

    <\input|octave\<gtr\> >
      y=lsode("butter",x0,t);
    </input>

    <\input|octave\<gtr\> >
      gset parametric;
    </input>

    <\input|octave\<gtr\> >
      gset set term postscript enhanced color eps;
    </input>

    <\input|octave\<gtr\> >
      gset xtics 10;gset ytics 10; gset ztics 10;
    </input>

    <\input|octave\<gtr\> >
      gset out "/tmp/butterfly.eps";
    </input>

    <\input|octave\<gtr\> >
      gsplot y title "Butterfly Effect"
    </input>

    <\input|octave\<gtr\> >
      \;
    </input>
  </session>

  In order to embed the 3D graph, we first save it as butterfly.eps in /tmp
  directory. Then we can embed this EPS file into the worksheet using
  <menu|Insert|Image>.

  <big-figure|<image|<tuple|<#[encoded data, 39416 characters]>|eps>||||>|Embedded
  3D graph from Octave.>

  <tmdoc-copyright|2003|Chu-Ching Huang|Joris van der Hoeven>

  <tmdoc-license|Permission is granted to copy, distribute and/or modify this
  document under the terms of the GNU Free Documentation License, Version 1.1
  or any later version published by the Free Software Foundation; with no
  Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  Texts. A copy of the license is included in the section entitled "GNU Free
  Documentation License".>
</body>

<\initial>
  <\collection>
    <associate|language|english>
  </collection>
</initial>