Scilab Function

optim - non-linear optimization routine

Calling Sequence

[f,xopt]=optim(costf,x0)
[f,[xopt,[gradopt,[work]]]]=optim(costf,[contr],x0,['algo'],[df0,[mem]],
[work],[stop],['in'],[imp=iflag])

Parameters

Description

Non-linear optimization routine for programs without constraints or with bound constraints:

min costf(x) w.r.t x.
   

costf is an "external" i.e function, or list or Fortran routine (see "external"). This external must return f (costf(x)) and g (gradient of costf) given x.

If costf is a function, the calling sequence for costf must be:

[f,g,ind]=costf(x,ind).
   

Here, costf is a function which returns f, value (real number) of cost function at x, and g, gradient vector of cost function at x. The variable ind is used by optim and is described below.

If ind=2 (resp. 3, 4), costf must provide f (resp. g, f and g).

If ind=1 nothing is computed (used for display purposes only).

On output, ind<0 means that f cannot be evaluated at x and ind=0 interrupts the optimization.

If costf is a character string, it refers to the name of a Fortran routine which must be linked to Scilab (see examples in the routines foptim.f and e.g. genros.f in the directory SCIDIR/default)

Dynamic link of Fortran routine is also possible (help link).

Here, the generic calling sequence for the Fortran subroutine is: function costf(ind,n,x,f,g,ti,tr,td)

ind has the same meaning as above if set to 0,1,2 but the values ind=10 and ind=11 are now valid. These values are used for initializations (see below).

n is the dimension of x, x is an n vector, ti,tr,td are working arrays.

The Fortran function costf must return f and the vector g, given x, ind, n, ti, tr, td.

If costf is given as a Fortran routine, it is possible to initialize parameters or to send Scilab variables to this routine.

This facility is managed by the parameter 'in.

If the string 'in' is present, initialization is done by Fortran: optim makes two calls to the Fortran function costf, once with ind=10 and once with ind=11. In this case, for ind=10, costf must set the dimensions nti, ntr, ntd of ti, tr, td in the common/nird/nti, ntr, ntd and, for ind=11, costf must initialize the vectors ti , tr, td (integer vector, real vector, double precision vector respectively).

In the calling sequence of optim, the string 'in' can be replaced by 'ti', valti ,'td' , valtd. Then, the Fortran function costf(ind, x, f, g, ti, tr, td) is evaluated with ti=valti and td=valtd whatever the value of ind. Thus, the Scilab variables valti and valtd (integer vector and real vector) are sent to the Fortran function costf.

It is also possible to save the content of of the working arrays ti and td. This is possible by adding the strings 'si' and/or 'sd' at the ned of the calling sequence of optim. Then, the output variables must be: [f,[x,[g],[to]]],[ti],[td]].

Examples

See Also