Learn R Programming

DiceView (version 2.2-0)

mesh_roots: Multi Dimensional Multiple Roots (Zero) Finding, sampled by a mesh

Description

Multi Dimensional Multiple Roots (Zero) Finding, sampled by a mesh

Usage

mesh_roots(
  f,
  vectorized = FALSE,
  intervals,
  mesh = "seq",
  mesh.sizes = 11,
  maxerror_f = 1e-07,
  tol = .Machine$double.eps^0.25,
  ...
)

Value

matrix of x, so f(x)=0

Arguments

f

Function (one or more dimensions) to find roots of

vectorized

is f already vectorized ? (default: no)

intervals

bounds to inverse in, each column contains min and max of each dimension

mesh

function or "unif" or "seq" (default) to preform interval partition

mesh.sizes

number of parts for mesh (duplicate for each dimension if using "seq")

maxerror_f

the maximum error on f evaluation (iterates over uniroot to converge).

tol

the desired accuracy (convergence tolerance on f arg).

...

Other args for f

Examples

Run this code
mesh_roots(function(x) x-.51, intervals=rbind(0,1))
mesh_roots(function(x) sum(x)-.51, intervals=cbind(rbind(0,1),rbind(0,1)))
mesh_roots(sin,intervals=c(pi/2,5*pi/2))
mesh_roots(f = function(x) sin(pi*x[1])*sin(pi*x[2]),
           intervals = matrix(c(1/2,5/2,1/2,5/2),nrow=2))

r = mesh_roots(function(x) (0.25+x[1])^2+(0.5+x[2])^2-.25,
               intervals=matrix(c(-1,1,-1,1),nrow=2))
plot(r,xlim=c(-1,1),ylim=c(-1,1))

r = mesh_roots(function(x) (0.5+x[1])^2+(-0.5+x[2])^2+(0.+x[3])^2- .25,
               mesh.sizes = 11,
               intervals=matrix(c(-1,1,-1,1,-1,1),nrow=2))
scatterplot3d::scatterplot3d(r,xlim=c(-1,1),ylim=c(-1,1),zlim=c(-1,1))

mesh_roots(function(x)exp(x)-1,intervals=c(-1,2))
mesh_roots(function(x)exp(1000*x)-1,intervals=c(-1,2))

Run the code above in your browser using DataLab