-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from owlbarn/first-class-ode
First class ode
- Loading branch information
Showing
24 changed files
with
352 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
(executable | ||
(name van_der_pol) | ||
(libraries ode) | ||
(libraries owl owl-ode-sundials) | ||
(modules van_der_pol) | ||
) | ||
|
||
(executable | ||
(name damped) | ||
(libraries ode) | ||
(libraries owl owl-ode) | ||
(modules damped) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
opam-version: "2.0" | ||
maintainer: "owlbarn" | ||
authors: [ "Marcello Seri" "Ta-Chu Calvin Kao" ] | ||
license: "MIT" | ||
homepage: "https://github.com/owlbarn/owl_sundials" | ||
dev-repo: "git+https://github.com/owlbarn/owl_sundials.git" | ||
bug-reports: "https://github.com/owlbarn/owl_sundials/issues" | ||
doc: "https://owlbarn.github.io/owl_sundials/ode" | ||
build: [ | ||
["dune" "build" "-p" name "-j" jobs] | ||
["dune" "exec" "examples/van_der_pol.exe"] {with-test} | ||
] | ||
depends: [ | ||
"ocaml" {>= "4.02"} | ||
"owl" {>= "0.4.0"} | ||
"dune" {build & >= "1.1.0"} | ||
"owl-ode" (*{>="0.0.4"}*) | ||
"sundialsml" | ||
] | ||
synopsis: "Owl's ODE solvers, interface with SundialsML" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(library | ||
(name owl_ode) | ||
(public_name owl-ode) | ||
(libraries owl) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
open Owl | ||
open Types | ||
|
||
type f_t = Mat.mat -> float -> Mat.mat | ||
|
||
let euler_s ~(f:f_t) ~dt = fun y0 t0 -> | ||
let y = Mat.(y0 + (f y0 t0) *$ dt) in | ||
let t = t0 +. dt in | ||
y, t | ||
|
||
let rk4_s ~(f:f_t) ~dt = fun y0 t0 -> | ||
let k1 = Mat.(dt $* (f y0 t0)) in | ||
let k2 = Mat.(dt $* (f (y0 + k1 *$ 0.5) (t0 +. 0.5 *. dt))) in | ||
let k3 = Mat.(dt $* (f (y0 + k2 *$ 0.5) (t0 +. 0.5 *. dt))) in | ||
let k4 = Mat.(dt $* (f (y0 + k3) (t0 +. dt))) in | ||
let dy = Mat.((k1 + k2 + k3 + k4) /$ 6.) in | ||
let y = Mat.(y0 + dy) in | ||
let t = t0 +. dt in | ||
y, t | ||
|
||
let prepare step f y0 tspec () = | ||
let tspan, dt = match tspec with | ||
| T1 {t0; duration; dt} -> (t0, t0+.duration), dt | ||
| T2 {tspan; dt} -> tspan, dt | ||
| T3 _ -> raise Owl_exception.NOT_IMPLEMENTED | ||
in | ||
let step = step ~f ~dt in | ||
Common.integrate ~step ~tspan ~dt y0 | ||
|
||
|
||
module Euler = struct | ||
type t = Mat.mat | ||
type output = float array * Mat.mat | ||
let solve = prepare euler_s | ||
end | ||
|
||
module RK4 = struct | ||
type t = Mat.mat | ||
type output = float array * Mat.mat | ||
let solve = prepare rk4_s | ||
end |
Oops, something went wrong.