deeve: Event Detection in ODE solution

View source: R/deval.R

deeveR Documentation

Event Detection in ODE solution

Description

Detect events in solutions of a differential equation.

Usage

deeve(x, y, yv = 0, idx = NULL)

Arguments

x

vector of (time) points at which the differential equation has been solved.

y

values of the function(s) that have been computed for the given (time) points.

yv

point or numeric vector at which the solution is wanted.

idx

index of functions whose vales shall be returned.

Details

Determines when (in x coordinates) the idx-th solution function will take on the value yv.

The interpolation is linear for the moment. For points outside the x interval NA is returned.

Value

A (time) point x0 at which the event happens.

Note

The interpolation is linear only for the moment.

See Also

deval

Examples

##  Damped pendulum:  y'' = -0.3 y' - sin(y)
#   y1 = y, y2 = y':  y1' = y2,  y2' = -0.3*y2 - sin(y1)
f <- function(t, y) {
	dy1 <- y[2]
	dy2 <- -0.3*y[2] - sin(y[1])
	return(c(dy1, dy2))
}
sol <- rk4sys(f, 0, 10, c(pi/2, 0), 100)
deeve(sol$x, sol$y[,1])                   # y1 = 0 : elongation in [sec]
# [1] 2.073507 5.414753 8.650250
# matplot(sol$x, sol$y); grid()

pracma documentation built on March 19, 2024, 3:05 a.m.