Cody

Problem 1196. Apply a function array to an array of numbers

Solution 189828

Submitted on 11 Jan 2013 by James
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
%% f{1} = @(x) x; f{2} = @(x) x^2; f{3} = @(x) x^3; x = 1:5; y_correct = [ 1 2 3 4 5 1 4 9 16 25 1 8 27 64 125]; assert(isequal(arfn(f,x),y_correct))

``` f2 = 3 y = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y = 1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 y = 1 2 3 4 5 1 4 9 16 25 0 0 0 0 0 y = 1 2 3 4 5 1 4 9 16 25 1 8 27 64 125 ```

2   Pass
%% f{1} = @(x) 1/x; f{2} = @(x) x^0.5; f{3} = @(x) x-4; x = [4 16 25 100]; y_correct = [0.25 0.0625 0.04 0.01 2 4 5 10 0 12 21 96]; assert(isequal(arfn(f,x),y_correct))

``` f2 = 3 y = 0 0 0 0 0 0 0 0 0 0 0 0 y = 0.2500 0.0625 0.0400 0.0100 0 0 0 0 0 0 0 0 y = 0.2500 0.0625 0.0400 0.0100 2.0000 4.0000 5.0000 10.0000 0 0 0 0 y = 0.2500 0.0625 0.0400 0.0100 2.0000 4.0000 5.0000 10.0000 0 12.0000 21.0000 96.0000 ```