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 = composeFcn(f,g);
because (3+1)^2 = 16.
My code runs fine on my local machine, but I get error messages when I try it here.
Error using compose (line 85) First argument must be a string array, character vector, or cell array of character vectors. Error in TestPoint1 (line 3) h = compose(f,g);
To the creator of this problem: please rename this function in your test suite. "Compose" is already a built-in MATLAB function.
Changed the function name to composeFcn to avoid clashing with the compose built-in function. Let me know if you're still having trouble!
I guess the name needed changing, but be aware that if we ever re-score old entries, everyone who passed before the name change will now fail, since they will now be calling the wrong function.
Thanks, David Hruska!
Make one big string out of two smaller strings
Sophie Germain prime
Max index of 3D array
Function composition - harder
Implement a counter
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office