[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Function names in feval -Reply
From: |
Gerrit Visser |
Subject: |
Function names in feval -Reply |
Date: |
Wed, 22 Mar 2000 13:28:49 +0200 |
>>> "John W. Eaton" <address@hidden> 22/March/2000
11:35am >>>
On 22-Mar-2000, Dirk Laurie <address@hidden> wrote:
| In the following Octave code (2.0.14):
|
| function y=integ(f,a,b,n)
| h=(b-a)/n; x=a+h*(0.5:n);
| y=h*sum(feval(f,x));
| endfunction
|
| the string 'f' may not contain the name of any local variable.
| I.e. if I have coded
|
| function y=f(x)
| y=exp(sin(x));
| endfunction
|
| it is illegal to ask for
|
| integ('f', 0, 2*pi, 16)
<snip>
How about:
function y=integ(f,a,b,n)
h=(b-a)/n; x=a+h*(0.5:n);
y=h*sum( eval([f, '(x)']) ); % evaluates 'f(x)'
endfunction
The function is then:
function y=f(x)
y=exp(sin(x));
endfunction
Call integ() then :
octave> integ('f', a, b, n)
or else
octave> integ(('exp(sin(x))', a, b, n))
if integ() is defined as:
function y=integ(f,a,b,n)
h=(b-a)/n; x=a+h*(0.5:n);
y=h*sum( eval(f)); % evaluates 'f'
endfunction
Hope this helps.
Gerrit
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------