Coupled-map lattice dynamics, use of background task for real-time updates

Education: This code demonstrates coupled map lattices, a simple form of dynamical system that shows intriguing complex behavior. On a 2d lattice (with periodic boundary conditions), every site has a logistic map, f(x)=ax(1-x). This map itself is a famous example of a simple dynamical system showing chaos and many other phenomena. The maps on each site are coupled diffusively (approximating a 2d Laplacian).

Programming: This is my first use of background tasks in Igor, and hopefully this example will help others get started. For demonstrating to a class, I wanted to show real-time execution, changing parameters on the fly. Here, the map is updated as a background task (10 times a second). This allows control changes to register and update. Thanks to Larry Hutchinson for getting me going.

To do: Copy this code into your procedure window. Type demo() on the command line. Use the buttons to alter values, start and stop, reset, etc.

To try: Set a=4 (fully chaotic). Toggle D=0 (independent) to D ~ 1.0. For D>1, the pattern synchs completely if you let it. Just before it's all uniform, go back to D=0.
Notice how the chaos rapidly destroys all memory of the nearly synched initial condition. Use "Initialize" if it syncs.

Note: a bug in cml_2d (apparent at once in Igor 6.3x) was corrected on October 20, 2013.


Function demo()                         // execute this first!
    Variable/G a=3.1, D=0, nmax=20
    initialize()                                // initialize u to random
   
    Execute "u_graph()"                 // create the lattice graph, with controls
    Execute "udisp_graph()"             // create the time series graph
End

function initialize()
    Nvar nmax
    Make /o/n=(nmax,nmax) u=(1+enoise(1))/2 // init cond (0<u<1)
    Make /o/n=100 udisp=0                   // for displaying last 100 points
end

function cml_2d(u,a,D,nmax)                 // 2d lattice, periodic boundary conditions
    wave u; variable a,D,nmax
    duplicate /free u, u1, f_left,f_right,f_up,f_down
    f_left[1, ][] = f(a,u[mod(p-1,nmax)][q])                // evaluate f at    u(i-1,j)
    f_right[0,nmax-2][]= f(a,u[mod(p+1,nmax)][q])       //              u(i+1,j)
    f_up[][0, nmax-2] = f(a,u[p][mod(q+1,nmax)])        //              u(i,j+1)
    f_down[][1, ] = f(a,u[p][mod(q-1,nmax)] )           //              u(i,j-1)
    u1 = f(a,u)*(1-D) + (D/4)*(f_left+f_right+f_up+f_down)
    u = u1
    wave udisp
    Rotate -1, udisp;                               // shift to make chart-like display
    udisp[numpnts(udisp)-1]=u[0][0]         // add new time point
end

function f(a,u)                                 // logistic map
    variable a,u
    return a*u*(1-u)
end

//_______________________________________________________

Function MyBackground(s)
    STRUCT WMBackgroundStruct &s
    NVAR a,D,nmax
    WAVE u
    cml_2d(u,a,D,nmax)                  // iterative map update
    return 0
End

Function ButtonProc(ba) : ButtonControl
    STRUCT WMButtonAction &ba
    switch( ba.eventCode )
        case 2: // mouse up
            initialize()                        // re-initialize u to random
            break
    endswitch
    return 0
End


Function CheckProc(s) : CheckBoxControl
    STRUCT WMCheckboxAction &s 
    if (s.eventCode == 2 )  // mouse up
        if (s.checked )
            CtrlNamedBackground fred,period=6,proc=MyBackground, start
        else
            CtrlNamedBackground fred,stop
        endif
    endif
    return 0
End
//_______________________________________________________

Window u_graph() : Graph
    PauseUpdate; Silent 1       // building window...
    Display /W=(750,137,1243,602)
    AppendImage u
    ModifyImage u ctab= {0,1,Grays,0}
    ModifyGraph margin(right)=72,width=360,height={Plan,1,left,bottom}
    ModifyGraph mirror=2
    ControlBar 43
    SetVariable setvar0,pos={63,12},size={70,22},title="D",fSize=14
    SetVariable setvar0,limits={0,10,0.1},value= D
    SetVariable setvar1,pos={151,11},size={70,22},title="a",fSize=14
    SetVariable setvar1,limits={0,4,0.01},value= a
    Button button0,pos={239,11},size={80,20},proc=ButtonProc,title="Initialize"
    CheckBox ck,pos={340,11},size={90,19},proc=CheckProc,title="Run / stop",fSize=14
    CheckBox ck,value= 0
EndMacro

Window udisp_graph() : Graph
    PauseUpdate; Silent 1       // building window...
    Display /W=(257,44,722,327) udisp
    ModifyGraph width=360,height=216
    ModifyGraph lSize=2
    ModifyGraph nticks(left)=2
    ModifyGraph minor(left)=1
    ModifyGraph fSize=14
    Label left "u(0,0)  [typical lattice site]"
    Label bottom "Iteration number"
    SetAxis left 0,1
EndMacro

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More