[R] integrate with vector arguments
marKo
mtoncic at ffri.hr
Thu Feb 26 19:49:17 CET 2015
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'm a bit stuck.
I have to integrate a series of polynomial functions with vector
arguments.
v1<-c(1:5)
v2<-c(1:5)
f1<-function (x) {v1*x+v2*x^2}
The problem is that integrate(f1, 0, 1) does not work.
I does not, even if a pas the arguments (v1, v2)
f1<-function (x, v1, v2) {v1*x+v2*x^2}
or if i try to vectorize the function
f1<-Vectorize(function(x, v1, v2){v1*x+v2*x^2},
vectorize.args=c("v1", "v2"))
integrate(f1, 0, 1) gives an error:
Error in integrate(f1, 0, 1) :
evaluation of function gave a result of wrong length
Any help will be greatly appreciated.
Thanks,
Marko
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBAgAGBQJU72qnAAoJEJcj4KySkkQsLAkP/R7DvO0GiZDRrtHgDna/2xj+
XJd8G/gGfe029lVjg+3i6wfKfZ9CoRH+kHEVnT0/SRYcSAeRu3/fys11sjEgVGnl
a/Go167YRYfDkP/OrY4jKtlULySeiGBxNJwKmk1oCidoodk2mejWdPQ61tBj6ozF
sA+Bzoi7Exh2pp88Eks4+Ynz+Toi8Ck1hItV60kP9yOMSBsIPVLw53lGXDfOshzM
zLcFbHM5hyjmt/BQvyaBm3E822YEJgcDQN3nedjQgwThJuEyig2TXHAvyEZcdBWD
H8Py0b5/TBdmxqJQ3EqYyBFmPxeFuhO4ZS22IhP+rqPJ51EZnfqG6DRBHHLqQ9rX
ZnYJN8ryqDVMOrYHn6j3dNd/m7C/YWmrY8gjArv8WxRsX+kX+DAgbRmiw/43BXNG
Y2Jco5dChWBrXQDR3FMoJWBTWjvwgPfP06hnwjrJT1uJZQLPUzhdrIxyHxbhsW0A
UeiRqNiPjE9YpKrFGn9Itg1tXk35yrPrNmmj1nzIzaHejMzT8zf0X2pJAygAYyk3
+mrEgwkB31GOt2mUqqFzDxgDHASaSTPlskviIVJ9klcs7ViWYSy5ARiF4/ptbluE
CTny7dVj/AoXq8dC8TxghOT1QSnPVy7ceb6fCep7LxJDWlFqTEM0LCbL7Ql78yzP
+Em5gaikzPGbJ7uvVKIG
=7J6P
-----END PGP SIGNATURE-----
More information about the R-help
mailing list