|
Contents | Previous | Next | Subchapters |
| Syntax |
function new function = existing function ( implicit arguments )
|
| See Also | arguments , local variable functions , strings to functions |
clear
function residual(d, t, x) begin
return d - x * t
end
Time = seq(3)
Data = 2 * Time
function f = residual(Data, Time)
print f(1)
O-Matrix will respond
{
1
2
3
}
because f(1) is evaluated as residual(Data, Time, 1).
This feature is useful when using a general purpose utility that
expects a function of a specific type.
For example, you could use the variable function f defined
above to solve the problem
2
minimize |f(x)| with respect to x
as follows
level = 0
maxit = 20
x0 = 1.
scale = 1.
result = nlsq(function f, x0, scale, maxit, level)
xout = result.col(coldim(result))
print xout
to which O-Matrix would respond
2