First, why do you want the jacobian? Assuming you have a good reason for wanting jacobian, Is this want you want to do?
require(numDeriv) func2 <- function(z) { x <- z[1] y <- z[2] c(sin(x*y), cos(x^2*y)) } x <- seq(0, 1, length=5) *2*pi y <- seq(0, 1, length=5) *2*pi z <- cbind(x, y) jac <- vector("list") for (i in 1:nrow(z)) { jac[[i]] <- jacobian(func=func2, x=z[i, ]) } jac Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Roslina Zakaria Sent: Monday, April 13, 2009 9:48 PM To: r-help@r-project.org; r-help-boun...@r-project.org Subject: [R] Jacobian Hi R-users, I would like to use jacobian function from numDeriv package. If I have more than one parameters how do I modify it? This is the example given in the package: func2 <- function(x) c(sin(x), cos(x)) x <- (0:1)*2*pi jacobian(func2, x) Can I do the following: z <- c(x,y) func2 <- function(z) c(sin(xy), cos(x^2*y)) x <- (0:1)*2*pi y <- (0:1)*2*pi jacobian(func2, z) output: > jacobian(func2, z) Error in func(x, ...) : object "xy" not found Thank you so much for any help given. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.