- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatChapter9/C091704b.cpp

Go to the documentation of this file.

    00001 #include "MusimatChapter9.h"
    00002 MusimatChapter9Section(C091704b) {
    00003 Print("*** Brownian Nose Generator ***");
    00004 /*****************************************************************************
    00005
    00006 Brownian Nose Generator
    00007
    00008 Here is a simple Brownian number generator (F. R. Moore 1990):
    00009 *****************************************************************************/
    00010         para1(); // Step into this function to continue.
    00011 }
    00012
    00013 Real brownian(Real x, Real w, Real B){
    00014         Real R;
    00015         Do {
    00016                 R = x + Random( -w, w );
    00017         } While ( R > B Or R < -B );
    00018         Return R;
    00019 }
    00020
    00021 Static Void PlotPoint(Real x, Real y)
    00022 {
    00023         //Note, this function is a placeholder for the appropriate
    00024         //graphics function call on your platform to plot a point
    00025         //on a graph.
    00026 }
    00027
    00028 Static Void para1() {
    00029 /*****************************************************************************
    00030 Parameter x is either the initial value of the random walk or the value last calculated by brownian().
    00031 Parameter w is called the window parameter because it determines the maximum amount by which
    00032 the value of x can change at one time. Parameter B is the bounds, limiting the Brownian motion
    00033 to within its range. This method departs from strict Brownian motion by retrying the random
    00034 choice until the new value lies within this range.
    00035
    00036 We call the brownian() method each time we want a new Brownian number, passing it either
    00037 an initial value or the value of its previous output. For example, the following code generated the
    00038 function shown in figure 9.30.
    00039 *****************************************************************************/
    00040
    00041 Real x = 0.0;
    00042 Real y = 0.0;
    00043
    00044 For (Integer i = 0; i < 1000; i = i + 1) {
    00045         x = brownian(x, 0.5, 0.5);
    00046         y = brownian(y, 0.5, 0.5);
    00047         PlotPoint(x, y);        // plot a point on a graph at location [x, y]
    00048 }
    00049
    00050 /*****************************************************************************
    00051 A Brownian noise signal and its power spectrum on a log-log plot are shown in figure 9.31. The
    00052 straight line in the figure traces the contour of 1/(f*f) for reference.
    00053 *****************************************************************************/
    00054 }}
    00055
    00057 /* $Revision: 1.2 $ $Date: 2006/09/09 06:22:44 $ $Author: dgl $ $Name:  $ $Id: _c091704b_8cpp-source.html,v 1.2 2006/09/09 06:22:44 dgl Exp $ */
    00058 // The Musimat Tutorial © 2006 Gareth Loy
    00059 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy
    00060 // and published exclusively by The MIT Press.
    00061 // This program is released WITHOUT ANY WARRANTY; without even the implied
    00062 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00063 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
    00064 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
    00065 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
    00066 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
    00067 // The Musimat website:                 http://www.musimat.com/
    00068 // This program is released under the terms of the GNU General Public License
    00069 // available here:                      http://www.gnu.org/licenses/gpl.txt
    00070