Contents

Using an external function

Assuming you defined the function f, or it is a built in function call a function f and evaluate f(2).

x = 2;
f(x)
ans =

   0.909297426825682

Using an inline function

Define a function g and evaluate g(3).

g = inline('x^2+2*x+2');
g(3)
ans =

    17

Using a symbolic function

Define a symbolic function h and evaluate h(4).

x = 4;
h = 'x^3+3*x-5';
eval(h)
ans =

    71

Using a function handle

Define a function i to be f and evaluate i(5) and i(6).

i = @f;
i(5)

feval(i,6)
ans =

  -0.958924274663138


ans =

  -0.279415498198926

Error messages

The function j was defined, j(x) = x unless x = 0 in which case it stops with an error message.

j(1)

j(0)

j(3)
Error using ==> j at 6
Error:666