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 RealList rL(x, y); 00028 Print(rL); 00029 } 00030 00031 Static Void para1() { 00032 /***************************************************************************** 00033 Parameter x is either the initial value of the random walk or the value last calculated by brownian(). 00034 Parameter w is called the window parameter because it determines the maximum amount by which 00035 the value of x can change at one time. Parameter B is the bounds, limiting the Brownian motion 00036 to within its range. This method departs from strict Brownian motion by retrying the random 00037 choice until the new value lies within this range. 00038 00039 We call the brownian() method each time we want a new Brownian number, passing it either 00040 an initial value or the value of its previous output. For example, the following code generated the 00041 function shown in figure 9.30. 00042 *****************************************************************************/ 00043 00044 Real x = 0.0; 00045 Real y = 0.0; 00046 00047 For (Integer i = 0; i < 10; i = i + 1) { 00048 x = brownian(x, 0.5, 0.5); 00049 y = brownian(y, 0.5, 0.5); 00050 PlotPoint(x, y); // plot a point on a graph at location [x, y] 00051 } 00052 00053 /***************************************************************************** 00054 A Brownian noise signal and its power spectrum on a log-log plot are shown in figure 9.31. The 00055 straight line in the figure traces the contour of 1/(f*f) for reference. 00056 *****************************************************************************/ 00057 } 00058 00060 /* $Revision: 1.3 $ $Date: 2006/09/05 08:02:46 $ $Author: dgl $ $Name: $ $Id: C091704b.cpp,v 1.3 2006/09/05 08:02:46 dgl Exp $ */ 00061 // The Musimat Tutorial � 2006 Gareth Loy 00062 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" � 2006 Gareth Loy 00063 // and published exclusively by The MIT Press. 00064 // This program is released WITHOUT ANY WARRANTY; without even the implied 00065 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00066 // For information on usage and redistribution, and for a DISCLAIMER OF ALL 00067 // WARRANTIES, see the file, "LICENSE.txt," in this distribution. 00068 // "Musimathics" is available here: http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916 00069 // Gareth Loy's Musimathics website: http://www.musimathics.com/ 00070 // The Musimat website: http://www.musimat.com/ 00071 // This program is released under the terms of the GNU General Public License 00072 // available here: http://www.gnu.org/licenses/gpl.txt 00073