On Feb 3, 3:39 am, "Suranita " <kanji...@geophysik.uni-frankfurt.de> wrote: > Hi, > Yes but if you calculate z(3,4,2) manually then you'll have answer as 0.8671875 which is not same as the computed result obtained from function handle and that was the reason why I said it didn't work. Because for me also it was not giving the same result as with the one obtained by manual computation and so finally I was not getting the result I expect :(.
If you get a different answer, it's most likely because the value of i is different from the one used in the evaluation above. You've got a hint earlier in this thread about what might be wrong -- the value of i seen by s2 is the one i had at the time s2 was defined, not the one i might have at the time s2 is called:
i = 0; foo = @() i;
foo() % 0
i = 1; foo() % 0
If i in your formula for s2 is supposed to be fixed (you do want it to be a constant throughout all calls), then you may want to use that constant value to avoid confusion. However, if you expect i to be different from call to call, you need to include it in the function's parameters. As you can see above, the approach of setting i externally to s2 does not work. Try redefining s2 (and possibly z) as