Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 225275

Submitted on 29 Mar 2013

Incorrect

52Size
Leading solution size is 13.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
A = [1 2 4];
B = [-1 1 3];
fun = @plus;
y_correct = [0 3 7];
assert(isequal(ABfun(A,B,fun),y_correct))

                    
2
Pass
 
%%
A = [1 2 4];
B = [-1 1 3];
fun = @minus;
y_correct = [2 1 1];
assert(isequal(ABfun(A,B,fun),y_correct))

                    
3
Fail
 
%%
 A = [2 3 4];
B = 2;
fun = @power;
y_correct = [4 9 16];
assert(isequal(ABfun(A,B,fun),y_correct))
Error: Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
4
Pass
 
%%
 A = [1 0 1];
B = [0 1 0];
fun = @times;
y_correct = [0 0 0];
assert(isequal(ABfun(A,B,fun),y_correct))