Skip to contents

Optimize over array using line search

Usage

full_index_line_search(
  f,
  xarray,
  startind,
  plot = "none",
  ystart = NULL,
  verbose = 0
)

Arguments

f

Function

xarray

Array of values

startind

Starting index

plot

Should plots be made?

ystart

Value of f when evaluated on element of xarray at index startind, aka f(xarray[startind])

verbose

Level of info to print

Value

List

Examples

full_index_line_search(function(x) {(x-50)^2}, 3:12, 5)
#> $ind
#> [1] 9
#> 
#> $x
#> [1] 11
#> 
#> $val
#> [1] 1521
#> 
full_index_line_search(function(x) {(x-50)^2}, 3, 1)
#> $ind
#> [1] 1
#> 
#> $x
#> [1] 3
#> 
#> $val
#> [1] 2209
#> 
full_index_line_search(function(x) {(x-50)^2}, 3:4, 1)
#> $ind
#> [1] 2
#> 
#> $x
#> [1] 4
#> 
#> $val
#> [1] 2116
#> 
full_index_line_search(function(x) {(x-50)^2}, 3:5, 1)
#> $ind
#> [1] 3
#> 
#> $x
#> [1] 5
#> 
#> $val
#> [1] 2025
#> 
full_index_line_search(function(x) {(x+50)^2}, 3, 1)
#> $ind
#> [1] 1
#> 
#> $x
#> [1] 3
#> 
#> $val
#> [1] 2809
#> 
full_index_line_search(function(x) {(x+50)^2}, 3:4, 1)
#> $ind
#> [1] 1
#> 
#> $x
#> [1] 3
#> 
#> $val
#> [1] 2809
#> 
full_index_line_search(function(x) {(x+50)^2}, 3:5, 1)
#> $ind
#> [1] 1
#> 
#> $x
#> [1] 3
#> 
#> $val
#> [1] 2809
#> 
full_index_line_search(function(x) {(x-50)^2}, 12:3, 8)
#> $ind
#> [1] 2
#> 
#> $x
#> [1] 11
#> 
#> $val
#> [1] 1521
#> 
full_index_line_search(function(x) {(x-50)^2}, 0:1000, 8)
#> $ind
#> [1] 51
#> 
#> $x
#> [1] 50
#> 
#> $val
#> [1] 0
#> 
full_index_line_search(function(x) {(x-50)^2}, 0:1000, 999)
#> $ind
#> [1] 51
#> 
#> $x
#> [1] 50
#> 
#> $val
#> [1] 0
#> 
full_index_line_search(function(x) {sin(x/30)}, 0:1000, 999)
#> $ind
#> [1] 1001
#> 
#> $x
#> [1] 1000
#> 
#> $val
#> [1] 0.9405296
#>