newbie: function of function of function ... Classic List Threaded 6 messages Open this post in threaded view
|

newbie: function of function of function ...

 Maybe the subject can be misleading but expresses well my confusion. It is my n-th attempt with octave and every time I try I I get stuck with some "stupid" problem. This time I decided to go on and ask for help. I think the problem is trivial but I just don't see the solution. I need a funcioin that computes the integral (using something like quadgk or quadcc) from -Inf to +Inf of an integrand like this: f(x) * log( f(x) ) where f is the argument of the function Naively, should read as: function retval = entropy( f )   quadcc( f*log(f), -Inf, +Inf) end I know that, if I define a somewhere function, say "gauss", I can write f = @(x) -gauss(x) .* log( gauss(x) ); quadcc(f,-Inf,+Inf) and it gives the right result. The problem is that I need to include the two lines above in a function that uses another function name as argument. And I couldn't sort it out :( Alberto _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

Re: newbie: function of function of function ...

Open this post in threaded view
|

RE: newbie: function of function of function ...

 In reply to this post by Dot Deb > From: [hidden email] [mailto:help-octave- > [hidden email]] On Behalf Of Dot Deb > Sent: Thursday, September 27, 2012 2:26 PM > To: [hidden email] > Subject: newbie: function of function of function ... > > Maybe the subject can be misleading but expresses well my confusion. > It is my n-th attempt with octave and every time I try I I get stuck with some > "stupid" problem. > This time I decided to go on and ask for help. > > I think the problem is trivial but I just don't see the solution. > > I need a funcioin that computes the integral (using something like quadgk or > quadcc) from -Inf to +Inf of an integrand like this: > > f(x) * log( f(x) ) > > where f is the argument of the function > > Naively, should read as: > > function retval = entropy( f ) >   quadcc( f*log(f), -Inf, +Inf) > end > > I know that, if I define a somewhere function, say "gauss", I can write > > f = @(x) -gauss(x) .* log( gauss(x) ); > quadcc(f,-Inf,+Inf) > > and it gives the right result. > > The problem is that I need to include the two lines above in a function that > uses another function name as argument. > And I couldn't sort it out :( > > Alberto Try defining the entropy function like this: function retval = entropy( f )    quadcc( @(x) f(x).*log(f(x)), -Inf, +Inf) end and call it using:  entropy(@gauss) Tony Richardson   _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

Re: newbie: function of function of function ...

 On Thu, Sep 27, 2012 at 11:25 PM, Richardson, Anthony <[hidden email]> wrote: > > Try defining the entropy function like this: > > function retval = entropy( f ) >    quadcc( @(x) f(x).*log(f(x)), -Inf, +Inf) > end > > and call it using:  entropy(@gauss) > Oh, it works! Now I understand where the problem was: actually I did try something similar, but without using the "@" at call level. Thank you. Alberto _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave