help-octave
[Top][All Lists]
Advanced

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

Re: Numerical Differentiation and Integration of Array Data


From: c.
Subject: Re: Numerical Differentiation and Integration of Array Data
Date: Wed, 7 Dec 2011 08:46:39 +0100

On 7 Dec 2011, at 04:04, syberraith wrote:

> I was thinking you used the anonymous function to avoid the repeating the
> code of the process function.
> 
> I understand what your showing there, although I've tried it a number of
> different ways, and octave keeps giving me undefined errs.  So when I put
> this into a script and try to run it:
> 
> a = 2;
> b = 3;
> one = @(x) a.*x + b;
> two = @(x) a.^2.*x + b;
> function res = calculate ( f, v )
>   res = f(v)  
> endfunction
> calculate (one, 5)
> calculate (two, 4)

Your example works without errors for me:

>> a = 2;
>> b = 3;
>> one = @(x) a.*x + b;
>> two = @(x) a.^2.*x + b;
>> function res = calculate ( f, v )
  res = f(v)  
endfunction
>> calculate (one, 5)
res =  13
ans =  13
>> calculate (two, 4)
res =  19
ans =  19

the double outpt is due to a missing semicolon in the roe "res = f(v)"

> I get this:
> 
> error: `a' undefined near line 4 column 12
> error: evaluating binary operator `.*' near line 4, column 13
> error: evaluating binary operator `+' near line 4, column 17
> error: called from `?unknown?'
> error: evaluating assignment expression near line 8, column 8
> error: called from `calculate'
> error: near line 11 of file `/home/fred/octave/test4.m'
> octave:1> 

what version of Octave are you using?
on what system?
how did you install it?

c.


reply via email to

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