Problem 581. Function composition

Created by David Hruska

Write a function that accepts two function handles f and g and returns the composition h. That is,

h = (f o g)(x) = f(g(x))

Example:

>> f = @(x)x^2;
>> g = @(x)x+1;
>> h = compose(f,g);
>> h(3)
ans =
  16

because (3+1)^2 = 16.

Problem Group

49 solvers submitted 64 solutions (1.31 solutions/solver).