Part D: Statistics, Linear Algebra, and Visualization

Exercises

  1. Write a Python program MatrixExp.py that exponentiates a square matrix of any dimension by diagonalization. The steps are:
    1. Read in a text file in which you've specified a square matrix A;
    2. Find A's eigenvalues (a vector l) and eigenvectors (a matrix V);
    3. Apply the Python function exp() to the components of l and form a diagonal matrix L with those values on the diagonal; and
    4. Multiply the resulting matrix L with the eigenvector matrix from both sides, in this way: V L V-1. This undoes the diagonalization. It turns out that the result is the exponential of the matrix A; that is, eA = V L V-1.
    5. Print the resulting matrix to a text file.
    Now write a function TaylorMatrixExp(A) that returns the exponential of a matrix A using the approximate matrix Taylor expansion: eA ≈ I + A + 1/2 A2 + 1/3! A3 + 1/4! A4, where I is the identity matrix. Print the matrix to the same file. Use the diagonalization method to check the accuracy of the Taylor series method by calculating the error between the two matrices by averaging the component-by-component error. Print that result, suitably labeled, to the file.
    Hints: A compact way to calculate the error over the elements of a matrix was given in the Programming Lab Notes. Be aware of the differences between the * and dot() operators for numpy arrays. Initially test on three cases: (i) a 2 x 2 matrix A = array( [ [ 2., 1.] , [1., 1.] ] ); (ii) a 3 x 3 matrix A = array([ [ 1., 0., 0.],[0.,2.,0.],[0.,0.,3.] ] ); and (iii) A = array( [ [ 1., 2., 3.] , [ 3., 2., 1.] , [4., 5., 6.] ] ).
  2. Processing experimental data (continued): Recall the data file of the time series of maximum distances between successive iterates of the logistic map: the file produced by MaxSeparation.py developed in the previous exercise for Part C. Write a Python program PlotMaxSep.py that reads this file in and plots the time series. What do you see? What is your interpretation of the results?
  3. Write a Python program LogisticICSpread.py that iterates the logistic map at r = 4.0. Have it calculate the mean and standard deviation of a tightly clustered set of 1000 initial conditions as a function of iteration number. The bunch of initial conditions should be Gaussian distributed about x = 0.3 with a standard deviation of 10-3. For output, have the program plot two time series: mean position of the bunch versus iteration number and the standard deviation of the bunch versus iteration number.
    Hints: Start with a copy of the LogisticData.py you wrote previously. Use the numpy package statistics functions.
  4. Write a Python program LogisticDensity.py that plots the probability density of iterates of the logistic map at r = 4.0. Choose an initial condition, iterate it a number of times (say, 100), then collect the state values for the next 10,000 iterations, storing the counts of how often the iterates fall into 20 bins along the unit interval. Plot the resulting distribution of iterates on the interval.
    Hints: See the Programming Lab Notes this week. Use the numpy package histogram function, if you like.
  5. Write a new Python program DensityEvolution.py that shows graphically the iteration of a tightly packed set of initial conditions after a specified number of iterations. If the specified number of iterations is 0, then the program should simply plot the starting distribution of initial conditions. If the specified number of iterations is N > 0, then it should plot the distribution after N iterations.
    Hint: Combine parts of LogisticICSpread.py and LogisticDensity.py.

Table of Contents