Newsgroups: comp.sys.hp48

BEGIN_DOC SonicPlotting.doc
@ Version 1.0 @

_Introduction_

The programs contained in this document are the examples I used for a talk at
the Internation Conference on Technology in Collegiate Mathematics. The abstract
is as follows.


   Sonic Plotting: Another "Visualization" Technique

           Charles M. Patton
           Hewlett-Packard Co.
           Corvallis, OR

     presented at the
     Fifth International Conference on
     Technology in College Mathematics
     November 12-15, 1992

   The NCTM standards for the teaching of mathematics now embraces
   the widespread use of the triple, symbolic-, numeric-, and
   graphical-views, of mathematical concepts. Both my experiences
   building physics instrumentation for visually impaired students and
   my own experiments in conceptual aids for understanding complicated
   dynamical systems suggest that the notion of "graphical-view"
   should be expanded to include auditory information. Simple
   implementation techniques, applicable to the HP-48/28 and other
   suitably capable machines, will be presented along with demonstrations
   of the technique.

_NO WARRANTY_
    This work is provided on an "as is" basis. Hewlett-Packard Co.
provides no warranty whatsoever, either express or implied regarding
the work, including warranties with respect to its merchantability or
fitness for any purpose whatsoever.

_Copyright_
   Copyright (C), 1991, Hewlett-Packard Co. Permission to copy all or
part of this work is granted provided that the copies are not made or
distributed for resale (excepting nominal copying fees) and the
 _NO WARRANTY_ and this copyright notice are included verbatim. Other
permissions can be arranged by contacting the author.

_Correspondence_

Please note that while suggestions, additions, corrections, insights,
commentary, and criticisms are welcome, we are not in a position to
offer meaningful support on this material.

Correspondence on SonicPlotting should be sent to Charles Patton at
one of the following addresses:

snail-mail:
          M.S. 5U-P9
          Hewlett-Packard Co.
          1000 N.E. Circle Blvd.
          Corvallis, OR 97330

e-mail:
          charliep@cv.hp.com    (for Internet hosts)
          hplabs!hpcvrs!charliep (for UUCP hosts)

_Organization_

