├── MATLAB ├── RIFFLE │ ├── bin2real.m │ ├── minsep.m │ ├── real2bin.m │ ├── riffle.m │ ├── riffle.tex.data │ └── riffle2.m ├── arrowfield.m ├── cycexample.m ├── cycledriver.m ├── damp.m ├── damplot.m ├── dance.m ├── debt.m ├── euler.m ├── fracstep.m ├── hump.m ├── iterate.m ├── markov_example ├── newdance.m ├── nonlinex.m ├── pendulum.m ├── ppscript.m ├── predpray.m ├── quad.m ├── runpend.m ├── runweird.m ├── showmat.m └── weird.m ├── README.md ├── inv-dyn-sys-book.pdf └── inv-dyn-sys-solns.pdf /MATLAB/RIFFLE/bin2real.m: -------------------------------------------------------------------------------- 1 | function x = bin2real(binvec) 2 | % 3 | % bin2real converts a row vector of 0's and 1's 4 | % to a real in [0,1) 5 | % 6 | n = length(binvec); 7 | pows = (2.^(-[1:n]))'; 8 | x = binvec * pows; 9 | -------------------------------------------------------------------------------- /MATLAB/RIFFLE/minsep.m: -------------------------------------------------------------------------------- 1 | function ms = minsep(list) 2 | % computes the minimum difference between succesive 3 | % elements in list 4 | n = length(list); 5 | delta = list(2:n) - list(1:n-1); 6 | ms = min(abs(delta)); 7 | -------------------------------------------------------------------------------- /MATLAB/RIFFLE/real2bin.m: -------------------------------------------------------------------------------- 1 | function out = real2bin(x,bits) 2 | % 3 | % converts real x \in [0,1) to binary 4 | % 5 | out = zeros(1,bits); 6 | for k=1:bits 7 | if (x >= 1/2), out(k) = 1; end; 8 | x = rem(2*x,1); 9 | end; 10 | -------------------------------------------------------------------------------- /MATLAB/RIFFLE/riffle.m: -------------------------------------------------------------------------------- 1 | function outlist = riffle(inlist) 2 | % 3 | % does a riffle shuffle on list 4 | % 5 | 6 | n = length(inlist); 7 | rnd = sort(rand(1,n)); 8 | y = rem( 2 * rnd, 1); 9 | [yy, idx] = sort(y); 10 | outlist = inlist(idx); 11 | 12 | -------------------------------------------------------------------------------- /MATLAB/RIFFLE/riffle.tex.data: -------------------------------------------------------------------------------- 1 | 2 | sep1 = 3 | 0.0103 7.3972 4 | sep2 = 5 | 0.0103 12.7686 6 | 7 | A & 0.1484 & 0.001001011111 & 0.2968 & 0.01001011111 \\ 8 | 2 & 0.2321 & 0.001110110110 & 0.4642 & 0.01110110110 \\ 9 | 3 & 0.3116 & 0.010011111100 & 0.6232 & 0.10011111100 \\ 10 | 4 & 0.3296 & 0.010101000101 & 0.6592 & 0.10101000101 \\ 11 | 5 & 0.4036 & 0.011001110101 & 0.8072 & 0.11001110101 \\ 12 | 6 & 0.4306 & 0.011011100011 & 0.8612 & 0.11011100011 \\ 13 | 7 & 0.5365 & 0.100010010101 & 0.0731 & 0.00010010101 \\ 14 | 8 & 0.6395 & 0.101000111011 & 0.2790 & 0.01000111011 \\ 15 | 9 & 0.8505 & 0.110110011011 & 0.7011 & 0.10110011011 \\ 16 | T & 0.8675 & 0.110111100001 & 0.7350 & 0.10111100001 \\ 17 | J & 0.9669 & 0.111101111000 & 0.9338 & 0.11101111000 \\ 18 | Q & 0.9873 & 0.111111001100 & 0.9746 & 0.11111001100 \\ 19 | K & 0.9976 & 0.111111110110 & 0.9952 & 0.11111110110 \\ 20 | 21 | 0.0731 & 0.00010010101 & 7 \\ 22 | 0.2790 & 0.01000111011 & 8 \\ 23 | 0.2968 & 0.01001011111 & A \\ 24 | 0.4642 & 0.01110110110 & 2 \\ 25 | 0.6232 & 0.10011111100 & 3 \\ 26 | 0.6592 & 0.10101000101 & 4 \\ 27 | 0.7011 & 0.10110011011 & 9 \\ 28 | 0.7350 & 0.10111100001 & T \\ 29 | 0.8072 & 0.11001110101 & 5 \\ 30 | 0.8612 & 0.11011100011 & 6 \\ 31 | 0.9338 & 0.11101111000 & J \\ 32 | 0.9746 & 0.11111001100 & Q \\ 33 | 0.9952 & 0.11111110110 & K \\ 34 | -------------------------------------------------------------------------------- /MATLAB/RIFFLE/riffle2.m: -------------------------------------------------------------------------------- 1 | % 2 | % does a riffle shuffle on A - K, with lots of feedback 3 | % 4 | 5 | bitdepth = 12; 6 | inlist = [1:13]; 7 | 8 | cn = 'A23456789TJQK'; 9 | 10 | s = 0; 11 | 12 | while(s<.009) 13 | n = length(inlist); 14 | rnd = sort(rand(1,n)); 15 | y = rem( 2 * rnd, 1); 16 | [yy, idx] = sort(y); 17 | outlist = inlist(idx); 18 | 19 | s1 = minsep(rnd); 20 | s2 = minsep(yy); 21 | s = min([s1 s2]); 22 | end; 23 | 24 | sep1 = [s, 720*s1] 25 | sep2 = [s,720*s2] 26 | 27 | 28 | for k=1:n 29 | disp( sprintf( ... 30 | '%s & %6.4f & 0.%s & %6.4f & 0.%s \\\\', ... 31 | cn(inlist(k)), ... 32 | rnd(k),... 33 | int2str(real2bin(rnd(k),bitdepth)), ... 34 | y(k),... 35 | int2str(real2bin( y(k),bitdepth-1)) ... 36 | )); 37 | end; 38 | 39 | disp(' '); 40 | 41 | for k=1:n 42 | disp( sprintf( ... 43 | '%6.4f & 0.%s & %s \\\\',... 44 | yy(k), ... 45 | int2str(real2bin(yy(k),bitdepth-1)), ... 46 | cn(outlist(k)) ... 47 | )); 48 | end; 49 | -------------------------------------------------------------------------------- /MATLAB/arrowfield.m: -------------------------------------------------------------------------------- 1 | a = [ 0 1; -1 0] 2 | 3 | [x,y] = meshdom(-3:.4:3, -3:.4:3); 4 | [r,c] = size(x); 5 | m = zeros(x); 6 | 7 | for j=1:r, for k=1:c, 8 | v = a * [x(j,k); y(j,k)]; 9 | m(j,k) = v(1) + i*v(2); 10 | end; end; 11 | 12 | m = m ./ (2*abs(m)); 13 | quiver(m); 14 | -------------------------------------------------------------------------------- /MATLAB/cycexample.m: -------------------------------------------------------------------------------- 1 | function yp = cycexample(t,y) 2 | % 3 | u = y(1); 4 | v = y(2); 5 | a = -0.1; 6 | 7 | yp1 = a*u + v - u*u*u; 8 | yp2 = -u; 9 | yp = [yp1;yp2]; 10 | -------------------------------------------------------------------------------- /MATLAB/cycledriver.m: -------------------------------------------------------------------------------- 1 | axis('square') 2 | [t,y] = ode45('cycexample', 0,50,[start,0]); 3 | plot(y(:,1),y(:,2)); 4 | -------------------------------------------------------------------------------- /MATLAB/damp.m: -------------------------------------------------------------------------------- 1 | function xv = damp(mu,t) 2 | % call damp(mu,t) 3 | % where mu is damping and t is time 4 | % 5 | a = [0 1; -1 -mu]; 6 | xv = expm(a*t)*[1;0]; 7 | -------------------------------------------------------------------------------- /MATLAB/damplot.m: -------------------------------------------------------------------------------- 1 | function damplot(mu,tlast) 2 | % plots x and v as t goes from 0 to tlast 3 | t = [0:.05:tlast]; 4 | [r,n] = size(t); 5 | xvarray = zeros(2,n); 6 | for j=1:n, xvarray(:,j) = damp(mu,t(j)); end 7 | plot(t,xvarray(1,:),t,xvarray(2,:),':'); 8 | -------------------------------------------------------------------------------- /MATLAB/dance.m: -------------------------------------------------------------------------------- 1 | % Dancing on a triangle 2 | 3 | % set up the graphics screen 4 | clg; 5 | axis('square'); 6 | axis([0 1 0 1]); 7 | hold on; 8 | 9 | % we start "point" at the origin 10 | point = [0,0]; 11 | 12 | % let A,B,C be three corners of a triangle 13 | A = [0,0]; 14 | B = [1,0]; 15 | C = [0.5,1]; 16 | 17 | % repeat the following forever 18 | while (1) 19 | % plot the point on the screen 20 | plot(point(1),point(2),'.'); 21 | 22 | % pick a random number among 1, 2 and 3 23 | picker = fix(3*rand(1))+1; 24 | 25 | % jump half way to A, B or C depending on "picker" 26 | if picker==1, point = (point+A)/2; end; 27 | if picker==2, point = (point+B)/2; end; 28 | if picker==3, point = (point+C)/2; end; 29 | end; 30 | -------------------------------------------------------------------------------- /MATLAB/debt.m: -------------------------------------------------------------------------------- 1 | function x = debt(t) 2 | % computes out indebtedness at time t given 3 | % interest rate r = 6% 4 | % initial balance x0 = $1000 5 | % annual payment rate b = $100 6 | 7 | r = 0.06; 8 | x0 = -1000; % negative for a debt 9 | b = 100; % annual payment rate 10 | 11 | x = exp(r*t)*x0 + (b/r)*(exp(r*t)-1); 12 | -------------------------------------------------------------------------------- /MATLAB/euler.m: -------------------------------------------------------------------------------- 1 | function [x,y] = euler(n) 2 | % uses euler's method to compute y(1) for the diff'eq 3 | % y' = x+y with y(0) = 1 4 | % using n steps 5 | 6 | h = 1/n; 7 | x = zeros(1,n+1); 8 | y = x; 9 | y(1) = 1; 10 | for i=1:n 11 | x(i+1) = x(i) + 1/n; 12 | y(i+1) = y(i) + (x(i) + y(i))/n; 13 | end; 14 | -------------------------------------------------------------------------------- /MATLAB/fracstep.m: -------------------------------------------------------------------------------- 1 | function mout = fracstep(m,ifsdata) 2 | % 3 | % mout = fracstep(m,ifsdata) 4 | % performs one step of the IFS in ifsdata on the 5 | % image in m. Answer written to mout 6 | % Assumed that m and mout are square. 7 | % Assume that ifsdata is a 6 by k matrix 8 | 9 | 10 | % get the size of the matrix 11 | [r,c] = size(m); 12 | if (r ~= c) 13 | disp('Input matrix is not square. I can not deal with it.'); 14 | return; 15 | end; 16 | n = r; 17 | 18 | % check the ifsdata matrix, r is the number of rows 19 | [r,c] = size(ifsdata); 20 | if (c~=6) 21 | disp('IFS data matrix should have 6 columns'); 22 | return; 23 | end; 24 | 25 | 26 | mout = zeros(m); % clear output matrix 27 | for k = 1:r % step for each row of the IFS data 28 | A = [ifsdata(k,1), ifsdata(k,2); ifsdata(k,3), ifsdata(k,4)]; 29 | B = [ifsdata(k,5); ifsdata(k,6)]; 30 | for i=1:n, for j=1:n, if m(i,j) % step through m 31 | vec = [i-1;j-1] ./ (n-1); % convert to real data 32 | newvec = A * vec + B; % compute the affine trans 33 | iijj = 1+fix(newvec .* (n-1)); 34 | ii=iijj(1); jj=iijj(2); 35 | if ((1 <= ii) & (ii <= n) & (1 <= jj) & (jj <= n)) 36 | mout(ii,jj)=1; 37 | end; 38 | end;end;end; 39 | end; 40 | 41 | 42 | -------------------------------------------------------------------------------- /MATLAB/hump.m: -------------------------------------------------------------------------------- 1 | function xx = hump(x) 2 | 3 | % xx = hump(x) 4 | % this is an example from the book (end of sect 4.2) 5 | 6 | xx=x; % so xx inherits x's size and shape 7 | 8 | xx = 1- x.^2; 9 | -------------------------------------------------------------------------------- /MATLAB/iterate.m: -------------------------------------------------------------------------------- 1 | function [k,x] = iterate(fnc, x0, steps) 2 | % 3 | % [k,x] = iterate(fnc, x0, steps) 4 | % where... 5 | % fnc is the 'name' of a function 6 | % x0 is the starting value of x (should be a col vec) 7 | % steps is the number of steps 8 | % returns... 9 | % k = [0:steps] 10 | % x a matrix with steps+1 column corresponding to x(0)... 11 | 12 | k = [0:steps]; 13 | 14 | [r,c] = size(x0); 15 | if (c>1) 16 | disp('The initial vector should be a column vector'); 17 | return; 18 | end; 19 | 20 | x = zeros(r,steps+1); 21 | x(:,1) = x0; 22 | 23 | for i=1:steps 24 | x(:,i+1) = feval(fnc,x(:,i)); 25 | end; 26 | -------------------------------------------------------------------------------- /MATLAB/markov_example: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scheinerman/InvitationToDynamicalSystems/70e3b21a6cb91fcc5b57407d60d8b44a65ea592d/MATLAB/markov_example -------------------------------------------------------------------------------- /MATLAB/newdance.m: -------------------------------------------------------------------------------- 1 | % newdance.m 2 | % 3 | % Dancing on a triangle 4 | % 5 | 6 | 7 | % set up the graphics screen 8 | axis('square'); 9 | axis([0 1 0 1]); 10 | hold on; 11 | 12 | npoints = 500; 13 | 14 | corners = [ 0 1 .5; 0 0 1]; 15 | 16 | points = zeros(2,npoints); 17 | choice = fix(3*rand(1,npoints)+1); 18 | 19 | for k=2:npoints 20 | points(:,k) = (points(:,k-1) + corners(:,choice(k-1)))/2; 21 | end; 22 | 23 | plot(points(1,:),points(2,:),'.') 24 | -------------------------------------------------------------------------------- /MATLAB/nonlinex.m: -------------------------------------------------------------------------------- 1 | function xx=nonlinex(x) 2 | % xx = nonlinex(x) 3 | % this is an example from the book (end of sect 3.2) 4 | 5 | xx=x; % so xx inherits x's size and shape 6 | 7 | xx(1) = (x(1)+x(2))/2; 8 | xx(2) = 4 * cos(x(1)); 9 | -------------------------------------------------------------------------------- /MATLAB/pendulum.m: -------------------------------------------------------------------------------- 1 | function xprime = pendulum(t,x) 2 | % 3 | % This function computes the right side 4 | % of equation (1.15) for use with the ode45 5 | % differential equation solver. 6 | 7 | theta = x(1); % the first component of the state vector x is theta 8 | omega = x(2); % and the second component is omega 9 | 10 | thetaprime = omega; 11 | omegaprime = -sin(theta); 12 | 13 | % the result is placed in xprime with the first 14 | % component of xprime being omega and the second 15 | % component being sin(theta) 16 | 17 | xprime = [thetaprime; omegaprime]; 18 | -------------------------------------------------------------------------------- /MATLAB/ppscript.m: -------------------------------------------------------------------------------- 1 | %preditor/prey script 2 | [t,y] = ode45('predpray',0,200,[100;25]); 3 | plot(t,y(:,1),t,y(:,2),':'); 4 | pause; 5 | plot(y(:,1),y(:,2)) 6 | -------------------------------------------------------------------------------- /MATLAB/predpray.m: -------------------------------------------------------------------------------- 1 | function yprime = predpray(t,y) 2 | % 3 | % The preditor/prey model from the text 4 | % y(1) is the number of rabbits 5 | % y(2) is the number of wolves 6 | % 7 | r = y(1); 8 | w = y(2); 9 | 10 | a = .2; b=.1; g = .002; h = .001; 11 | 12 | rprime = a*r - g*r*w; 13 | wprime = -b*w + h*r*w; 14 | 15 | yprime = [rprime;wprime]; 16 | -------------------------------------------------------------------------------- /MATLAB/quad.m: -------------------------------------------------------------------------------- 1 | function xx = quad(x) 2 | 3 | % xx = quad(x) 4 | % xx = x^2 + a 5 | 6 | a = -1.3; 7 | xx=x; % so xx inherits x's size and shape 8 | 9 | xx = x*x+a; 10 | -------------------------------------------------------------------------------- /MATLAB/runpend.m: -------------------------------------------------------------------------------- 1 | % runpendulum 2 | 3 | theta0 = 3; 4 | omega0 = 0; 5 | 6 | last = 30; 7 | 8 | [t,x] = ode45('pendulum',0,last,[theta0,omega0]); 9 | plot(t,x(:,1),'-',t,x(:,2),':'); 10 | -------------------------------------------------------------------------------- /MATLAB/runweird.m: -------------------------------------------------------------------------------- 1 | % run wierd 2 | tstart = 0; 3 | tstop = 50; 4 | y0 = [2;0]; 5 | 6 | 7 | [t,y] = ode45('weird',tstart,tstop,y0); 8 | 9 | plot(y(:,1),y(:,2)); 10 | -------------------------------------------------------------------------------- /MATLAB/showmat.m: -------------------------------------------------------------------------------- 1 | function showmat(m) 2 | % showmat(m) plots the bitmap in m 3 | % we assume m is square and the range is [0,1]^2 4 | [r,c] = size(m); 5 | if (r~=c) 6 | disp('I can only deal with square zero/one matrices'); 7 | return; 8 | end; 9 | 10 | n = r; 11 | 12 | clg; 13 | axis('square') 14 | axis([0 1 0 1]); 15 | 16 | for i=1:n, for j=1:n, if m(i,j), 17 | point = ([i;j]-1) ./ (n-1); 18 | plot(point,'.'); 19 | end;end;end; 20 | 21 | -------------------------------------------------------------------------------- /MATLAB/weird.m: -------------------------------------------------------------------------------- 1 | function ydot = weird(t,y) 2 | % wierd friction f 3 | mu = 0.25; 4 | x = y(1); 5 | v = y(2); 6 | xdot = v; 7 | vdot = -x - mu*v*v*v; 8 | ydot = [ xdot; vdot]; 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Invitation To Dynamical Systems 2 | 3 | This is an undergraduate textbook on dynamical systems, chaos, and fractals originally published by Prentice-Hall. 4 | 5 | ## Purchase the paperback version 6 | 7 | The book is currently published in paperback by [Dover](http://store.doverpublications.com/0486485943.html) 8 | and is available for purchase on 9 | [Amazon](http://www.amazon.com/Invitation-Dynamical-Systems-Dover-Mathematics/dp/0486485943/ref=sr_1_7?ie=UTF8&qid=1328557406&sr=8-7). 10 | 11 | ## Postcardware download 12 | 13 | I make this book (and its solutions manual) available as postcardware. 14 | If you download from this site, send no money; instead, 15 | please send me a postcard from your home town to me at: 16 | 17 | Ed Scheinerman, Office of the Dean, Whiting School of Engineering, Johns Hopkins University, Baltimore, MD 21218 USA 18 | 19 | Or send a photo of your home town (or your university, or yourself, or your dog, or ...) to me by [email](mailto:ers@jhu.edu). 20 | 21 | ## Matlab code might not work 22 | 23 | Please note that the book includes Matlab programs that were written a long time ago and are likely not compatible with 24 | the current version of Matlab. You'll need to update. A copy of the MATLAB programs I wrote for the book can be found in the 25 | MATLAB folder. 26 | -------------------------------------------------------------------------------- /inv-dyn-sys-book.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scheinerman/InvitationToDynamicalSystems/70e3b21a6cb91fcc5b57407d60d8b44a65ea592d/inv-dyn-sys-book.pdf -------------------------------------------------------------------------------- /inv-dyn-sys-solns.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scheinerman/InvitationToDynamicalSystems/70e3b21a6cb91fcc5b57407d60d8b44a65ea592d/inv-dyn-sys-solns.pdf --------------------------------------------------------------------------------