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 306981

Submitted on 19 Aug 2013 by Alfonso Nieto-Castanon

Correct

26Size
This is the leading solution.
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 = 1;
y1=-1;
neg3(neg3(x));
assert(isequal(ans,y1))

                    
2
Pass
 
%%
x=2;
y=3;
z=4;
neg3(x);
assert(isequal(ans,2))
neg3(y);
assert(isequal(ans,3))
neg3(x);
assert(isequal(ans,-2))
neg3(z);
assert(isequal(ans,4))
neg3(x);
assert(isequal(ans,2))
neg3(z);
assert(isequal(ans,-4))

                    
3
Pass
 
%%
x=0;
y=10;
neg3(x);
assert(isequal(ans,0))
neg3(x);
assert(isequal(ans,0))
neg3(y);
assert(isequal(ans,10))
neg3(y);
assert(isequal(ans,-10))