[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 |
Hi,
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;
endfunction
function y = mean(f, a, b)
y = (f(a) + f(b))/2.0;
endfunction
mean (foo, 5, 0)
or
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: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Passing a function as parameter,
Luca Manini <=