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 216890

Submitted on 13 Mar 2013

Incorrect

51Size
Leading solution size is 12.
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
Fail
 
%%
x = 1;
y =2;
y_correct = 2;
assert(isequal(round(your_fcn_name(x,y)),y_correct))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, '*')),'sign * forbidden')
assert(isempty(strfind(filetext, 'mtimes')),'mtimes forbidden')
assert(isempty(strfind(filetext, 'cross')),'cross forbidden')
assert(isempty(strfind(filetext, 'prod')),'prod forbidden')
assert(isempty(strfind(filetext, 'cumprod')))
assert(isempty(strfind(filetext, 'times')))
assert(isempty(strfind(filetext, 'mldivide')))
assert(isempty(strfind(filetext, 'mrdivide')))
assert(isempty(strfind(filetext, '/')),'/ forbidden')
assert(isempty(strfind(filetext, '\')))
assert(isempty(strfind(filetext, '-')))
assert(isempty(strfind(filetext, '^')),'^ forbidden')
assert(isempty(strfind(filetext, 'dot')))
assert(isempty(strfind(filetext, '''')),'string forbidden')
Error: Assertion failed.
2
Pass
 
%%
x = 8;
y =25;
y_correct = 200;
assert(isequal(round(your_fcn_name(x,y)),y_correct))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, '*')))
assert(isempty(strfind(filetext, 'mtimes')))
assert(isempty(strfind(filetext, 'cross')))
assert(isempty(strfind(filetext, 'prod')))
assert(isempty(strfind(filetext, 'cumprod')))
assert(isempty(strfind(filetext, 'times')))
assert(isempty(strfind(filetext, 'dot')))
z =
    25
z =
    50
z =
    75
z =
   100
z =
   125
z =
   150
z =
   175
z =
   200
output =
   200
3
Pass
 
%%
x = 8;
y =0;
y_correct = 0;
assert(isequal(round(your_fcn_name(x,y)),y_correct))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, '*')))
assert(isempty(strfind(filetext, 'mtimes')))
assert(isempty(strfind(filetext, 'cross')))
assert(isempty(strfind(filetext, 'prod')))
assert(isempty(strfind(filetext, 'cumprod')))
assert(isempty(strfind(filetext, 'times')))
assert(isempty(strfind(filetext, 'dot')))
z =
     0
z =
     0
z =
     0
z =
     0
z =
     0
z =
     0
z =
     0
z =
     0
output =
     0
4
Pass
 
%%
x = -148;
y =2865;
y_correct = -424020;
assert(isequal(round(your_fcn_name(x,y)),y_correct))
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, '*')))
assert(isempty(strfind(filetext, 'mtimes')))
assert(isempty(strfind(filetext, 'cross')))
assert(isempty(strfind(filetext, 'prod')))
assert(isempty(strfind(filetext, 'cumprod')))
assert(isempty(strfind(filetext, 'times')))
assert(isempty(strfind(filetext, 'dot')))
z =
       -2865
z =
       -5730
z =
       -8595
z =
      -11460
z =
      -14325
z =
      -17190
z =
      -20055
z =
      -22920
z =
      -25785
z =
      -28650
z =
      -31515
z =
      -34380
z =
      -37245
z =
      -40110
z =
      -42975
z =
      -45840
z =
      -48705
z =
      -51570
z =
      -54435
z =
      -57300
z =
      -60165
z =
      -63030
z =
      -65895
z =
      -68760
z =
      -71625
z =
      -74490
z =
      -77355
z =
      -80220
z =
      -83085
z =
      -85950
z =
      -88815
z =
      -91680
z =
      -94545
z =
      -97410
z =
     -100275
z =
     -103140
z =
     -106005
z =
     -108870
z =
     -111735
z =
     -114600
z =
     -117465
z =
     -120330
z =
     -123195
z =
     -126060
z =
     -128925
z =
     -131790
z =
     -134655
z =
     -137520
z =
     -140385
z =
     -143250
z =
     -146115
z =
     -148980
z =
     -151845
z =
     -154710
z =
     -157575
z =
     -160440
z =
     -163305
z =
     -166170
z =
     -169035
z =
     -171900
z =
     -174765
z =
     -177630
z =
     -180495
z =
     -183360
z =
     -186225
z =
     -189090
z =
     -191955
z =
     -194820
z =
     -197685
z =
     -200550
z =
     -203415
z =
     -206280
z =
     -209145
z =
     -212010
z =
     -214875
z =
     -217740
z =
     -220605
z =
     -223470
z =
     -226335
z =
     -229200
z =
     -232065
z =
     -234930
z =
     -237795
z =
     -240660
z =
     -243525
z =
     -246390
z =
     -249255
z =
     -252120
z =
     -254985
z =
     -257850
z =
     -260715
z =
     -263580
z =
     -266445
z =
     -269310
z =
     -272175
z =
     -275040
z =
     -277905
z =
     -280770
z =
     -283635
z =
     -286500
z =
     -289365
z =
     -292230
z =
     -295095
z =
     -297960
z =
     -300825
z =
     -303690
z =
     -306555
z =
     -309420
z =
     -312285
z =
     -315150
z =
     -318015
z =
     -320880
z =
     -323745
z =
     -326610
z =
     -329475
z =
     -332340
z =
     -335205
z =
     -338070
z =
     -340935
z =
     -343800
z =
     -346665
z =
     -349530
z =
     -352395
z =
     -355260
z =
     -358125
z =
     -360990
z =
     -363855
z =
     -366720
z =
     -369585
z =
     -372450
z =
     -375315
z =
     -378180
z =
     -381045
z =
     -383910
z =
     -386775
z =
     -389640
z =
     -392505
z =
     -395370
z =
     -398235
z =
     -401100
z =
     -403965
z =
     -406830
z =
     -409695
z =
     -412560
z =
     -415425
z =
     -418290
z =
     -421155
z =
     -424020
output =
     -424020
5
Pass
 
%% Test 5 : randi!!
x = randi([1 58]);
y =286.5;
y_correct = x*y;
assert(abs( your_fcn_name(x,y)-y_correct)<1e-9)
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, '*')))
assert(isempty(strfind(filetext, 'mtimes')))
assert(isempty(strfind(filetext, 'cross')))
assert(isempty(strfind(filetext, 'prod')))
assert(isempty(strfind(filetext, 'cumprod')))
assert(isempty(strfind(filetext, 'times')))
assert(isempty(strfind(filetext, 'dot')))
z =
  286.5000
z =
   573
z =
  859.5000
z =
        1146
z =
   1.4325e+03
z =
        1719
z =
   2.0055e+03
z =
        2292
z =
   2.5785e+03
z =
        2865
z =
   3.1515e+03
z =
        3438
z =
   3.7245e+03
z =
        4011
z =
   4.2975e+03
z =
        4584
z =
   4.8705e+03
z =
        5157
z =
   5.4435e+03
z =
        5730
z =
   6.0165e+03
z =
        6303
z =
   6.5895e+03
z =
        6876
z =
   7.1625e+03
z =
        7449
z =
   7.7355e+03
z =
        8022
z =
   8.3085e+03
z =
        8595
z =
   8.8815e+03
output =
   8.8815e+03
6
Pass
 
%% Test 6 : randi and pi !!
x = randi([14 580]);
y = -pi;
y_correct = x*y;
assert(abs( your_fcn_name(x,y)-y_correct)<1e-9)
filetext = fileread('your_fcn_name.m');
assert(isempty(strfind(filetext, '*')))
assert(isempty(strfind(filetext, 'mtimes')))
assert(isempty(strfind(filetext, 'cross')))
assert(isempty(strfind(filetext, 'prod')))
assert(isempty(strfind(filetext, 'cumprod')))
assert(isempty(strfind(filetext, 'times')))
assert(isempty(strfind(filetext, 'dot')))
assert(isempty(strfind(filetext, 'num2str')))
assert(isempty(strfind(filetext, 'int2str')))
assert(isempty(strfind(filetext, 'dec2bin')))
z =
   -3.1416
z =
   -6.2832
z =
   -9.4248
z =
  -12.5664
z =
  -15.7080
z =
  -18.8496
z =
  -21.9911
z =
  -25.1327
z =
  -28.2743
z =
  -31.4159
z =
  -34.5575
z =
  -37.6991
z =
  -40.8407
z =
  -43.9823
z =
  -47.1239
z =
  -50.2655
z =
  -53.4071
z =
  -56.5487
z =
  -59.6903
z =
  -62.8319
z =
  -65.9734
z =
  -69.1150
z =
  -72.2566
z =
  -75.3982
z =
  -78.5398
z =
  -81.6814
z =
  -84.8230
z =
  -87.9646
z =
  -91.1062
z =
  -94.2478
z =
  -97.3894
z =
 -100.5310
z =
 -103.6726
z =
 -106.8142
z =
 -109.9557
z =
 -113.0973
z =
 -116.2389
z =
 -119.3805
z =
 -122.5221
z =
 -125.6637
z =
 -128.8053
z =
 -131.9469
z =
 -135.0885
z =
 -138.2301
z =
 -141.3717
z =
 -144.5133
z =
 -147.6549
z =
 -150.7964
z =
 -153.9380
z =
 -157.0796
z =
 -160.2212
z =
 -163.3628
z =
 -166.5044
z =
 -169.6460
z =
 -172.7876
z =
 -175.9292
z =
 -179.0708
z =
 -182.2124
z =
 -185.3540
z =
 -188.4956
z =
 -191.6372
z =
 -194.7787
z =
 -197.9203
z =
 -201.0619
z =
 -204.2035
z =
 -207.3451
z =
 -210.4867
z =
 -213.6283
z =
 -216.7699
z =
 -219.9115
z =
 -223.0531
z =
 -226.1947
z =
 -229.3363
z =
 -232.4779
z =
 -235.6194
z =
 -238.7610
z =
 -241.9026
z =
 -245.0442
z =
 -248.1858
z =
 -251.3274
z =
 -254.4690
z =
 -257.6106
z =
 -260.7522
z =
 -263.8938
z =
 -267.0354
z =
 -270.1770
z =
 -273.3186
z =
 -276.4602
z =
 -279.6017
z =
 -282.7433
z =
 -285.8849
z =
 -289.0265
z =
 -292.1681
z =
 -295.3097
z =
 -298.4513
z =
 -301.5929
z =
 -304.7345
z =
 -307.8761
z =
 -311.0177
z =
 -314.1593
z =
 -317.3009
z =
 -320.4425
z =
 -323.5840
z =
 -326.7256
z =
 -329.8672
z =
 -333.0088
z =
 -336.1504
z =
 -339.2920
z =
 -342.4336
z =
 -345.5752
z =
 -348.7168
z =
 -351.8584
z =
 -355.0000
z =
 -358.1416
z =
 -361.2832
z =
 -364.4247
z =
 -367.5663
z =
 -370.7079
z =
 -373.8495
z =
 -376.9911
z =
 -380.1327
z =
 -383.2743
z =
 -386.4159
z =
 -389.5575
z =
 -392.6991
z =
 -395.8407
z =
 -398.9823
z =
 -402.1239
z =
 -405.2655
z =
 -408.4070
z =
 -411.5486
z =
 -414.6902
z =
 -417.8318
z =
 -420.9734
z =
 -424.1150
z =
 -427.2566
z =
 -430.3982
z =
 -433.5398
z =
 -436.6814
z =
 -439.8230
z =
 -442.9646
z =
 -446.1062
z =
 -449.2477
z =
 -452.3893
z =
 -455.5309
output =
 -455.5309