Define and call functions

To define a simple one-liner function, one can use the sign ->
>> f = x -> (1 - x) / (1 + x + x^2)
A defined function can be called in the usual way
>> f = x -> (1 - x) / (1 + x + x^2)
   user defined function
>> f(-1)
   -2

A function can have several variables

>> f = (r, theta) -> r * (1 + cos(theta));
>> f(2, pi)
   0

More complicated functions have to be defined using the keyword function.



oz 2009-12-22