Example of m-file, graphic output, matlab writeup (Word and PDF formats)

linear_beetle.m equations 1.5 (page 39) of text. You can download this file by right clicking on the link and using the "save as ..." option

Output from linear_beetle.m [PNG format]

Sample writeup [Microsoft Word format]

Sample writeup [PDF format]


cobweb.m Generate cobweb plot

f.m sample function

Execute by typing

	cobweb(@f,0,1,0.1,0.15); 
into matlab command window.
Codes for 2-body problem

twobody_script.m
twobody.m


Essential pieces for calculating correlation dimension:

N = length of data set "data", "r" is the tolerance, k is the number of data within the tolerance

for (i=1:N)
  for (j=1:N)
      if ((i ~= j) && (abs(data(i)-data(j)) < r))
          k=1+k;
      end
  end
end
Note: This actually double counts pairs, so you can either divide by 2, or modify the code to be
for (i=1:N)
  for (j=i:N) % eliminate double counting ...
      if ((i ~= j) && (abs(data(i)-data(j)) < r))
          k=1+k;
      end
  end
end
Now return k/N^2 (percentage of total points within tolerance r). The exact percentage is k/(N*(N-1)/2), but this introduces an additive constant of log(2) which dissapears in the limit...

To calculate correlation dimension (via least squares), use the Matlab built in function "polyfit", where the independent variable is log(r) and the dependent variable is log(C(r))