21.04.2015 Views

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

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

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

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

182 CHAPTER 9. DIFFERENTIAL ALGEBRAIC EQUATIONS<br />

In practice it is better not to compute the inverse, but instead to use a linear solver<br />

to compute the update, however, this program is for illustrative purposes and the<br />

inverse is sufficient. Finally, we can implement the solver. Of course we also need<br />

to give values to the parameters α, β, γ.<br />

{A n , B n , X n , e n } = {1, 0, 0, 1};<br />

h = 0.01;<br />

α=10; β=γ=1;<br />

data = {{0, A n , B n , X n , e n }};<br />

For[t = 0, t < 3, t += h,<br />

{A n , B n ,X n , e n } = nextStep[h, {A n , B n , X n , e n }];<br />

data = Append[data, {t+h, A n , B n , X n , e n }];<br />

];<br />

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 }, . . .<br />

at each of the mesh points. To see the data we could type<br />

TableForm[data]<br />

Mathematica would respond with (only some of the data is shown):<br />

0 1 0 0 1<br />

0.01 0.916713 0.0824626 0.000824626 0.917537<br />

0.02 0.84639 0.151273 0.00233735 0.0848727<br />

. etc<br />

To plot all the curves on a single graph using ListPlot we write the function<br />

plotDataTable,<br />

plotDataTable[d ,styles ] := Module[{nvars, makedata, plt, data,<br />

plots},<br />

nvars = Length[d[[1]]] - 1;<br />

data = Transpose[d];<br />

makedata[i ] := {data[[1]], data[[i + 1]]};<br />

plt[i ] := ListPlot[makedata[i]<br />

Transpose, PlotJoined -> True, PlotStyle -> styles[[i]],<br />

DisplayFunction -> Identity];<br />

plots = plt /@ Range[nvars];<br />

Show[plots, DisplayFunction -> $DisplayFunction];<br />

]<br />

<strong>The</strong> to actually generate the plot,<br />

plotDataTable[data,<br />

{{Red, Dashing[{.006, 0.008}]},<br />

{Blue, Thickness[.006], Dashing[{0.01}]},<br />

{Green, Thickness[.005]},<br />

Purple}]<br />

Math 582B, Spring 2007<br />

California State University Northridge<br />

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

Last revised: May 23, 2007

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

Saved successfully!

Ooh no, something went wrong!