This page was automatically generated by NetLogo 4.1.3.

powered by NetLogo

view/download model file: sprott-03a.nlogo

WHAT IS IT?

This is a mathematical model that demonstrates abstract vector fields and integral curves.

Generally speaking, a field is a "region in which a body experiences a force as the result of the presence of some other body or bodies. A field is thus a method of representing the way in which bodies are able to influence each other. For example, a body that has mass is surrounded by a region in which another body that has mass experiences a force tending to draw the two bodies together.... The strength of any field can be described as the ratio of the force experienced by a small appropriate specimen to the relevant property of that specimen, e.g. force/mass for the gravitational field" (Oxford Minidictionary of Physics).

By 'abstract vector fields' we mean that this model is not committed to any specific type of force, such as gravity or magnetism. Rather, it simulates a general field, in which some focal property of influence affects a "small appropriate specimen", or particle, placed in the field.

Normally, if you look at a field with bare eyes, you will not necessarily see the forces. For instance, if you drop an apple it falls down, even though you cannot see the gravitational force. The apple is an object in the gravitational field. You saw how it behaved so you could guess that there is some force that made it go down. Humans do not perceive (visually) forces of gravitation or electro-magnetic forces. However, in a model, we can use little arrows (vectors) to show where, how forceful, and in which direction there are forces in this field.


HOW IT WORKS

In this model, the field is plotted using vector graphics: green streaks are individual vectors with yellow turtles serving as arrowheads. The length of each vector is roughly proportional to the magnitude of the vector field at each point. In this model, it is just the distance from the origin: The further away from the origin, the larger the vector. Also, all vectors are aimed clockwise along tangents to circles centered on the origin.

The vectors show you in what direction and how forcefully an appropriate specimen -- here, a 'particle' -- will be "knocked about" once it is placed the field. Once the particle is "knocked" to a new location, it will be knocked yet again by the force there (represented by the vector). Actually, it being "knocked about" continuously, but in this simulation, the "knock" occurs at discrete points in the field. Since the particle does not use up the forces, it will keep being knocked about. The path the particle takes is called its 'trajectory.' You will be able to track this trajectory because the particle will leave a red trail behind it as it moves along its trajectory. Trajectories in vector fields are called 'integral curves.'

Even though behavior of particles can be interesting and possibly unanticipated, owing to forces not being distributed uniformly in the field, or some other factor, we have chosen, for clarity, a vector field with a logical and consistent relation between location in space and size/orientation of the force. The vector field chosen for this particular model is

    - y d/dx  +  x d/dy

Ideally, in the particular force field modeled here, the particle trajectories should be concentric circles (that is, the particle should go round and round along the same circular trajectory).


HOW TO USE IT

SETUP: Clears the screen and computes the vector field.
PLACE-PARTICLES: Puts the program into the mode in which you can position red test-particles by clicking anywhere in the graphics window.
GO: Runs the simulation continuously to show the integral curves.


THINGS TO NOTICE

Notice that the vectors grow in length as you move away from the origin. What effect do short vectors have on a particle? Long vectors?

The way this model is programmed, each particle moves some finite amount before calculating its new heading. Therefore, the particles do not turn as much as they would if their headings were continuously recalculated. This causes their trajectories to spiral slowly outward. (You have to let the model run for a while before this becomes apparent.) We tried to minimize this by having the particles move forward only a very small amount at each time step (the variable STEP-SIZE). We couldn't make this amount too small since the model would then run too slowly. If you want the particles to spiral less, or you want the model to run faster, change this value.


THINGS TO TRY

Place particles in different parts of the screen. Does the particle's position have any effect on the trajectory?


EXTENDING THE MODEL

Try a different vector field by changing it in the SETUP-VECTOR, FORCE-X, and FORCE-Y procedures. For instance, if you choose

    x d/dx - y d/dy

the integral curves will be hyperbolas.


CREDITS AND REFERENCES

To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Vector Fields model. http://ccl.northwestern.edu/netlogo/models/VectorFields. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/VectorFields for terms of use.


PROCEDURES

;;; sprott03a.nlogo, cr 28 jan 2011 (NLS brought inside)

extensions [ sound ]

;;; BREEDS ;;;;;;;;;;;
breed [ particles ]

;;; VARIABLES ;;;;;;;;;;;
globals
[
  deltax deltay   ;;; window widths for conversion routines
  deltau deltav   ;;; world coord window widths
  umin umax vmin vmax ;;; from def of map-u and map-v
  xmin xmax ymin ymax ;;; from Graphics Window attributes
  u-smallest u-largest v-smallest v-largest ;;; or debugging
  a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 ;;; eqn coeffs from file
  radius ;;; for geometry
  u-offset 
  v-offset
]
patches-own [ hits ] ;;; record number of hits by a particle (new to dorband2)

;;; PROCEDURES ;;;;;;;;;;;;;;;;;;;;

