I am trying to apply multivariate Newton-Raphson method using R language. However I have encountered some difficulties to define functions which includes the integral in the equations. For instance, the general form of the equations look like below.
\begin{align}
F_{a}(a,b) = \int_{\text{all}}f(z;a,b)dz – a &= 0, \\
F_{b}(a,b) = \int_{\text{all}}g(z;a,b)dz – b &= 0.
\end{align}
The R code that I applied is written on the bottom.
integrand_f <- function(z) { some function f(z;a,b) }
integrand_g <- function(z) { some function g(z;a,b) }
F_a <- function(a,b) { integrate(integrand_f,-Inf,Inf)$value - a }
F_b <- function(a,b) { integrate(integrand_g,-Inf,Inf)$value - b }
Apparently, when I substitute initial values $(a_{0},b_{0})$ in both $F_{a}$ and $F_{b}$, the output that I get is $-a_{0}$ and $-b_{0}$, respectively. In other words, the integral parts of both functions do not give a meaningful output but zero. How should I fix this problem?
NEW ATTEMPT
Apparently, if I apply Vectorize
function:
F_a <- Vectorize(function(a,b) { integrate(integrand_f,-Inf,Inf)$value - a })
I get some non-trivial value. Perhaps could this be a correct way to compute?
Best Answer
pp.13-16 here discuss a library function that does what you need to use Newton-Raphson, the
multiroot
function in therootSolve
package. The compulsory arguments ofmultiroot
are a functionf
, which for your purposes will send a 2D vector to a 2D vector, and an initial value for its argument so you can begin the iteration. The real challenge is creating the functionf
, whose first and second components should be the values ofF_a
andF_b
. So you want something like: