Skip to content

Commit

Permalink
Fix eqns
Browse files Browse the repository at this point in the history
  • Loading branch information
rreusser committed Jul 25, 2015
1 parent b00f819 commit 358af21
Show file tree
Hide file tree
Showing 34 changed files with 28 additions and 12 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@

## Introduction

This module integrates a system of ordinary differential equations of the form <p align="center"><img alt="undefined" valign="middle" src="images/yt-ft-yt-fae25965d3.png" width="151.5" height="25"></p> <p align="center"><img alt="undefined" valign="middle" src="images/yt_0-y_0-42d14f447f.png" width="91.5" height="24"></p> where <img alt="undefined" valign="middle" src="images/y-adb83ba1d7.png" width="14.5" height="16.5"> is a vector of length <img alt="undefined" valign="middle" src="images/n-66e1b1ee17.png" width="16" height="13">. Given time step <img alt="undefined" valign="middle" src="images/delta-t-9813ae7971.png" width="28" height="18">, the Runge-Kutta 4 method integrates the ODE with update <p align="center"><img alt="undefined" valign="middle" src="images/y_n1-fracdelta-t6leftk_1-2k_2-2k_3-k_4right-58f49ef625.png" width="289" height="45"></p> <p align="center"><img alt="undefined" valign="middle" src="images/t_n1-t_n-delta-t-a6feda606a.png" width="135" height="22.5"></p> where <img alt="undefined" valign="middle" src="images/k_n-bcd1333065.png" width="25.5" height="21"> are given by <p align="center"><img alt="undefined" valign="middle" src="images/k_1-ft_n-y_n-9aa4e00ef0.png" width="130.5" height="24"></p> <p align="center"><img alt="undefined" valign="middle" src="images/k_2-ft_n-fracdelta-t2-y_n-fracdelta-t2-k_1-d1c9d16d54.png" width="255.5" height="45"></p> <p align="center"><img alt="undefined" valign="middle" src="images/k_3-ft_n-fracdelta-t2-y_n-fracdelta-t2-k_2-605f389527.png" width="255.5" height="45"></p> <p align="center"><img alt="undefined" valign="middle" src="images/k_4-ft_n-delta-t-y_n-delta-tk_3-8ee3750675.png" width="246" height="24"></p>
This module integrates a system of ordinary differential equations of the form

<p align="center"><img alt="&bsol;begin&lcub;eqnarray&midast;&rcub; y&apos;&lpar;t&rpar; &amp;&equals;&amp; f&lpar;t&comma; y&lpar;t&rpar;&rpar;&comma; &bsol;&bsol; y&lpar;t&lowbar;0&rpar; &amp;&equals;&amp; y&lowbar;0 &bsol;end&lcub;eqnarray&midast;&rcub;" valign="middle" src="docs/images/begineqnarray-yt-ft-yt-yt_0-y_0-endeqnarray-0298eae3db.png" width="187" height="61"></p>

where <img alt="y" valign="middle" src="docs/images/y-720f311276.png" width="14.5" height="20"> is a vector of length <img alt="n" valign="middle" src="docs/images/n-9baedbc330.png" width="16" height="16">. Given time step <img alt="&bsol;Delta t" valign="middle" src="docs/images/delta-t-a20a5fe4f2.png" width="28" height="16">, the Runge-Kutta 4 method integrates the ODE with update