;;; these are for coord conversion functions (affine isomorphisms)
to init-globals
  set-eqns ;;; from included file
  set xmin min-pxcor
  set xmax max-pxcor
  set ymin min-pycor
  set ymax max-pycor
  set deltax world-width - 1 ;;; this is Graphics Window attribute
  set deltay world-height - 1 ;;; this is Graphics Window attribute
  set umin ( - 1 ) * ( 4 / 3 ) * radius - u-offset
  set umax ( 4 / 3 ) * radius - u-offset
  set vmin ( - 1 ) * radius - v-offset
  set vmax radius - v-offset
  set deltau (umax - umin) 
  set deltav (vmax - vmin)
  set u-smallest 0 ;;; initial value
  set u-largest 0
  set v-smallest 0
  set v-largest 0
end

;;; REPORTERS ;;;;;;;;;;;;;;;

;;; ==============================================
;;; conversion functions, world-coords <--> turtle-screen-coords:
;;; horizontal: (u <--> x), vertical (v <--> y)
;;; ----------------------------------------------
;;; (u <-- x): u = convert(x)
to-report horizconvert [ x ]
  let u (deltau * ( x - xmin ) / deltax) + umin
  report u
end

;;; (u --> x): x = deconvert(u)
to-report horizdeconvert [ u ]
  let x (deltax * ( u - umin ) / deltau) + xmin
  report x
end

;;; (v <-- y): v = convert(y)
to-report vertconvert [ y ]
  let v (deltav * ( y - ymin ) / deltay) + vmin
  report v
end

;;; (v --> y): y = deconvert(v)
to-report vertdeconvert [ v ]
  let y (deltay * ( v - vmin ) / deltav) + ymin
  report y
end
;;; ==============================================
;;; more procedures
to setup
  ca
  init-globals
  let u0 0.05 ;;; sprott init values
  let v0 0.05
  let x0 horizdeconvert u0
  ;; show x0
  let y0 vertdeconvert v0
  crt 1 
    [ 
    setxy x0 y0 
    set size 5
    ]
end

;;; green test particles move along trajectories, leaving red blotches
to go
  every 0.2 [ step ]
end

to step
  ask turtle 0
  [ 
    ifelse hits > 10 [ set pcolor red ] ;;; primitive color code for density
      [ ifelse hits > 5 [ set pcolor green ] 
        [ ifelse hits > 1 [ set pcolor blue ] [set pcolor magenta ] ] ]
    set hits ( hits + 1 )
    let xtemp xcor
    let ytemp ycor
    set xcor map-x xtemp ytemp ;;; move to image point
    set ycor map-y xtemp ytemp
    sound:play-note "TRUMPET" ( 60 + xtemp ) (50 + ytemp) 0.1
  ]
  tick
end

;;; reset pcolor of all patches
to clear
  ask patches
  [
    set pcolor black
  ]
end

;; calculate the horizontal component of the map where the turtle is located
to-report map-x [ x y ] ;; turtle procedure
  let utemp1 horizconvert x
  let vtemp1 vertconvert y
  let utemp2 map-u utemp1 vtemp1
  let xtemp horizdeconvert utemp2
  if xtemp > xmax [ set xtemp xmax ] ;;; have to crop as wrapping is urned off
  if xtemp < xmin [ set xtemp xmin ]
  report xtemp
end

;; calculate the vertical component of the map where the turtle is located
to-report map-y [ x y ] ;; turtle procedure
  let utemp1 horizconvert x
  let vtemp1 vertconvert y
  let vtemp2 map-v utemp1 vtemp1
  let ytemp vertdeconvert vtemp2
  if ytemp > ymax [ set ytemp ymax ] ;;; have to crop as wrapping is urned off
  if ytemp < ymin [ set ytemp ymin ]
  report ytemp
end

;;; and at last, the map in world coords
to-report map-u [ u v ]
  let new-u ( a1 + a2 * u + a3 * u * u + a4 * u * v + a5 * v + a6 * v * v )
  if new-u < u-smallest [ set u-smallest new-u ]
  if new-u > u-largest [ set u-largest new-u ]
  report new-u
end

to-report map-v [ u v ]
  let new-v ( a7 + a8 * u + a9 * u * u + a10 * u * v + a11 * v + a12 * v * v )
  if new-v < v-smallest [ set v-smallest new-v ]
  if new-v > v-largest [ set v-largest new-v ]
  report new-v
end

;;; sprott03.nls, 28 jan 2011, params for fig 3-2

to set-eqns  
  set a1 -1.1 ;;; B
  set a2 -1.0 ;;; C
  set a3 0.4 ;;; Q
  set a4 -1.2 ;;; A
  set a5 -0.7 ;;; F
  set a6 0.0  ;;; M
  set a7 -0.7 ;;; F
  set a8 0.9 ;;; V
  set a9 0.3 ;;; P
  set a10 1.1 ;;; X
  set a11 -0.2 ;;; K
  set a12 0.4 ;;; Q
  set radius 1.2 ;;; found by experiment
  set u-offset 0.3
  set v-offset 0.2
end

;;; END sprott03a.nlogo