| 1 |
\name{cleanEventTimes} |
| 2 |
\alias{cleanEventTimes} |
| 3 |
\alias{nearestEvent} |
| 4 |
|
| 5 |
\title{ |
| 6 |
Find Nearest Event for Each Time Step and Clean Time Steps to Avoid Doubles |
| 7 |
} |
| 8 |
\description{ |
| 9 |
These functions can be used for checking time steps and events used by |
| 10 |
ode solver functions. They are normally called internally within the solvers. |
| 11 |
} |
| 12 |
\usage{ |
| 13 |
nearestEvent(times, eventtimes) |
| 14 |
cleanEventTimes(times, eventtimes, eps = .Machine$double.eps * 10) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{times}{the vector of output times,} |
| 18 |
\item{eventtimes}{a vector with the event times,} |
| 19 |
\item{eps}{relative tolerance value below which two numbers are assumed |
| 20 |
to be numerically equal.} |
| 21 |
} |
| 22 |
\details{ |
| 23 |
In floating point arithmetics, problems can occur if values have to be |
| 24 |
compared for 'equality' but are only close to each other and not exactly |
| 25 |
the same. |
| 26 |
|
| 27 |
The utility functions can be used to add all \code{eventtimes} to |
| 28 |
the output \code{times} vector, but without including times that are |
| 29 |
very close to an event. |
| 30 |
|
| 31 |
This means that all values of \code{eventtimes} are contained |
| 32 |
but only the subset of \code{times} that have no close neighbors in |
| 33 |
\code{eventtimes}. |
| 34 |
|
| 35 |
These checks are normally performed internally by the integration solvers. |
| 36 |
} |
| 37 |
\value{ |
| 38 |
\code{nearestEvent} returns a vector with the closest events for |
| 39 |
each time step and |
| 40 |
|
| 41 |
\code{cleanEventTimes} returns a vector with the output times |
| 42 |
without all those that are 'very close' to an event. |
| 43 |
} |
| 44 |
|
| 45 |
\author{ |
| 46 |
Thomas Petzoldt |
| 47 |
} |
| 48 |
|
| 49 |
\seealso{ |
| 50 |
\code{\link{events}} |
| 51 |
} |
| 52 |
|
| 53 |
\examples{ |
| 54 |
|
| 55 |
events <- sort(c(0, 2, 3, 4 + 1e-10, 5, 7 - 1e-10, |
| 56 |
7 + 6e-15, 7.5, 9, 24.9999, 25, 80, 1001, 1e300)) |
| 57 |
times <- sort(c(0, 1:7, 4.5, 6.75, 7.5, 9.2, 9.0001, 25, 879, 1e3, 1e300+5)) |
| 58 |
|
| 59 |
nearest <- nearestEvent(times, events) |
| 60 |
data.frame(times=times, nearest = nearest) |
| 61 |
|
| 62 |
## typical usage: include all events in times after removing values that |
| 63 |
## are numerically close together, events have priority |
| 64 |
times |
| 65 |
unique_times <- cleanEventTimes(times, events) |
| 66 |
newtimes <- sort(c(unique_times, events)) |
| 67 |
newtimes |
| 68 |
} |
| 69 |
\keyword{ misc } |