関数uniroot.all()

  • パッケージに "rootSolve"というものがあるらしい
    • こちらのコメントで教えていただいたもの
    • 詳しくは次を実行
vignette("rootSolve")
    • 中身は以下の通り

rootSolve

  • uniroot.all : to solve for all roots of one (nonlinear) equation
  • multiroot : to solve n roots of n (nonlinear) equations
  • steady : for a general interface to most of the steady-state solvers
  • steady.band : to find the steady-state of ODE models with a banded Jacobian
  • steady.1D, steady.2D, steady.3D : steady-state solvers for 1-D, 2-D and 3-D partial differential equations.
  • stode : iterative steady-state solver for ODEs with full or banded Jacobian.
  • stodes : iterative steady-state solver for ODEs with arbitrary sparse Jacobian.
  • runsteady : steady-state solver by dynamically running to steady-state
  • jacobian.full, jacobian.band : estimates the Jacobian matrix assuming a full or banded structure.
  • gradient, hessian : estimates the gradient matrix or the Hessian.
  • まずは1変数について
  • uniroot.all(fun,interval)
    • 1変数の方程式の解を出す
    • 中間値の定理を利用している
    • 中身を見てみると
      • uniroot.all(function,interval,n=100)という構造で、100等分して中間値の定理を使っている
        • そのあとで解を含む(と思われる)区間に対して uniroot 関数を適用している
      • \lim_{x \uparrow a} f(x) =-\infty, \, \lim_{x \downarrow a} f(x)= \infty
      • となるような a も解になってしまうので、f(a)0 に近いかどうかを確認する
    • ついでにヘルプのExampleの解の表示の仕方について
      • curve(f,from,to,n=101)
      • points(x,y)
library(rootSolve)
fun <- function (x) cos(2*x)^3
curve(fun(x),0,10,main="uniroot.all")
All <- uniroot.all(fun,c(0,10))
points(All,y=rep(0,length(All)),pch=16,cex=2,col=2)
    • curve()とは異なるが、spline(x,y,n)でも点を補完して点をかき出してくれる
      • nで点の数を指定、補完してくれる
n <- 10
x <- 1:n
y <- rnorm(n)
plot(x, y, main = paste("spline[fun](.) through", n, "points"))
lines(spline(x, y))
lines(spline(x, y, n = 100), col = 2)