[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
error with function handles
From: |
simone marras |
Subject: |
error with function handles |
Date: |
Wed, 19 Aug 2009 14:18:30 +0200 |
Hi,
I am trying to call a function that accepts a function handle as
argument. My functions are all defined within the same directory where
myfun.m rerturns a simple expression as:
function y = myfun(x)
y = 10*exp(-50.0*abs(x)) - 0.01/((x-0.5).*(x-0.5) + 0.001) +
5.0*sin(5.0*x);
endfunction
and midpntc is defined as:
function [Int] = midpntc(a, b, m, function)
h=(b-a)/m
x=[a+h/2:h:b];
k = max(size(x));
y = eval(fun);
if size(y) == 1, y = diag(ones(k))*y; end
int = h*sum(y);
when I call midpntc in octave as:
>> Int = midpntc(0, 1, 10, "myfun")
I obtain the following error:
midpntc(0,1,10,"myfun")
h = 0.10000
error: `x' undefined near line 2 column 9
error: evaluating binary operator `.^' near line 2, column 10
error: evaluating binary operator `-' near line 2, column 13
error: evaluating binary operator `-' near line 2, column 17
error: evaluating binary operator `./' near line 2, column 6
error: evaluating assignment expression near line 2, column 3
error: called from `myfun'
error: evaluating assignment expression near line 13, column 4
error: called from `midpntc' in file
`/home/simone/Documents/scientific/CFD/myCFD_library/ATMOSPHERE_miscellanea/TMP/midpntc.m'
while, if I use the syntax
>> Int = midpntc(0, 1, 10, @myfun)
the error that I get is:
h = 0.10000
error: octave_base_value::convert_to_str_internal (): wrong type
argument `function handle'
error: eval: expecting std::string argument
error: evaluating assignment expression near line 13, column 4
error: called from `midpntc' in file
`/home/simone/Documents/scientific/CFD/myCFD_library/ATMOSPHERE_miscellanea/TMP/midpntc.m'
Could anyone help me with this issue?
Thank you very much in advance,
S.
--
Simone Marras, Ph.D. candidate
Barcelona Supercomputing Center
Universitat Politecnica de Catalunya
Avd. Diagonal 647,
Edificio H, planta 10
Barcelona, 08028
SPAIN
Tel.: (+34) 93 4011744
web: www.cranfield.ac.uk/~c086030
- error with function handles,
simone marras <=