Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cleanEventTimes

Find Nearest Event for Each Time Step and Clean Time Steps to Avoid Doubles


Description

These functions can be used for checking time steps and events used by ode solver functions. They are normally called internally within the solvers.

Usage

nearestEvent(times, eventtimes)
cleanEventTimes(times, eventtimes, eps = .Machine$double.eps * 10)

Arguments

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.

Details

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.

Value

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.

Author(s)

Thomas Petzoldt

See Also

Examples

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

deSolve

Solvers for Initial Value Problems of Differential Equations ('ODE', 'DAE', 'DDE')

v1.28
GPL (>= 2)
Authors
Karline Soetaert [aut] (<https://orcid.org/0000-0003-4603-7100>), Thomas Petzoldt [aut, cre] (<https://orcid.org/0000-0002-4951-6468>), R. Woodrow Setzer [aut] (<https://orcid.org/0000-0002-6709-9186>), Peter N. Brown [ctb] (files ddaspk.f, dvode.f, zvode.f), George D. Byrne [ctb] (files dvode.f, zvode.f), Ernst Hairer [ctb] (files radau5.f, radau5a), Alan C. Hindmarsh [ctb] (files ddaspk.f, dlsode.f, dvode.f, zvode.f, opdkmain.f, opdka1.f), Cleve Moler [ctb] (file dlinpck.f), Linda R. Petzold [ctb] (files ddaspk.f, dlsoda.f), Youcef Saad [ctb] (file dsparsk.f), Clement W. Ulrich [ctb] (file ddaspk.f)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.