[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Passing a function as parameter

From: Luca Manini
Subject: Passing a function as parameter
Date: Fri, 16 Nov 2001 09:50:55 +0100


is it possible to pass functions to other fucntions?
The simple example is to write a function that calculate the 
mean (or the definite integral) of that function on a given interval.

in Python is like this:

def foo(x):
    return x * x

def mean(f, a, b):
    return (f(a) + f(b))/2.0

print mean(foo, 5, 0)

in Octave "should" be something like:

function y = foo(x)
  y = x * x;

function y = mean(f, a, b)
  y = (f(a) + f(b))/2.0;

mean (foo, 5, 0)


mean ('foo', 5, 0)

but it does not work. 

        Any hint? TIA, Luca.
        Please answer (also) directly to address@hidden

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]