Summer 2005 Research Repository for Files, Examples, etc.


Some Links


Some Examples


Code generator for some functions needed to compute solutions of the coupled oscillator system

cpldosc_codegen.cpp This C++ program uses ginac to create an assortment of C subroutines.
ginac_linalg_funcs.cpp Some ginac-related functions
ginac_linalg_funcs.h Header file that must be included in any file that uses functions in ginac_linalg_func.cpp
ginac_write_code.cpp Functions that write C code based on ginac expression, vectors or matrices.
Makefile_codegen Makefile for cpldosc_codegen

To run this program, save the files in a directory, and run the commands

 $ make -f Makefile_codegen
 $ ./cpldosc_codegen
The program will create several C files.

Solver for the slow vector field

cpldosc_slowvf_main.c The main routine for a program that computes solutions to the slow vector field, and stops when it reaches a fold.
evt_stepsize.c The step size function that helps to ensure that sign changes are detected.
Makefile_slowvf Makefile for the cpldosc_slowvf_main program.

To run this program, you must first download and run the code generator. Then save these files in the same directory, and run (for example)

 $ make -f Makefile_slowvf
 $ ./cpldosc_slowvf_main 1.0 1.5 3 1.25 0.05 10 > data
 $ gnuplot
gnuplot> set xlabel "v1"
gnuplot> set ylabel "v2"
gnuplot> plot "data" using 2:3 with linespoints
gnuplot> quit
The command line arguments for the executable cpldosc_slowvf_main are: v1, v2, sigma1, sigma2, omega, stoptime. (The solution will stop when it reaches a fold or at time stoptime, which ever happens first.)

Solver for the fast vector field

cpldosc_fastvf_main.c The main routine for a program that computes solutions to the fast vector field, and stops when it reaches an equilibrium point.
cpldosc_fast_gvf.c The C function that defines the fast vector field and its Jacobian, to be used with the GSL ODE suite.
cpldosc_fast_proto.h Header file that give the function prototypes for the functions defined in cpldosc_fast_gvf.c
Makefile_fastvf Makefile for the cpldosc_fastvf_main program.

To run this program, save these files, and run (for example)

 $ make -f Makefile_fastvf
 $ ./cpldosc_fastvf_main 1.0 1.2 0.9 0.25 3 1.25 0.05 100 > data
 $ gnuplot
gnuplot> set xlabel "t"
gnuplot> plot "data" using 1:2 with linespoints, "data" using 1:3 with linespoints
gnuplot> quit
The command line arguments for the executable cpldosc_fastvf_main are: v1, v2, q1, q2, sigma1, sigma2, omega, stoptime. (The solution will stop when it "reaches" an equilibrium point, or when stoptime is reached, which ever occurs first.)

Another solver for the slow vector field

In the version, the code that actually solves the differential equations has been put into a separate function that is called by the main program. You must run the cpldosc_codegen program first, and you also need evt_stepsize.c.

cpldosc_slowvf_main2.c The main routine. This puts the command-line arguments into appropriate arrays, and calls cpldosc_slowvf_solve.
cpldosc_slowvf_solve.c This file contains the function that actually calls the GSL ODE solver to solve the differential equations.
Makefile_slowvf2 Makefile for the cpldosc_slowvf_main2 program.

To run this program, you must first download and run the code generator. You must also get evt_stepsize.c. If you put the files from the previous examples all in one directory, then you can just add these three new files to the same directory. Run the commands:

 $ make -f Makefile_slowvf2
 $ ./cpldosc_slowvf_main2 1.0 1.5 3 1.25 0.05 10 > data
 $ gnuplot
gnuplot> set xlabel "v1"
gnuplot> set ylabel "v2"
gnuplot> plot "data" using 2:3 with linespoints
gnuplot> quit
The command line arguments for the executable cpldosc_slowvf_main2 are: v1, v2, sigma1, sigma2, omega, stoptime. (The solution will stop when it reaches a fold or at time stoptime, which ever happens first.)

Compute the fold curve

cpldosc_computefold2.c A program that computes pieces of the fold curve.
Makefile_computefold2 Makefile for the cpldosc_computefold2 program.
cf A shell script that runs cpldosc_computefold2 to compute the fold curves for sigma1=3.00, sigma2=1.25, omega=0.05
plotfold.gnuplot A gnuplot script that plots the files generated by the cf script.

This code computes pieces of the fold curve. Save the files in the same directory with the previous programs. To compile and run it, first run the cpldosc_codegen program (if you haven't already), then

 $ make -f Makefile_computefold2

The executable is called cpldosc_computefold2, and its arguments are v1 v2 sigma1 sigma2 omega delta N, where (v1,v2) is a guess for the starting point, (sigma1, sigma2, omega) are the parameter values, delta is the (maximum) step size, and N is the number of points to compute. Change the sign of delta to change the direction of the computed curve. The program will use the magnitude of the gradient of the fold function to adapt the step size; where the gradient is small, the step size will be small.

Here is an example of running the program and plotting the results.

 $ ./cpldosc_computefold2 -0.4 -1.5 3.0 1.25 0.05  .02 350  > fold3.00-1.25-0.05-1.dat
 $ gnuplot
 > plot "fold3.00-1.25-0.05-1.dat" u 2:3 w lines

To use the cf and plotcurve.gnuplot scripts, do this:

 $ sh cf
 $ gnuplot
 > load "plotcurve.gnuplot"
Here is the result: fold.png.

More files

cpldosc_fast_eigvec0.c A function that computes an eigenvector associated with the zero eigenvalue of the Jacobian of the fast subsystem.

Notes


Some MATLAB Plotting Scripts and Functions

cpldosc_fhat.m Matlab function that computes the critical manifold q=cpldosc_fhat(v,p), where q = (q1,q2), v=(v1,v2) and p=(sigma1,sigma2,omega).
cpldosc_fhat_q1.m Matlab function that computes the q1 coordinate of the critical manifold as a function of (v1,v2). That is, q1=cpldosc_fhat_q1(v,p), where v=(v1,v2) and p=(sigma1,sigma2,omega).
cpldosc_fhat_q2.m Matlab function that computes the q2 coordinate of the critical manifold as a function of (v1,v2). That is, q2=cpldosc_fhat_q2(v,p), where v=(v1,v2) and p=(sigma1,sigma2,omega).
q2plot.m A Matlab script that plots the critical manifold in (v1,v2,q2) coordinates, and also plots two curves, one slow and one fast.
slow.dat Data used by q2plot.m.
fast.dat Data used by q2plot.m.

Here is the output of the Matlab script q2plot: q2plot.png.


More Stuff

slowfast_plot.m Matlab script to plot a curve with alternating blue and red, depending on whether a column of data is 0 or 1.