The Computable Differential Equation Lecture ... - Bruce E. Shapiro

The Computable Differential Equation Lecture ... - Bruce E. Shapiro The Computable Differential Equation Lecture ... - Bruce E. Shapiro

bruce.shapiro.com
from bruce.shapiro.com More from this publisher
21.04.2015 Views

182 CHAPTER 9. DIFFERENTIAL ALGEBRAIC EQUATIONS In practice it is better not to compute the inverse, but instead to use a linear solver to compute the update, however, this program is for illustrative purposes and the inverse is sufficient. Finally, we can implement the solver. Of course we also need to give values to the parameters α, β, γ. {A n , B n , X n , e n } = {1, 0, 0, 1}; h = 0.01; α=10; β=γ=1; data = {{0, A n , B n , X n , e n }}; For[t = 0, t < 3, t += h, {A n , B n ,X n , e n } = nextStep[h, {A n , B n , X n , e n }]; data = Append[data, {t+h, A n , B n , X n , e n }]; ]; This will generate a table of values of ordered sets of values {{t 0 , A 0 , B 0 , X 0 , e 0 }, {t 1 , A 1 , B 1 , X 1 , e 1 }, . . . at each of the mesh points. To see the data we could type TableForm[data] Mathematica would respond with (only some of the data is shown): 0 1 0 0 1 0.01 0.916713 0.0824626 0.000824626 0.917537 0.02 0.84639 0.151273 0.00233735 0.0848727 . etc To plot all the curves on a single graph using ListPlot we write the function plotDataTable, plotDataTable[d ,styles ] := Module[{nvars, makedata, plt, data, plots}, nvars = Length[d[[1]]] - 1; data = Transpose[d]; makedata[i ] := {data[[1]], data[[i + 1]]}; plt[i ] := ListPlot[makedata[i] Transpose, PlotJoined -> True, PlotStyle -> styles[[i]], DisplayFunction -> Identity]; plots = plt /@ Range[nvars]; Show[plots, DisplayFunction -> $DisplayFunction]; ] The to actually generate the plot, plotDataTable[data, {{Red, Dashing[{.006, 0.008}]}, {Blue, Thickness[.006], Dashing[{0.01}]}, {Green, Thickness[.005]}, Purple}] Math 582B, Spring 2007 California State University Northridge c○2007, B.E.Shapiro Last revised: May 23, 2007

CHAPTER 9. DIFFERENTIAL ALGEBRAIC EQUATIONS 183 Each curve will be plotted in its own style: the first column of data (A) as a thin, dashed, red line; the second (B) as a thick blue dashed line; the third (X) as a thick green line; and the forth (e) as a thin purple line: The figure shows how all of the substrate (A, thin, red, dashed curve) is eventually converted to the product (B, thick green). The concentration of enzyme dips, and the concentration of intermediate (X, thick blue dashes) while the conversion is taking place, but as the process reaches completion they return to their steady state values. Unfortunately, the simple process of writing 0 = F ( t n , y n , y ) n − y n−1 h (9.164) (or using any other discretization method besides backwards Euler) does not always work. For some equations, it is even possible to find any discretization formula at all. Consider, for example, the index-2 differential-algebraic equation The exact solution is x ′ − ty ′ = 0 (9.165) x − ty = f(t) (9.166) x = f(t) − tf ′ (t) (9.167) y = −f ′ (t) (9.168) which may be verified by substitution. Backward Euler gives the formulas x n − x n−1 h − t n y n − y n−1 h = 0 (9.169) x n − t n y n = f(t n ) (9.170) c○2007, B.E.Shapiro Last revised: May 23, 2007 Math 582B, Spring 2007 California State University Northridge

CHAPTER 9. DIFFERENTIAL ALGEBRAIC EQUATIONS 183<br />

Each curve will be plotted in its own style: the first column of data (A) as a thin,<br />

dashed, red line; the second (B) as a thick blue dashed line; the third (X) as a thick<br />

green line; and the forth (e) as a thin purple line:<br />

<strong>The</strong> figure shows how all of the substrate (A, thin, red, dashed curve) is eventually<br />

converted to the product (B, thick green). <strong>The</strong> concentration of enzyme dips, and<br />

the concentration of intermediate (X, thick blue dashes) while the conversion is<br />

taking place, but as the process reaches completion they return to their steady state<br />

values.<br />

Unfortunately, the simple process of writing<br />

0 = F<br />

(<br />

t n , y n , y )<br />

n − y n−1<br />

h<br />

(9.164)<br />

(or using any other discretization method besides backwards Euler) does not always<br />

work. For some equations, it is even possible to find any discretization formula at<br />

all. Consider, for example, the index-2 differential-algebraic equation<br />

<strong>The</strong> exact solution is<br />

x ′ − ty ′ = 0 (9.165)<br />

x − ty = f(t) (9.166)<br />

x = f(t) − tf ′ (t) (9.167)<br />

y = −f ′ (t) (9.168)<br />

which may be verified by substitution. Backward Euler gives the formulas<br />

x n − x n−1<br />

h<br />

− t n<br />

y n − y n−1<br />

h<br />

= 0 (9.169)<br />

x n − t n y n = f(t n ) (9.170)<br />

c○2007, B.E.<strong>Shapiro</strong><br />

Last revised: May 23, 2007<br />

Math 582B, Spring 2007<br />

California State University Northridge

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!