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 221706

Submitted on 22 Mar 2013 by Tim

Correct

72Size
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
 
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.593842872517657
val =
   0.049842205058381
val =
   0.220268397747343
val =
   5.746881198882869
val =
   0.935548474383002
val =
     4
val =
    14
val =
        1474
val =
      147043
val =
      147043