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 304608

Submitted on 15 Aug 2013 by Alfonso Nieto-Castanon

Correct

18Size
Leading solution size is 10.
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
 
%%
x = rand(2,2,2);
y = neg2(neg2(x));
y_correct = -x;
assert(isequal(y,y_correct))
ans =
    @(~)-x
ans(:,:,1) =
  -0.969295197028605  -0.460800409235046
  -0.177632055984951  -0.723363805017810
ans(:,:,2) =
  -0.491873666872008  -0.755446933707137
  -0.561513294667482  -0.968089029074987
2
Pass
 
%%
x = [];
y = neg2(neg2(x));
y_correct = -x;
assert(isequal(y,y_correct))
ans =
    @(~)-x
ans =
     []
3
Pass
 
%%
x = sqrt(-5);
y = neg2(neg2(x));
y_correct = -x;
assert(isequal(y,y_correct))
ans =
    @(~)-x
ans =
  0.000000000000000 - 2.236067977499790i
4
Pass
 
%% What does a single call give?
x = rand;
disp(neg2(x))
ans =
    @(~)-x
    @(~)-x