Description Usage Arguments Details Value Author(s) References Examples
This function provides the corresponding index position on the specified grid.
1 | get_i(x, domain, N_discr)
|
domain |
Vector of type double - Vector with two components containing the bounds of the discretized interval |
N_discr |
integer - discretization of the interval bounded by domain |
X |
Double - Continuous value, to be identified on specified grid. |
This routine is implemented in C++. Note that a (continuous) value between two grid points condenses two its right grid point
Integer - The index position on the specified grid belonging to the continuous value x or -1 if input values are not adequate
P.v.W. Crommelin
S. Sprott, Chaos and Time-series analysis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // C++ C++ DEFINITION
double get_i(double x, Rcpp::NumericVector domain, int N_discr){
if(N_discr>1.0 & domain[1]>domain[0] & x<=domain[1] & x>=domain[0]){
double dx = (domain[1]-domain[0])/(N_discr-1.0);
double minDiff = domain[1]-domain[0];
int i = 0;
double diff = abs(i*dx-x);
while(diff <= minDiff){
minDiff = diff;
diff = abs(++i*dx - x);
}
return(i);
}else{
return(-1);
std::printf("Input parameters not adequately chosen. See help(get_i) for more information");
}
}
/*** R
#R code example
N_discr = 10 # Discretization of grid
lower = 0
upper = 1
domain = c(lower,upper)
dx = (domain[2]-domain[1])/(N_discr-1)
X = seq(0,1,dx) # grid (for comparism)
X2 = seq(0,1,dx/2) # test values to be indexed, note: step size is dx/2
(df = data.frame(TestValues = X2, CorrespondingIndexPositionsOnGrid = sapply(X2,function(x) get_i(x,domain,N_discr))))
*/
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.