File: node64.html

package info (click to toggle)
dstooltk-doc 2.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,024 kB
  • ctags: 451
  • sloc: perl: 753; makefile: 49; sh: 8
file content (312 lines) | stat: -rw-r--r-- 12,434 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 98.1p1 release (March 2nd, 1998)
originally by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>A Vector Field Example: Duffing's Equations</TITLE>
<META NAME="description" CONTENT="A Vector Field Example: Duffing's Equations">
<META NAME="keywords" CONTENT="userman">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="userman.css">
<LINK REL="next" HREF="node66.html">
<LINK REL="previous" HREF="node52.html">
<LINK REL="up" HREF="node50.html">
<LINK REL="next" HREF="node65.html">
</HEAD>
<BODY >
<!--Navigation Panel-->
<A NAME="tex2html1325"
 HREF="node65.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
 SRC="/usr/lib/latex2html/icons.gif/next_motif.gif"></A> 
<A NAME="tex2html1322"
 HREF="node50.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
 SRC="/usr/lib/latex2html/icons.gif/up_motif.gif"></A> 
<A NAME="tex2html1316"
 HREF="node63.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
 SRC="/usr/lib/latex2html/icons.gif/previous_motif.gif"></A> 
<A NAME="tex2html1324"
 HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
 SRC="/usr/lib/latex2html/icons.gif/contents_motif.gif"></A>  
<BR>
<B> Next:</B> <A NAME="tex2html1326"
 HREF="node65.html">A Few Remarks on</A>
<B> Up:</B> <A NAME="tex2html1323"
 HREF="node50.html">User-Defined Dynamical Systems</A>
<B> Previous:</B> <A NAME="tex2html1317"
 HREF="node63.html">Installing a Defined Dynamical</A>
<BR>
<BR>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION00630000000000000000">&#160;</A><A NAME="vfield">&#160;</A>
<BR>
A Vector Field Example: Duffing's Equations
</H1>
In this section we present an example of installing a user-defined vector field into DsTool.
It is assumed that the reader is familiar with the material in Section&nbsp;<A HREF="node52.html#def_ds"><IMG  ALIGN="BOTTOM" BORDER="1" ALT="[*]"
 SRC="/usr/lib/latex2html/icons.gif/cross_ref_motif.gif"></A>.

<P>
Our task is to install the vector field defined by the equations
<A NAME="duff1">&#160;</A>
<BR>
86#86
<BR>
This system is known as Duffing's equations and we direct the reader to 
[<A
 HREF="node68.html#guckenheimerholmes">1</A>] and references therein for an exposition of the dynamics of this system.

<P>
To define and install this system, change to your local DsTool directory
and copy the file GENERIC.c to the file userduffing_def.c.
Use any text editor to edit userduffing_def.c.

<P>
The segment of code which defines the equations of motion (Equation&nbsp;<A HREF="node64.html#duff1"><IMG  ALIGN="BOTTOM" BORDER="1" ALT="[*]"
 SRC="/usr/lib/latex2html/icons.gif/cross_ref_motif.gif"></A>) 
will be called userduffing().  This function is defined as follows:
<PRE>
/* ------------------------------------------------------------------------
   function used to define the vector field 
   ------------------------------------------------------------------------ */
int userduffing(f,x,p)
double *f,*x,*p;
{
   f[0] = x[1];
   f[1] = x[0] - x[0]*x[0]*x[0] - p[0]*x[1] - p[1]*cos( p[2]*x[2] );
}
</PRE>
Here we have defined the variables and parameters as

	x &amp;=&amp; { x[0], x[1] } = { u, v }, <BR>
p &amp;=&amp; { p[0], p[1], p[2] } = { , , }.

As usual, the independent variable is stored after the spatial variables so that
x[2] is time.  The function userduffing() returns in the array f the strength of the
vector field with parameters p, evaluated at the point x.

<P>
We now define the Jacobian of Equation&nbsp;<A HREF="node64.html#duff1"><IMG  ALIGN="BOTTOM" BORDER="1" ALT="[*]"
 SRC="/usr/lib/latex2html/icons.gif/cross_ref_motif.gif"></A> by writing the function userduffing_jac():
<PRE>
/* ------------------------------------------------------------------------
   function used to define the Jacobian
   ------------------------------------------------------------------------ */
