For example the function costfunc is an argument of the optim primitive. Its calling sequence must be: [f,g,ind]=costfunc(x,ind) as imposed by the optim primitive. The following non-linear primitives in Scilab need argument functions or subroutines: ode, optim, impl, dassl, intg, odedc, fsolve. For problems where computation time is important, it is recommended to use C or Fortran subroutines. Examples of such subroutines are given in the directory SCIDIR/routines/default. See the README file there for more details.
When such a subroutine is written it must be linked to Scilab. This link operation can be done dynamically by the link command. It is also possible to introduce the code in a more permanent manner by inserting it in a specific interface in SCIDIR/routines/default and rebuild a new Scilab by a make all command in the Scilab directory.