I think we can do this using Outer and Vectorize.
sigm = function(a=0,b=0,x){ return(exp(x*a+b)) } sigm1 = Vectorize(function(a=-1:1,b=-1:1,x){ outer(a,b,sigm,x) },SIMPLIFY = FALSE)
Now sigm1 (x = 1: 3) gives the required output
[[1]] [,1] [,2] [,3] [1,] 0.1353353 0.3678794 1.000000 [2,] 0.3678794 1.0000000 2.718282 [3,] 1.0000000 2.7182818 7.389056 [[2]] [,1] [,2] [,3] [1,] 0.04978707 0.1353353 0.3678794 [2,] 0.36787944 1.0000000 2.7182818 [3,] 2.71828183 7.3890561 20.0855369 [[3]] [,1] [,2] [,3] [1,] 0.01831564 0.04978707 0.1353353 [2,] 0.36787944 1.00000000 2.7182818 [3,] 7.38905610 20.08553692 54.5981500
The only rollback using this piece of code is that I use the default values a = -1: 1 and b = -1: 1. When I try to pass the same thing during a function call, it goes haywire. For example.
sigm1(-1:1,-1:1,1:3) [[1]] [,1] [1,] 0.1353353 [[2]] [,1] [1,] 1 [[3]] [,1] [1,] 54.59815
I cannot understand why passing arguments makes this difference in output.