Cody

Problem 582. Function composition - harder

Write a function that accepts an arbitrary number of function handles f_1, f_2, ..., f_n and returns the composition h. That is,

h = (f_1 o f_2 o ... o f_n)(x) = f_1(f_2( ... f_n(x) ... ))

Example:

>> f1 = @(x)x+1;
>> f2 = @(x)3*x;
>> f3 = @sqrt;
>> h = compose(f1,f2,f3);
>> h(9)
ans =
  10

because 3*sqrt(9)+1 = 10.

You can assume that there will always be at least one input passed to the compose function.

Solution Stats

55.49% Correct | 44.51% Incorrect
Last solution submitted on Sep 17, 2016

Problem Comments

Solution 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