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

Correct

151Size
Leading solution size is 72.
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
 
z = rand(2,1)*10;
val = rpn(z(1),z(2),'/')
assert( val == z(2)/z(1) )
z = rand(2,1)*10;
val = rpn(z(1),z(2),'%')
assert( val == mod(z(2),z(1)) )
z = rand(2,1)*10;
val = rpn(z(1),z(2),'/')
assert( val == z(2)/z(1) )
z = rand(2,1)*10;
val = rpn(z(1),z(2),'-')
assert( val == (z(1)-z(2)) )
z = rand(2,1)*10;
val = rpn(z(1),z(2),'+')
assert( val == (z(1)+z(2)) )
z = rand(2,1)*10;
val = rpn(3,4,'-',5,'+')
assert( val == eval('3 - 4 + 5') )
val = rpn(5,1,2,'+',4,'*','+',3,'-')
assert( val == eval('5 + ((1+2)*4) - 3') )
val = rpn(55,11,22,'+',44,'*','+',33,'-')
assert( val == eval('55 + ((11+22)*44) - 33') )
val = rpn(553,112,221,'+',440,'*','+',30,'-')
assert( val == eval('553 + ((112+221)*440) - 30') )
val = rpn(553,112,221,'+',440,'*','+',30,'-')
assert( val == eval('553 + ((112+221)*440) - 30') )
%z = ceil(rand(1,5)*50);
%z = [1,2,3,4,5];
%val = rpn(z(1),'+',z(2),'*',z(1),z(3),'-',z(4),z(5),'%','*')
%q = mod( z(5),z(4))*(((z(1)+z(2))*z(1))-z(3))
%assert( val == q )
val =
    1.0077
val =
    0.2491
val =
    0.5071
val =
    6.5839
val =
   13.3750
val =
     4
val =
    14
val =
        1474
val =
      147043
val =
      147043