Since f1(x) requires a call to f(x), there's no way for your approach to work in Julia. You probably should define f1(x) as sqrt(x[1]) and f2(x) as 2 * x[2].
-- John On Wednesday, August 19, 2015 at 2:32:38 PM UTC-7, Nikolay Kryukov wrote: > > I have a problem when I try to separate the components of a > multidimensional function. Example: > > Given the 2D function of a 2D argument: > f(x) = [sqrt(x[1]), 2*x[2]] > > I want to split it into two separate functions which are the components of > the original 2D function. I thought that the obvious solution was: > > f1(x) = f(x)[1] > f2(x) = f(x)[2] > > The second function merely doubles the second component of its argument, > as it should: > f2([2, 3]) > --> 6.0 > > But the functions don't turn out to be completely decoupled: let's see > what happens when we do > > f2([-2, 3]) > --> ERROR: DomainError > in f2 at none:1 > > Even though the second function doesn't do sqrt and doesn't even depend on > the first component of the argument, the first component of the original > function is still checked and obviously returns an error. > > How do I decouple a 2D function? >