<p align="center"><img alt="&bsol;begin&lcub;eqnarray&midast;&rcub; y&lowbar;&lcub;n&plus;1&rcub; &amp;&equals;&amp; &bsol;frac&lcub;&bsol;Delta t&rcub;&lcub;6&rcub;&bsol;left&lpar;k&lowbar;1 &plus; 2k&lowbar;2 &plus; 2k&lowbar;3 &plus; k&lowbar;4&bsol;right&rpar; &bsol;&bsol; t&lowbar;&lcub;n&plus;1&rcub; &amp;&equals;&amp; t&lowbar;n &plus; &bsol;Delta t &bsol;end&lcub;eqnarray&midast;&rcub;" valign="middle" src="docs/images/begineqnarray-y_n1-fracdelta-t6leftk_1-2k_2-2-41157480a7.png" width="321.5" height="71"></p>
where <img alt="k&lowbar;n" valign="middle" src="docs/images/k_n-d413726dee.png" width="25.5" height="19"> are given by
<p align="center"><img alt="&bsol;begin&lcub;eqnarray&midast;&rcub; k&lowbar;1 &amp;&equals;&amp; f&lpar;t&lowbar;n&comma; y&lowbar;n&rpar;&comma; &bsol;&bsol; k&lowbar;2 &amp;&equals;&amp; f&lpar;t&lowbar;n &plus; &bsol;frac&lcub;&bsol;Delta t&rcub;&lcub;2&rcub;&comma; y&lowbar;n &plus; &bsol;frac&lcub;&bsol;Delta t&rcub;&lcub;2&rcub; k&lowbar;1&rpar;&comma; &bsol;&bsol; k&lowbar;3 &amp;&equals;&amp; f&lpar;t&lowbar;n &plus; &bsol;frac&lcub;&bsol;Delta t&rcub;&lcub;2&rcub;&comma; y&lowbar;n &plus; &bsol;frac&lcub;&bsol;Delta t&rcub;&lcub;2&rcub; k&lowbar;2&rpar;&comma; &bsol;&bsol; k&lowbar;4 &amp;&equals;&amp; f&lpar;t&lowbar;n &plus; &bsol;Delta t&comma; y&lowbar;n &plus; &bsol;Delta tk&lowbar;3&rpar;&period; &bsol;end&lcub;eqnarray&midast;&rcub;" valign="middle" src="docs/images/begineqnarray-k_1-ft_n-y_n-k_2-ft_n-fracdelta-35d808c6ef.png" width="288" height="156.5"></p>

## Install

Expand Down Expand Up @@ -45,8 +53,8 @@ integrator.steps(n)
**Arguments:**
- `y0`: an array or typed array containing initial conditions. This vector is updated in-place with each integrator step.
- `deriv`: a function that calculates the derivative. Format is `function( dydt, y, t )`. Inputs are current state `y` and current time `t`, output is calcualted derivative `dydt`.
- `t0`: initial time <img alt="undefined" valign="middle" src="images/t-3f19307093.png" width="11.5" height="16.5">.
- `dt`: time step <img alt="undefined" valign="middle" src="images/delta-t-9813ae7971.png" width="28" height="18">.
- `t0`: initial time <img alt="t" valign="middle" src="docs/images/t-fc93da6f4d.png" width="11.5" height="16">.
- `dt`: time step <img alt="&bsol;Delta t" valign="middle" src="docs/images/delta-t-a20a5fe4f2.png" width="28" height="16">.

**Returns**:
Initialized integrator object.
Expand All @@ -56,12 +64,12 @@ Initialized integrator object.
- `y`: current state. Initialized as a shallow copy of input `y0`.
- `deriv`: function that calcualtes derivative. Initialized from input. May be changed.
- `t`: current time, incremented by `dt` with each time step.
- `dt`: time step <img alt="undefined" valign="middle" src="images/delta-t-9813ae7971.png" width="28" height="18">. Initialized from input `dt`. May be changed.
- `dt`: time step <img alt="&bsol;Delta t" valign="middle" src="docs/images/delta-t-a20a5fe4f2.png" width="28" height="16">. Initialized from input `dt`. May be changed.

**Methods:**
- `.step()`: takes a single step of the RK-4 integrator and stores the result in-place in the `y` property.
- `.steps( n )`: takes `n` steps of the RK-4 integrator, storing the result in-place in the `y` property.

## Credits

(c) 2015 Ricky Reusser. MIT License
(c) 2015 Ricky Reusser. MIT License
10 changes: 9 additions & 1 deletion README.mdtex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@

## Introduction

This module integrates a system of ordinary differential equations of the form $$ y'(t) &=& f(t, y(t)),$$ $$y(t_0) = y_0$$ where $y$ is a vector of length $n$. Given time step $\Delta t$, the Runge-Kutta 4 method integrates the ODE with update $$y_{n+1} = \frac{\Delta t}{6}\left(k_1 + 2k_2 + 2k_3 + k_4\right)$$ $$t_{n+1} = t_n + \Delta t$$ where $k_n$ are given by $$k_1 = f(t_n, y_n),$$ $$k_2 = f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} k_1),$$ $$k_3 = f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} k_2),$$ $$k_4 = f(t_n + \Delta t, y_n + \Delta tk_3).$$
This module integrates a system of ordinary differential equations of the form