int userduffing_jac(m,x,p)
double  **m, *x, *p;
{
   m[0][0] = 0.0;
   m[0][1] = 1.0;
   m[1][0] = 1.0 - 3.0 * x[0] * x[0];
   m[1][1] = -p[0];
}
</PRE>

<P>
Since our equations are for a vector field, we do not need to define an inverse function.
Our vector field is time-dependent, so we can define a function which returns
the temporal derivatives of the vector field.   This function is not yet used by DsTool, and
there is no template for such a function 
in GENERIC.c, but it is easy enough to write:
<PRE>
/* ------------------------------------------------------------------------
   function used to define temporal derivatives
   ------------------------------------------------------------------------ */
int userduffing_dfdt(f,x,p)
double  *f, *x, *p;
{
   f[0] = 0.0;
   f[1] = -p[1] * p[2] * sin( p[2] * x[2] ); 
}
</PRE>

<P>
Since our vector field is Hamiltonian for 
<!-- MATH: $\delta = 0$ -->
87#87,
we choose 
<BR><P></P>
<DIV ALIGN="CENTER">
<!-- MATH: \begin{displaymath}
H(u,v) = \frac{v^2}{2} - \frac{u^2}{2} + \frac{u^4}{4}
\end{displaymath} -->


88#88
</DIV>
<BR CLEAR="ALL">
<P></P>
as an auxiliary function.  We will also define a second auxiliary function.  Since our vector field is
periodic in time (with period 
<!-- MATH: $2 \pi / \omega$ -->
89#89), it is a common technique to look at the time-
<!-- MATH: $2 \pi / \omega$ -->
89#89map in order to better understand the dynamics.  This ``stroboscopic map'' can also be thought
of as a Poincar&#233; map for the extended phase space.  
We are thus interested in the times <I>t</I> for which 
<!-- MATH: $\sin( wt + t_0) = 0$ -->
90#90.
Choosing <I>t</I><SUB>0</SUB> = 0we define the procedure userduffing_aux() by:
<PRE>
/* ------------------------------------------------------------------------
   function used to define aux functions of the varbs, time, or params
   ------------------------------------------------------------------------ */
int userduffing_aux(f,x,p)
double *f,*x,*p;
{
   double   temp;

   temp = 0.5 * x[0] * x[0];
   f[0] = 0.5 * x[1] * x[1] - temp + temp * temp;
   f[1] = sin( p[2] * x[2] );
}
</PRE>

<P>
We are now ready to define the labels and initial conditions for Duffing's equations
by writing the function userduffing_init().  We choose [-2, 2] as default plotting ranges for both 
<I>u</I> and <I>v</I>.  Initializing the variables is straightforward:
<PRE>
int userduffing_init()
{
/* ------------ define the dynamical system in this segment --------------- */

int            n_varb=2;                  /* dim of phase space           */
static char    *variable_names[]={"u","v"}; /* list of phase varb names   */
static double  variables[]={0.5,0.5};     /* default varb initial values  */
static double  variable_min[]={-2.,-2.};  /* default varb min for display */
static double  variable_max[]={2.,2.};    /* default varb max for display */

static char    *indep_varb_name="time";   /* name of indep variable             */
static double  indep_varb_min=0.;         /* default indep varb min for display */
static double  indep_varb_max=1000;       /* default indep varb max for display */
</PRE>

<P>
Defining the parameter ranges is somewhat arbitrary. Sometimes it is difficult to 
tell <EM>a priori</EM> what range of parameters will provide interesting bifurcations.
This is not a big problem
since it is a trivial matter to change the range upon which a function (or parameter) is plotted
once within DsTool.  
We choose [0,1] as a range for each parameter.  We choose 
<!-- MATH: $(\delta_0, \gamma_0, \omega_0)
= (0.25, 0.4, 1.0)$ -->
91#91:
<PRE>
int           n_param=3;                  /* dim of parameter space        */
static char   *parameter_names[]={"delta","gamma", "w"}; /* list of param names */
static double parameters[]={0.25,0.4,1.}; /* initial parameter values      */
static double parameter_min[]={0.,0.,0.}; /* default param min for display */
static double parameter_max[]={1.,1.,1.}; /* default param max for display */
</PRE>

<P>
The initialization of our two auxiliary functions is accomplished by the code segment:
<PRE>
int            n_funct=2;               /* number of user-defined functions */
static char    *funct_names[]={"H", "P_Section"}; /* list of funct names; {""} if none */
static double  funct_min[]={-4.,-1.};   /* default funct min for display    */
static double  funct_max[]={4.,1.};     /* default funct max for display    */
</PRE>
As in the case with parameters, it is sometimes difficult to choose <EM>a priori</EM>
what appropriate ranges for the functions should be.  

<P>
The manifold type for Duffing's equations is EUCLIDEAN since we do not have any 
periodic spatial variables.  Thus we do not need to modify the following segment of code:
<PRE>
int           manifold_type=EUCLIDEAN; /* EUCLIDEAN or PERIODIC                 */
static int    periodic_varb[]={FALSE, FALSE}; /* if PERIODIC, which varbs periodic? */
static double period_start[]={0.,0.};  /* if PERIODIC, begin fundamental domain */
static double period_end[]={1., 1.};   /* if PERIODIC, end of fundamental domain*/
</PRE>

<P>
The last segment of code we need to modify is the segment which tells DsTool which numerical algorithms
may be used on the Duffing's equations.  
We complete the definition of userduffing_init() with the code segment:
<PRE>
int           mapping_toggle=FALSE;       /* this is a map? TRUE or FALSE         */
int           inverse_toggle=FALSE;       /* if so, is inverse FALSE, APPROX_INV, */
                                        /* or EXPLICIT_INV? FALSE for vec field */ 

/*  In this section, input NULL or the name of the function which contains...   */
int     (*def_name)()=userduffing;          /* the eqns of motion                   */
int     (*jac_name)()=userduffing_jac;      /* the jacobian (deriv w.r.t. space)    */
int     (*aux_func_name)()=userduffing_aux; /* the auxiliary functions              */
int     (*inv_name)()=NULL;             /* the inverse or approx inverse        */
int     (*dfdt_name)()=userduffing_dfdt;    /* the deriv w.r.t time                 */
int     (*dfdparam_name)()=NULL;        /* the derivs w.r.t. parameters         */
</PRE>

<P>
As in Section&nbsp;<A HREF="node52.html#def_ds"><IMG  ALIGN="BOTTOM" BORDER="1" ALT="[*]"
 SRC="/usr/lib/latex2html/icons.gif/cross_ref_motif.gif"></A>, we now need to edit two other files.
We edit Makefile and add userduffing_def.c
to the USER_SRCS list, and add userduffing_def.o to the
USER_OBJS list.  We also edit the file
user.c and add the lines
<PRE>
extern int  userduffing_init();
</PRE>
and 
<PRE>
{0, "Duffing's Eqns", userduffing_init},
</PRE>
to  the second and third blocks of code, respectively.

<P>
Typing make
will create a local executable of DsTool which includes Duffing's equations among its installed dynamical
systems.

<P>
<BR><HR>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS">&#160;</A>
<UL>
<LI><A NAME="tex2html1327"
 HREF="node65.html">A Few Remarks on the Definition of Duffing's Equations</A>
</UL>
<!--End of Table of Child-Links-->
<HR>
<!--Navigation Panel-->
<A NAME="tex2html1325"
 HREF="node65.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
 SRC="/usr/lib/latex2html/icons.gif/next_motif.gif"></A> 
<A NAME="tex2html1322"
 HREF="node50.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
 SRC="/usr/lib/latex2html/icons.gif/up_motif.gif"></A> 
<A NAME="tex2html1316"
 HREF="node63.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
 SRC="/usr/lib/latex2html/icons.gif/previous_motif.gif"></A> 
<A NAME="tex2html1324"
 HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
 SRC="/usr/lib/latex2html/icons.gif/contents_motif.gif"></A>  
<BR>
<B> Next:</B> <A NAME="tex2html1326"
 HREF="node65.html">A Few Remarks on</A>
<B> Up:</B> <A NAME="tex2html1323"
 HREF="node50.html">User-Defined Dynamical Systems</A>
<B> Previous:</B> <A NAME="tex2html1317"
 HREF="node63.html">Installing a Defined Dynamical</A>
<!--End of Navigation Panel-->
<ADDRESS>
<I>John Lapeyre</I>
<BR><I>1998-09-04</I>
</ADDRESS>
</BODY>
</HTML>