Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to sum up array of function handles
Replies: 10   Last Post: Feb 8, 2011 7:25 AM

 Messages: [ Previous | Next ]
 waku Posts: 14 Registered: 1/27/11
Re: how to sum up array of function handles
Posted: Feb 3, 2011 10:01 AM

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

s2 = @(n, f, phi0, i) ...

and see what happens.

vQ

Date Subject Author
2/2/11 Suranita
2/2/11 Steven Lord
2/2/11 Suranita
2/2/11 Matt J
2/2/11 Suranita
2/2/11 Matt J
2/3/11 Suranita
2/3/11 waku
2/3/11 Matt J
2/8/11 Suranita
2/8/11 Bruno Luong