Skip to content

Commit ecdae8e

Browse files
add constructor to README
1 parent 659e4ef commit ecdae8e

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

README.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,56 @@ the speed of computations. If they don't exist, the solvers will ignore them. Si
2828
`ParameterizedFunction` is a subtype of `Function`, these can be used anywhere that
2929
a function can be used, just with the extra functionality ignored.
3030

31-
## Basic Usage via Macros
31+
## Basic Usage
3232

33-
### ODEs
33+
### ParameterizedFunction Constructor
3434

35-
A helper macro is provided to make it easier to define a `ParameterizedFunction`.
36-
For example, to define the previous `LotkaVolterra`, you can use the following command:
35+
The easiest way to make a `ParameterizedFunction` is to use the constructor:
36+
37+
```julia
38+
pf = ParameterizedFunction(f,params)
39+
```
40+
41+
The form for `f` is `f(t,u,params,du)`
42+
where `params` is any type which defines the parameters. The
43+
resulting `ParameterizedFunction` has the function call `pf(t,u,params,du)`
44+
which matches the original function, and a call `pf(t,u,du)` which uses internal
45+
parmaeters which can be used with a differential equation solver. Note that the
46+
internal parameters can be modified at any time via the field: `pf.p = ...`.
47+
48+
An additional version exists for `f(t,u,params)` which will then act as the
49+
not inplace version `f(t,u)` in the differential equation solvers.
50+
51+
#### Example
52+
53+
```julia
54+
pf_func = function (t,u,p,du)
55+
du[1] = p[1] * u[1] - p[2] * u[1]*u[2]
56+
du[2] = -3 * u[2] + u[1]*u[2]
57+
end
58+
59+
pf = ParameterizedFunction(pf_func,[1.5,1.0])
60+
```
61+
62+
And now `pf` can be used in the differential equation solvers and the ecosystem
63+
functionality which requires explicit parameters (parameter estimation, etc.).
64+
65+
Note that the not inplace version works the same:
66+
67+
```julia
68+
pf_func2 = function (t,u,p)
69+
[p[1] * u[1] - p[2] * u[1]*u[2];-3 * u[2] + u[1]*u[2]]
70+
end
71+
72+
pf2 = ParameterizedFunction(pf_func2,[1.5,1.0])
73+
```
74+
75+
### ODE Macros
76+
77+
A helper macro is provided to make it easier to define a `ParameterizedFunction`,
78+
and it will symbolically compute a bunch of extra functions to make the differential
79+
equation solvers run faster. For example, to define the previous `LotkaVolterra`,
80+
you can use the following command:
3781

3882
```julia
3983
f = @ode_def LotkaVolterra begin
@@ -194,11 +238,9 @@ way when a function (usually an ODE/SDE solver) is dispatched on `f`. It is
194238
requested that solvers should only use the explicit functions when they exist
195239
to help with performance.
196240

197-
## Manually Defining `ParameterizedFunction`s
241+
## Internals: How it Works
198242

199-
It's recommended that for simple uses you use the macros. However, in many cases
200-
the macros will not suffice, but you may still wish to provide Jacobians to the
201-
solvers. This shows how to manually build a ParameterizedFunction to give to
243+
This shows how to manually build a ParameterizedFunction to give to
202244
a solver.
203245

204246
### Template

0 commit comments

Comments
 (0)