[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: newbie: function of function of function ...
From: |
Richardson, Anthony |
Subject: |
RE: newbie: function of function of function ... |
Date: |
Thu, 27 Sep 2012 21:25:18 +0000 |
> From: address@hidden [mailto:help-octave-
> address@hidden On Behalf Of Dot Deb
> Sent: Thursday, September 27, 2012 2:26 PM
> To: address@hidden
> 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