Reputation: 27
log1<-function(x,theta){ #make function with 2 argument
return(-length(x)*log(2*pi)+sum(log(1-cos(x-theta))))
}
g<-grad(func=log1, theta) # But I am getting an error.
Upvotes: 0
Views: 661
Reputation: 88
your function log1
requires two arguments x
and theta
, but you're only passing theta
, with no default for either arguments. Try:
library(numDeriv)
log1<-function(x,theta){ #make function with 2 argument
return(-length(x)*log(2*pi)+sum(log(1-cos(x-theta))))
}
g<-grad(func = log1, x=4, theta=5)
or assign some default values for your variables so that you can do something like this:
log1<-function(x=3,theta=4){ #make function with 2 argument
return(-length(x)*log(2*pi)+sum(log(1-cos(x-theta))))
}
g<-grad(func = log1, x=c(1,2,3))
Upvotes: 1