[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: optimizing error: undefined argument
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: optimizing error: undefined argument |
Date: |
Tue, 16 Aug 2011 10:47:12 -0500 |
On 16 August 2011 03:57, DGati <address@hidden> wrote:
> I'm currently trying out the different optimizers in the optim-package on
> Octave 3.2.4, such as minimize(), line_min, or nmsmax. The file I'm
> minimizing (or in case of nmsmax, I'm maximizing the file*-1) is for
> simplicity's sake:
>
> function result = func(x)
> result=0.5*(x)^2-10;
> endfunction
>
> The error that I keep getting is
>
> error: 'x' undefined near line 2, column 7
> error: evaluating argument list element number 1
> error: evaluating argument list element number 1
>
> I don't understand that. How more should I define 'x' when it is simply the
> argument of the function?
> Thanks for tips!
If you write
some_func(func, some_parameter)
and func is a function, that is equivalent to
some_func(func(), some_parameter)
i.e. it's equivalent to calling func() without parameters and passing
that result to some_func. In this case, since func requires that
parameter, you are seeing the error that the parameter is undefined.
What you instead want to write is
some_func(@func, some_parameter)
i.e. create a handle to func with the @func syntax, and pass that to
some_func. Most, perhaps all Octave functions also accept the name of
the function in a string instead of a handle, so you can also write
this instead:
some_func("func", some_paramter)
HTH,
- Jordi G. H.