 # Figures from Modeling and Analysis Principles for Chemical and Biological Engineers

 Michael D. Graham James B. Rawlings Department of Chemical and Biological Engineering Department of Chemical Engineering University of Wisconsin University of California, Santa Barbara Madison, Wisconsin Santa Barbara, California

Copyright (C) 2018 Nob Hill Publishing, LLC

Click on thumbnails to enlarge figures and display Octave/Matlab code and data. You will also need a few files (mostly for plotting) that are included only in the tar.gz or zip files linked below, so if you want to run them, the best thing to do is download the complete collection of M-files! Having the code linked here is still useful if you want to take a quick look at how something is done.

Running the example files requires Octave (version 4.0 or later) or Matlab (R2015a or later). Installation instructions can be found on the respective websites.

Complete collections of the M-files for both Octave and Matlab in zip file formats are available for download from the following links:

 Octave (v1.1) Matlab (v1.1)

## Chapter 1: Linear Algebra Figure 1.3 (page 31): An iteration of the Newton-Raphson method for solving f(x)=0 in the scalar case. Figure 1.6 (page 60): Contours of constant f(x)=x^TAx. Figure 1.8 (page 74): Experimental measurements of variable y versus x. Figure 1.9 (page 76): Measured rate constant at several temperatures. Figure 1.10 (page 84): Plot of Ax as x moves around a unit circle.

## Chapter 2: Ordinary Differential Equations Figure 2.1 (page 103): Dynamical regimes for the planar system dx/dt = Ax, A \in \mathbb {R}^{2 x2}. Figure 2.2 (page 104): Dynamical behavior on the region boundaries for the planar system dx/dt = Ax, A \in \mathbb {R}^{2 x2}. Figure 2.4 (page 123): Function f(x)=o{exp}\leavevmode@ifvmode {\right .}\box }-8\leavevmode@ifvmode {\right .}\box }\frac {x}{\pi }\leavevmode@ifvmode {\right .}\box }^{2}\leavevmode@ifvmode {\right .}\box } and truncated trigonometric Fourier series approximations with K=2,5,10. The approximations with K=5 and K=10 are visually indistinguishable from the exact function. Figure 2.5 (page 125): Truncated trigonometric Fourier series approximation to f(x)=x, using K=5,10, 50. The wiggles get finer as K increases. Figure 2.6 (page 127): Function f(x)=o{exp}\leavevmode@ifvmode {\right .}\box }-8x^{2}\leavevmode@ifvmode {\right .}\box } and truncated Legendre-Fourier series approximations with n=2,5,10. Figure 2.7 (page 128): Function f(x)=H(x) and truncated Legendre-Fourier series approximations with n=10,50,100. Figure 2.12 (page 173): Leading-order inner U_0, outer u_0, and composite solutions u_{0c}, for Example 2.30 with \epsilon =0.2, K=1, and k_{2}=1. Figure 2.15 (page 184): Contours of an energy function V(x_{1},x_{2}) or H(x_{1},x_{2}). Figure 2.16 (page 188): Energy landscape for a pendulum; H = \frac {1}{2} p^2 -\kappa o{cos}q; \kappa =2. Figure 2.17 (page 189): Landscape for H=\frac {1}{2}p^{2}+\frac {1}{4}q^{4}-\frac {1}{2}q^{2}. Figure 2.18 (page 191): A limit cycle (thick dashed curve) and a trajectory (thin solid curve) approaching it. Figure 2.19 (page 192): Periodic (left) and quasiperiodic (right) orbits on the surface of a torus. The orbit on the right eventually passes through every point in the domain. Figure 2.20 (page 194): A limit cycle for the R\"ossler system, a=b=0.2, c=1. Figure 2.21 (page 194): A strange attractor for the R\"ossler system, a=b=0.2, c=5.7. Figure 2.22 (page 196): Bifurcation diagram for the saddle-node bifurcation. Figure 2.23 (page 197): Bifurcation diagram for the transcritical bifurcation. Figure 2.24 (page 198): Bifurcation diagrams for the pitchfork bifurcation. Figure 2.25 (page 203): Approximate solutions to \dot {x}=-x using explicit and implicit Euler methods with \Delta t=2.1, along with the exact solution x(t)=e^{-t}. Figure 2.26 (page 206): Stability regions for Adams-Bashforth methods; \dot {x}=\lambda x. Figure 2.27 (page 207): Stability regions for Adams predictor-corrector methods; \dot {x}=\lambda x. Figure 2.28 (page 208): Stability regions for Runge-Kutta methods; \dot {x}=\lambda x. Figure 2.29 (page 211): Hat functions for N=2. Figure 2.30 (page 213): Approximate solutions to (2.89) using the finite element method with hat functions for N=6 and N=12. The exact solution also is shown. Figure 2.31 (page 217): Dependence of \left | c(j) \right | on j for the Legendre-Galerkin approximation of (2.89) with n=10. Figure 2.34 (page 239): Stability regions for Adams predictor-corrector methods; \dot {x}= \lambda x; APCn' uses nth-order predictor and nth-order corrector.

