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))
Example:
>> f = @(x)x^2; >> g = @(x)x+1; >> h = composeFcn(f,g); >> h(3) ans = 16
because (3+1)^2 = 16.
Solution Stats
Problem Comments
-
8 Comments
Show
5 older comments
yurenchu
on 27 Apr 2017
Thanks, David Hruska!
善翔 韩
on 28 Aug 2022
function h = composeFcn(f,g)
syms x
x=g(x);
h=matlabFunction(f(x));
end
I am so confused where i was wrong?
Dyuman Joshi
on 28 Aug 2022
@善翔 韩, syms is a part of symbolic toolbox and toolboxes are not available on cody.
Solution Comments
Show commentsProblem Recent Solvers251
Suggested Problems
-
Sort a list of complex numbers based on far they are from the origin.
5727 Solvers
-
276 Solvers
-
Back to basics 21 - Matrix replicating
1743 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
12894 Solvers
-
07 - Common functions and indexing 6
458 Solvers
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!