Function composition - MATLAB Cody - MATLAB Central

Problem 581. Function composition

Difficulty:Rate

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 = composeFcn(f,g);
>> h(3)
ans =
  16

because (3+1)^2 = 16.

Solution Stats

45.5% Correct | 54.5% Incorrect
Last Solution submitted on May 02, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
2
3

Problem Recent Solvers248

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!