-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gee. That simple. I knew that! Thanks a lot. Essentially, I needed only the diagonal elements. Easily solved by: diag(outer( X=v1,Y=v2, FUN= fV) I am sure that there are simpler options, but that works like a charm. Thanks a lot. Cheers, Marko On 02/27/2015 06:49 AM, David Winsemius wrote:> >> On Feb 26, 2015, at 1:49 PM, marKo <mtoncic at ffri.hr> wrote: >> >> 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: > > >> f1<-function (X, Y) integrate( function(x) {X*x+Y*x^2}, 0, 1)$value >> fV<-Vectorize(f1) >> outer( X=v1,Y=v2, FUN= fV) > [,1] [,2] [,3] [,4] [,5] > [1,] 0.8333333 1.166667 1.5 1.833333 2.166667 > [2,] 1.3333333 1.666667 2.0 2.333333 2.666667 > [3,] 1.8333333 2.166667 2.5 2.833333 3.166667 > [4,] 2.3333333 2.666667 3.0 3.333333 3.666667 > [5,] 2.8333333 3.166667 3.5 3.833333 4.166667 > > ? > David Winsemius, MD > Alameda, CA, USA >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU8D2hAAoJEJcj4KySkkQsblsQAK2cpOG/qsrXP6vK9Zq3UMkc 6jNQ9PQqvT1H8WyR8rNTY1Bis7npxgNh0avRYOrsRf1D3u9frNjBAhT2v0mMW+Uk LRvHpER1EnIZhdFcmE7uOUNsaU/IquicVVWAXgVVu2/yUW8nJZ4FQ2wkKDLlTY97 dyNMj5i1r5DWBtfUbCtTiSJz1G16DXiJBsk0Zi1Z9zT71evOh2tIfztv1qSSTOLJ gjWbpefYThypPq/170+Eqv3BOigjQd1ljeyXVgGrs/vMTX6a9ZL5KDUYsR7QnhmH ZiHNUTcUpAFb3QGLNVM6ULd7GfzDKgG7rH8JwokYzi/IIsm5aTNfY7dUCGySx+dL 4tOQKe6LjFGIfqPHeZXXs1ErYrIs7L//z+n9ZfHKT0RH7zAoakrzkvFxsBx2LU7z Wziv3/eMN65WOPFpH2puaUQrandbmpDujuZS0PfGBc5/hrIpeCejm7LfHocck6MT v+J4o05+a3jMSdZdtbNXv6q5z+tXaEdThKz77VmFwMQWzFto8QFbe5dOKP9EO6Vn 9+u0gSswtE43PXkn3Egj6HmhrTkREc3lnHsh/0E32+g4UsWxVlyLvfCrm9s4zKOZ fGjIpaUPUp2AkNGAa8BhLqO6LJVaU2/wCvcYIRAbv1Uck2XK9lppKsvFEUuRz9Uk kPaGAS9OJgsUS8kMVpMf =v7j4 -----END PGP SIGNATURE-----
> On Feb 27, 2015, at 4:49 AM, marKo <mtoncic at ffri.hr> wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Gee. That simple. I knew that! > Thanks a lot. > Essentially, I needed only the diagonal elements. > Easily solved by: > > diag(outer( X=v1,Y=v2, FUN= fV) > > I am sure that there are simpler options, but that works like a charm.If I had understood that you wanted only the values with v1 and v2 paired, then I would have suggested using apply:> mapply(fV, v1, v2)[1] 0.8333333 1.6666667 2.5000000 3.3333333 4.1666667 ? David.> > Thanks a lot. > > Cheers, > > Marko > > > > On 02/27/2015 06:49 AM, David Winsemius wrote: >> >>> On Feb 26, 2015, at 1:49 PM, marKo <mtoncic at ffri.hr> wrote: >>> >>> 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: >> >> >>> f1<-function (X, Y) integrate( function(x) {X*x+Y*x^2}, 0, 1)$value >>> fV<-Vectorize(f1) >>> outer( X=v1,Y=v2, FUN= fV) >> [,1] [,2] [,3] [,4] [,5] >> [1,] 0.8333333 1.166667 1.5 1.833333 2.166667 >> [2,] 1.3333333 1.666667 2.0 2.333333 2.666667 >> [3,] 1.8333333 2.166667 2.5 2.833333 3.166667 >> [4,] 2.3333333 2.666667 3.0 3.333333 3.666667 >> [5,] 2.8333333 3.166667 3.5 3.833333 4.166667 >> >> ? >> David Winsemius, MD >> Alameda, CA, USA >> > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1 > > iQIcBAEBAgAGBQJU8D2hAAoJEJcj4KySkkQsblsQAK2cpOG/qsrXP6vK9Zq3UMkc > 6jNQ9PQqvT1H8WyR8rNTY1Bis7npxgNh0avRYOrsRf1D3u9frNjBAhT2v0mMW+Uk > LRvHpER1EnIZhdFcmE7uOUNsaU/IquicVVWAXgVVu2/yUW8nJZ4FQ2wkKDLlTY97 > dyNMj5i1r5DWBtfUbCtTiSJz1G16DXiJBsk0Zi1Z9zT71evOh2tIfztv1qSSTOLJ > gjWbpefYThypPq/170+Eqv3BOigjQd1ljeyXVgGrs/vMTX6a9ZL5KDUYsR7QnhmH > ZiHNUTcUpAFb3QGLNVM6ULd7GfzDKgG7rH8JwokYzi/IIsm5aTNfY7dUCGySx+dL > 4tOQKe6LjFGIfqPHeZXXs1ErYrIs7L//z+n9ZfHKT0RH7zAoakrzkvFxsBx2LU7z > Wziv3/eMN65WOPFpH2puaUQrandbmpDujuZS0PfGBc5/hrIpeCejm7LfHocck6MT > v+J4o05+a3jMSdZdtbNXv6q5z+tXaEdThKz77VmFwMQWzFto8QFbe5dOKP9EO6Vn > 9+u0gSswtE43PXkn3Egj6HmhrTkREc3lnHsh/0E32+g4UsWxVlyLvfCrm9s4zKOZ > fGjIpaUPUp2AkNGAa8BhLqO6LJVaU2/wCvcYIRAbv1Uck2XK9lppKsvFEUuRz9Uk > kPaGAS9OJgsUS8kMVpMf > =v7j4 > -----END PGP SIGNATURE-----David Winsemius, MD Alameda, CA, USA
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Yes. That's it. Thanks, a lot, really. Marko On 02/27/2015 02:46 PM, David Winsemius wrote:> >> On Feb 27, 2015, at 4:49 AM, marKo <mtoncic at ffri.hr> wrote: >> > Gee. That simple. I knew that! Thanks a lot. Essentially, I needed > only the diagonal elements. Easily solved by: > > diag(outer( X=v1,Y=v2, FUN= fV) > > I am sure that there are simpler options, but that works like a > charm. > >> If I had understood that you wanted only the values with v1 and >> v2 paired, then I would have suggested using apply: > > mapply(fV, v1, v2) >> [1] 0.8333333 1.6666667 2.5000000 3.3333333 4.1666667 > >> ? David. > > Thanks a lot. > > Cheers, > > Marko > > > > On 02/27/2015 06:49 AM, David Winsemius wrote: >>>> >>>>> On Feb 26, 2015, at 1:49 PM, marKo <mtoncic at ffri.hr> >>>>> wrote: >>>>> >>>>> 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: >>>> >>>> >>>>> f1<-function (X, Y) integrate( function(x) {X*x+Y*x^2}, 0, >>>>> 1)$value fV<-Vectorize(f1) outer( X=v1,Y=v2, FUN= fV) >>>> [,1] [,2] [,3] [,4] [,5] [1,] 0.8333333 1.166667 >>>> 1.5 1.833333 2.166667 [2,] 1.3333333 1.666667 2.0 2.333333 >>>> 2.666667 [3,] 1.8333333 2.166667 2.5 2.833333 3.166667 [4,] >>>> 2.3333333 2.666667 3.0 3.333333 3.666667 [5,] 2.8333333 >>>> 3.166667 3.5 3.833333 4.166667 >>>> >>>> ? David Winsemius, MD Alameda, CA, USA >>>> > > > David Winsemius, MD Alameda, CA, USA >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU8HXQAAoJEJcj4KySkkQsDMUP/i2vCLuf21yrMIFotBehOcF8 XpN3gRWAvRAe9Thd4mpIzSj+5woQLJH/Rp8bF2ClXh0HaO3j62fn+RGJeKBEDS0g gxqkPFapm0ug6qEIYHvguHVLTMuAEWgzU+fpTY955jAwOYvrkHfWJ9XGqfik7R1o jBfbquq/4kyUqur1iBsHp4RZXkXEUfuk5lLPv03Tl7B6TOift0M/yJf5PAzi0VvY 2jhDpAvSJ6JSjwx+R+xnDkXhkSNMQAoiZuabuwVbD9dqA7T5dxreieAbu+YcUo4E FF96A6G7gfIgneCdX3i/2i632MjTfDTe1eDB5YYATf5GnmzYB1K0ZH6Egr6sB4/7 /0wvObJHWJfc5qZQpqJyk8mEy54Igm/jko75yaQ7EIHWbDEcm30AyC0b0/7qTels w2Tie3T4KvnjfSaPSz65AW7ip8bWYy3QpgNTzpQEn1zNjWSJ3lQYOOvWwFhr67YN axft3nHRpthOUWk5lZgLJ5Nmx0ILB/NxYIh/nj2uUypsYYvvMNqKTg+QRNEICm51 bace0rfvPTl4UaCCrtFtydN7awv8/weRCMqUtSZccxZ9Hvkli6inIWH0WDK9/xg3 HxPgv8BEF9wJtfHa8HWtDEG7pqUT5byhd3UVtxSkH+RYZl9iGu/Vat/a3Ikj+6Lb i9lIjaTylqlAy//m4S/Q =EH2y -----END PGP SIGNATURE-----