Function composition - harder - MATLAB Cody - MATLAB Central

Problem 582. Function composition - harder

Difficulty:Rate

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 = composeFcn(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 composeFcn function.

Solution Stats

47.95% Correct | 52.05% Incorrect
Last Solution submitted on Jul 22, 2024

Problem Comments

Solution Comments

Show comments
MATLAB Central 2024 In Review
...
Let's celebrate what made 2024 memorable! Together, we made big impacts, hosted...

Problem Recent Solvers101

Suggested Problems

More from this Author2

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page