The first five programs in the directory (EX.DRAW EX2.DRAW EX.SONMAP
EX2.SONMAP EX.ROSSLER) are ready-to-run examples (just make sure you
have BEEP enabled or you won't hear anything.)

The main program used here is SONICDRAW which is analogous to the
normal DRAW except it also plots points in auditory space as well as
visual space. The mapping convention at work here is pairing a number
with a frequency. While there are many other useful conventions, this
one is both effective and simple on the '48.

The main work involved is the conversion of a number to a frequency
based on the scaling given by the XRNG and YRNG with the convention
that "off screen" is represented by a constant high (low) frequency if
the point is above/right (below/left) of the viewing window. This
seemed better than having no sound at all in this case.

Because the scaling function is used many times during a plot and doesn't change 
during the plot, I decided to have it pre-computed at the start of the plot and
passed as a parameter to the function which does the actual plotting. The program
which computes the scaling function is called SONICEVAL.

SONICEVAL takes as an argument the main plotting program. It computes
the scaling function based on the current PPAR variable and passes the
scaling function to the main plotting program. The scaling function
takes a numeric argument (real, complex, or vector) produces a sound
based on its argument and returns the argument unchanged.

The main plotting program (the subprogram in SONICDRAW, for example)
can do anything it likes with the scaling function passed to it. Most
simply, the scaling function can be composed with the function stored
in EQ and the result plotted with DRAW. This allows the normal DRAW
operation to produce sounds as a side effect of each function evaluation.
This is exactly what is done in SONICDRAW.

Another example of what can be done with the scaling function is given
in SONMAP.  SONMAP takes a scalar function of one variable (given as
an expression in 'X') and an initial iterate and plots iterates of the
function both visually, using the MAPLINE plotter, and sonically,
using the scaling function produced by SONICEVAL.

The ROSSLER example shows another way SONICEVAL can be used. In this
case, we are approximating an integral curve to the famous Rossler
chaotic dynamical system. We are only visually plotting two of the
three coordinate points at each time step, but we are sonic-plotting
all three. The ability to sonic-plot in three or more dimensions gives
this method a significant advantage over visual plotting since visual
plotting can only deal with two dimensions on an equal footing.

END_DOC

BEGIN_ASC SonicPlot
%%HP: T(3)A(R)F(.);
DIR
 EX.DRAW  @ SonicPlotting X*SIN(X) @
    \<< ERASE 
      -8 8 XRNG 
      -8 8 YRNG 
      RAD FUNCTION 'X' INDEP
      'X*SIN(X)' STEQ
      SONICDRAW
    \>>

 EX2.DRAW  @ SonicPlotting a Circle @
    \<< ERASE 
      -2 2 XRNG 
      -2 2 YRNG 
      RAD PARAMETRIC {T 0 20} INDEP
      'SIN(T)+i*COS(T)' STEQ
      SONICDRAW
    \>>

 EX.SONMAP @ standard logistic map @
    \<< ERASE 
      -1 10 XRNG 
      -1 10 YRNG 
      'X+.49*(X*(6-X))'
      .11577030827
      SONMAP
    \>>

 EX2.SONMAP @ piecewise-linear logistic map @
    \<< ERASE 
      -1 10 XRNG 
      -1 10 YRNG 
      'IFTE(6>X,1.5*X,18-2*X)' 
      .11577030827
      SONMAP
    \>>

 EX.ROSSLER @ Sonic Plot the Rossler Band @
    \<< ERASE 
      -8 8 XRNG 
      -8 8 YRNG
      {# 0h # 0h } PVIEW
      \<< \-> SF     @ capture the scaling function as SF @
        \<< -.362251294685
          1.96138321354
           .556350375156
           .07
          DO 
            4 PICK 4 PICK R\->C SF EVAL
            PIXON
            OVER SF EVAL DROP
            ROSSLERNEXT
          UNTIL KEY
          END DROP
        \>>
      \>> SONICEVAL
    \>>

 SONMAP @ 'expr(X)' startvalue -> @
        @ iterates the mapping, both line-plotting and @
        @ sonic-plotting each value @
    \<< { # 0h # 0h } PVIEW
      \<< \-> G     @ capture the scaling function as G @
        \<<
          DO
             MAPLINE 
             G EVAL  @ that is, sonic plot the result @
          UNTIL KEY
          END 
          DROP
        \>>
      \>> SONICEVAL
    \>>

 SONICEVAL @ \<<\->\<<main prog\>>\>> ->   @
           @ pass the main program the current @
           @ sonic-plotting function derived from @
           @ the PPAR settings (evaluating the result) @
    \<< 'IM(PPAR(1))' EVAL
      'IM(PPAR(2))' EVAL
       DUP2 SWAP - 
      'RE(PPAR(1))' EVAL
      'RE(PPAR(2))' EVAL
       DUP2 SWAP - 
     \-> ylow yhigh ydif xlow xhigh xdif
      \<<
        \<< \-> sonicval
          \<< sonicval \->NUM DUP
            'sonicval' STO
            IF DUP TYPE 0 ==
            THEN 'INV(MAX(.0002+.0038*(yhigh-sonicval)/ydif,.0001))' \->NUM
                 .15 BEEP
            ELSE 'INV(MAX(.0002+.0038*(xhigh-RE(sonicval))/xdif,.0001))+INV(MAX(.0002+.0038*(yhigh-IM(sonicval))/ydif,.0001))*i'
                  \->NUM DUP IM .15 BEEP RE .15 BEEP
            END
          \>>
        \>> SWAP EVAL
      \>>
    \>>

 MAPLINE @ 'expr(X)' startvalue -> 'expr(X)' nextvalue @
         @ compute and plot the iterate of the function @
         @ determined by the given expression in X @
    \<< \-> EF PT
      \<< EF 
        'X' PT 2 \->LIST | 
        \->NUM 
       \-> PT2
        \<< 'PT+PT*i' \->NUM
          'PT+PT2*i' \->NUM
          LINE 
          'PT+PT2*i' \->NUM
          'PT2+PT2*i' \->NUM
          LINE
          EF PT2 
          {# 0h # 0h } PVIEW
        \>>
      \>>
    \>>


 ROSSLERNEXT @ compute next Euler time-step @
             @ of the Rossler band dynamical system @
    \<< \-> X Y Z d
      \<< X Y Z ROSSLER\Gd        @ \GdX \GdY \GdZ @
       \-> x y z
        \<< X x d * +
          Y y d * + 
          Z z d * +
          d
        \>>
      \>>
    \>>

 ROSSLER\Gd  @ compute components of Rossler vector field @
    \<< \-> X Y Z
      \<< Y NEG Z - 
        X Y .398 * + 
        2 Z X 4 - * +
      \>>
    \>>

 PPAR { (-1,-1) (10,10) X 0 (0,0) FUNCTION Y }
 
 SONICDRAW  @ draw EQ with sonic plotting @
    \<<
      \<< EQ \-> SF eq   @ capture the scaling function as SF @
        \<<
          IFERR eq
            IF { '&1=&2' 'SF(&1)=SF(&2)' } \|vMATCH
            THEN
            ELSE {& 'SF(&)' } \|vMATCH DROP
            END
            STEQ DRAW
          THEN eq STEQ ERRM DOERR
          END 
          eq STEQ
        \>>
      \>> SONICEVAL
    \>>

 EQ '(X+3)*((X+1)*((X-1)*(X-3)))*.05'


END

END_ASC
Xref: sparky comp.sys.hp48:6327 comp.sys.handhelds:2576