## Chapter 3: Vector Calculus and Partial Differential Equations Figure 3.12 (page 316): Concentration versus membrane penetration distance for different reaction rate constants. Figure 3.13 (page 337): Transient heating of slab, cylinder, and sphere.

## Chapter 4: Probability, Random Variables, and Estimation Figure 4.1 (page 359): Normal distribution, with probability density p_\xi (x) = (1/\sqrt {2\pi \sigma ^2}) o{exp}(-(1/2) (x-m)^2/\sigma ^2). Figure 4.2 (page 364): Multivariate normal for n=2. The contour lines show ellipses containing 95, 75, and 50 percent probability. Figure 4.5 (page 377): A joint density function for the two uncorrelated random variables in Example4.8. Figure 4.6 (page 381): A nearly singular normal density in two dimensions. Figure 4.8 (page 388): Histogram of 10,000 samples of uniformly distributed x. Figure 4.9 (page 388): Histogram of 10,000 samples of \displaystyle y=\DOTSB \sum@ \slimits@ _{i=1}^{10} x_i . Figure 4.10 (page 403): The multivariate normal, marginals, marginal box, and bounding box. Figure 4.11 (page 427): The sum of squares fitting error (top) and validation error (bottom) for PCR versus the number of principal components \ell ; cross validation indicates that four principal components are best. Figure 4.12 (page 428): The sum of squares validation error for PCR and PLSR versus the number of principal components/latent variables \ell ; note that only two latent variables are required versus four principal components. Figure 4.13 (page 429): Predicted versus measured outputs for the validation dataset. Top: PCR using \textit {four} principal components. Bottom: PLSR using \textit {two} latent variables. Left: first output. Right: second output. Figure 4.14 (page 430): Effect of undermodeling. Top: PCR using \textit {three} principal components. Bottom: PLSR using \textit {one} latent variable. Figure 4.15 (page 433): The indicator (step) function f_1(w;x) and its smooth approximation, f(w;x). Figure 4.16 (page 450): Typical strain versus time data from a molecular dynamics simulation. The data are available on the website \jbrawweb . Figure 4.17 (page 451): Plot of y versus x available on the website \jbrawweb . Figure 4.18 (page 457): Smooth approximation to a unit step function, H(z-1).

## Chapter 5: Stochastic Models and Processes Figure 5.1 (page 467): A simulation of the Wiener process with fixed sample time \Delta t= 10^{-6} and D=5x10^5. Figure 5.2 (page 468): Sampling faster on the last plot in Figure 5.1; the sample time is decreased to \Delta t = 10^{-9} and the roughness is restored on this time scale. Figure 5.3 (page 475): A representative trajectory of the discretely sampled Brownian motion; D=2, V=0, n=500. Figure 5.4 (page 475): The mean square displacement versus time; D=2, V=0, n=500. Figure 5.5 (page 483): Two first-order reactions in series in a batch reactor, c_{A0}=1, c_{B0}=c_{C0}=0, k_1=2, k_2=1. Figure 5.6 (page 485): A sample path of the unit Poisson process. Figure 5.7 (page 485): A unit Poisson process with more events; sample path (top) and frequency distribution of event times \tau . Figure 5.9 (page 492): Stochastic simulation of first-order series reaction A-> B-> C starting with 100 A molecules. Figure 5.11 (page 496): Solution to master equation for A + B <-> C starting with 20 A molecules, 100 B molecules and 0 C molecules, k_1=1/20, k_{-1}=3. Figure 5.12 (page 497): Solution to master equation for A + B <-> C starting with 200 A molecules, 1000 B molecules and 0 C molecules, k_1=1/200, k_{-1}=3. Figure 5.13 (page 499): The equilibrium reaction extent's probability density for Reactions 5.52 at system volume \Omega =20 (top) and \Omega = 200 (bottom). Notice the decrease in variance in the reaction extent as system volume increases. Figure 5.14 (page 503): Simulation of 2 A \mathrel {\mkern 4mu}\mathrel {\smash {\mathchar "392D}}\mathrel {\mkern -2.5mu}-> B for n_0=500, \Omega =500. Top: discrete simulation; bottom: SDE simulation. Figure 5.15 (page 504): Cumulative distribution for 2 A \mathrel {\mkern 4mu}\mathrel {\smash {\mathchar "392D}}\mathrel {\mkern -2.5mu}-> B at t=1 with n_0=500, \Omega =500. Discrete master equation (steps) versus omega expansion (smooth). Figure 5.16 (page 518): The change in 95% confidence intervals for \hat {x}(k\delimiter "026A30C k) versus time for a stable, optimal estimator. We start at k=0 with a large initial variance P(0), which gives a large confidence interval. Figure 5.17 (page 528): Deterministic simulation of reaction A + B <-> C compared to stochastic simulation.