function_name = function (input_arguments) -> (output arguments) ... // a bunch of statements endNote that in the body of the function, the input arguments can be used as if they are variables (but they are not visible outside the function), and the output arguments should be given values before the end of the function. The following function evaluates the Taylor expansion of
cos_taylor = function (x, N) -> v v = 1; vk = 1; xsq = x * x; for k = 1 : N vk = - vk * xsq / (2 * k) / (2 * k - 1); v += vk; end end