Description Usage Arguments Value Examples
Given f(x) = y
where f
is a monotonic function, find x
for a given y
.
Use a naive iterative approach dividing and mulitplying steps by 2 until a solution is found within desired precision.
Non-monotic functions are supported when the search range is limited to a monotonic subset of the function's range.
WARNING: This algorithm is naive, i.e. performance-wise suboptimal.
1 2 3 4 |
f |
A function receiving a numeric value as its first parameter followed by ... |
y_target_value |
The output of |
x_first_guess |
(Conditional) An initial best-effort first guess of what |
x_first_step |
(Conditional) An initial step length to find better better values. |
x_search_limit_min |
(Conditional) A strict limit below which |
x_search_limit_max |
(Conditional) A strict limit above which |
y_precision |
(Conditional) An acceptable degree of precision. Default: .01. |
max_iteration |
(Conditional) The maximum number of search loops performed by the function. This is a safeguard to avoid infinite loops. Default: 2048. |
verbosity |
(Conditional) When |
Numeric vector. x
such that f(x) = y_target_value
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | precision <- .0001
y_target <- runif(n = 1, min = -1000000, max = +1000000)
c <- runif(n = 1, min = -1000000, max = +1000000)
m <- runif(n = 1, min = -1000000, max = +1000000)
f <- function(x) { return(c + m * x) }
x_found <- find_function_1param_value_divideby2(
f = f,
y_target_value = y_target,
y_precision = precision,
verbosity = verbosity)
y_found <- f(x_found)
delta <- abs(y_target - y_found)
label <- paste0(
"f(x): c + m * x",
"\nc: ", fn(c,8),
"\nm: ", fn(m,8),
"\ny_target: ", fn(y_target,8),
"\nx_found: ", fn(x_found,8),
"\ny_found: ", fn(y_found,8),
"\ndelta: ", fn(delta,8))
message(label)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.