Problem 581. Function composition

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))


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

because (3+1)^2 = 16.

Solution Stats

66.08% Correct | 33.92% Incorrect
Last solution submitted on Dec 08, 2016

Problem Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more