$$[plain=true] \begin{eqnarray*} y'(t) &=& f(t, y(t)), \\ y(t_0) &=& y_0 \end{eqnarray*} $$

where $y$ is a vector of length $n$. Given time step $\Delta t$, the Runge-Kutta 4 method integrates the ODE with update

$$[plain=true] \begin{eqnarray*} y_{n+1} &=& \frac{\Delta t}{6}\left(k_1 + 2k_2 + 2k_3 + k_4\right) \\ t_{n+1} &=& t_n + \Delta t \end{eqnarray*}$$
where $k_n$ are given by
$$[plain=true] \begin{eqnarray*} k_1 &=& f(t_n, y_n), \\ k_2 &=& f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} k_1), \\ k_3 &=& f(t_n + \frac{\Delta t}{2}, y_n + \frac{\Delta t}{2} k_2), \\ k_4 &=& f(t_n + \Delta t, y_n + \Delta tk_3). \end{eqnarray*}$$

## Install

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/delta-t-a20a5fe4f2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/k_n-d413726dee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/n-9baedbc330.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/t-fc93da6f4d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/y-720f311276.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ gulp.task('mdtex',function() {

var transform = mdEqs({
defaults: {
display: { margin: '1pt' },
inline: { margin: '1pt' }
display: { margin: '1pt 1pt 1pt -10pt' },
inline: { margin: '1pt 1pt 1pt -5pt' }
}
})

return gulp.src('*.mdtex')
.pipe(transform)
.pipe(texFilter)
//.pipe(tap(function(file) { console.log(file.contents.toString()) }))
.pipe(tap(function(file) { console.log(file.contents.toString()) }))
.pipe(latex())
.pipe(pdftocairo({format: 'png'}))
.pipe(gulp.dest('images'))
.pipe(gulp.dest('docs/images'))
.pipe(tap(function(file) {
transform.completeSync(file,function() {
var img = '<img alt="'+this.alt+'" valign="middle" src="'+this.path+
'" width="'+this.width/2+'" height="'+this.height/2+'">'
return this.display ? '<p align="center">'+img+'</p>' : img
return this.inline ? img : '<p align="center">'+img+'</p>'
})
}))
.pipe(texFilter.restore()).pipe(mdFilter)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file removed images/delta-t-9813ae7971.png
Binary file not shown.
Binary file removed images/k_1-ft_n-y_n-9aa4e00ef0.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed images/k_n-bcd1333065.png
Binary file not shown.
Binary file removed images/n-66e1b1ee17.png
Binary file not shown.
Binary file removed images/t-3f19307093.png
Binary file not shown.
Binary file removed images/t_n1-t_n-delta-t-a6feda606a.png
Binary file not shown.
Binary file removed images/y-adb83ba1d7.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed images/y_n1-y_n-ft_n-y_n-a622b96922.png
Binary file not shown.
Binary file removed images/y_n1-y_n-ft_n-y_n-delta-t-7e1ddc48e6.png
Binary file not shown.
Binary file removed images/yt-ft-yt-4304a0aa5e.png
Binary file not shown.
Binary file removed images/yt-ft-yt-fae25965d3.png
Diff not rendered.
Binary file removed images/yt-ft-yt-yt_0-y_0-309707f928.png
Diff not rendered.
Binary file removed images/yt-ft-yt-yt_0-y_0-f7515619c6.png
Diff not rendered.
Binary file removed images/yt_0-y_0-42d14f447f.png
Diff not rendered.
Binary file removed images/yt_0-y_0-d7b398c658.png
Diff not rendered.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"chai": "^3.0.0",
"gulp-filter": "^2.0.2",
"gulp-latex": "^1.0.1",
"gulp-markdown-equations": "^1.2.0",
"gulp-markdown-equations": "^1.2.3",
"gulp-pdftocairo": "^0.2.0",
"gulp-tap": "^0.1.3",
"mocha": "^2.2.5"
Expand Down

0 comments on commit 358af21

Please sign in to comment.