Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.