View source: R/cleanEventTimes.R
cleanEventTimes | R Documentation |
These functions can be used for checking time steps and events used by ode solver functions. They are normally called internally within the solvers.
nearestEvent(times, eventtimes)
cleanEventTimes(times, eventtimes, eps = .Machine$double.eps * 10)
times |
the vector of output times, |
eventtimes |
a vector with the event times, |
eps |
relative tolerance value below which two numbers are assumed to be numerically equal. |
In floating point arithmetics, problems can occur if values have to be compared for 'equality' but are only close to each other and not exactly the same.
The utility functions can be used to add all eventtimes
to
the output times
vector, but without including times that are
very close to an event.
This means that all values of eventtimes
are contained
but only the subset of times
that have no close neighbors in
eventtimes
.
These checks are normally performed internally by the integration solvers.
nearestEvent
returns a vector with the closest events for
each time step and
cleanEventTimes
returns a vector with the output times
without all those that are 'very close' to an event.
Thomas Petzoldt
events
events <- sort(c(0, 2, 3, 4 + 1e-10, 5, 7 - 1e-10,
7 + 6e-15, 7.5, 9, 24.9999, 25, 80, 1001, 1e300))
times <- sort(c(0, 1:7, 4.5, 6.75, 7.5, 9.2, 9.0001, 25, 879, 1e3, 1e300+5))
nearest <- nearestEvent(times, events)
data.frame(times=times, nearest = nearest)
## typical usage: include all events in times after removing values that
## are numerically close together, events have priority
times
unique_times <- cleanEventTimes(times, events)
newtimes <- sort(c(unique_times, events))
newtimes
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.