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 457785

Submitted on 18 Jun 2014 by Ziko

Correct

78Size
Leading solution size is 36.
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 = 25;
y=sumOfSqr(x);
v=y(1)^2 + y(2)^2;
assert(isequal(x,v))
assert(round(y(1))==y(1))
assert(round(y(2))==y(2))
y =
    4.8990
y =
    4.8990    4.5826
y =
    4.8990    4.5826    4.0000
y =
    4.8990    4.5826    4.0000    3.0000
y =
    4.8990    4.5826    4.0000    3.0000         0
y =
     0     5
2
Pass
 
%%
x = 41;
y=sumOfSqr(x);
v=y(1)^2 + y(2)^2;
assert(isequal(x,v))
assert(round(y(1))==y(1))
assert(round(y(2))==y(2))
y =
    6.3246
y =
    6.3246    6.0828
y =
    6.3246    6.0828    5.6569
y =
    6.3246    6.0828    5.6569    5.0000
y =
    6.3246    6.0828    5.6569    5.0000    4.0000
y =
    6.3246    6.0828    5.6569    5.0000    4.0000    2.2361
y =
     4     5
3
Pass
 
%%
x = 7;
y=sumOfSqr(x);
assert(isempty(y));
y =
    2.4495
y =
    2.4495    1.7321
y =
     []
4
Pass
 
%%
x = 391250;
y=sumOfSqr(x);
v=y(1)^2 + y(2)^2;
assert(isequal(x,v))
assert(round(y(1))==y(1))
assert(round(y(2))==y(2))
y =
  625.4990
y =
  625.4990  625.4966
y =
  625.4990  625.4966  625.4926
y =
  625.4990  625.4966  625.4926  625.4870
y =
  625.4990  625.4966  625.4926  625.4870  625.4798
y =
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710
y =
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606
y =
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486
y =
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Column 10
  625.4199
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 11
  625.4199  625.4031
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 12
  625.4199  625.4031  625.3847
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 13
  625.4199  625.4031  625.3847  625.3647
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 14
  625.4199  625.4031  625.3847  625.3647  625.3431
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 15
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 16
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 17
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Column 19
  625.2112
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 20
  625.2112  625.1800
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 21
  625.2112  625.1800  625.1472
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 22
  625.2112  625.1800  625.1472  625.1128
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 23
  625.2112  625.1800  625.1472  625.1128  625.0768
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 24
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 25
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 26
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Column 28
  624.8728
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 29
  624.8728  624.8272
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 30
  624.8728  624.8272  624.7800
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 31
  624.8728  624.8272  624.7800  624.7311
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 32
  624.8728  624.8272  624.7800  624.7311  624.6807
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 33
  624.8728  624.8272  624.7800  624.7311  624.6807  624.6287
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 34
  624.8728  624.8272  624.7800  624.7311  624.6807  624.6287  624.5751
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 35
  624.8728  624.8272  624.7800  624.7311  624.6807  624.6287  624.5751  624.5198
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 36
  624.8728  624.8272  624.7800  624.7311  624.6807  624.6287  624.5751  624.5198  624.4630
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 36
  624.8728  624.8272  624.7800  624.7311  624.6807  624.6287  624.5751  624.5198  624.4630
  Column 37
  624.4045
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  625.2112  625.1800  625.1472  625.1128  625.0768  625.0392  625.0000  624.9592  624.9168
  Columns 28 through 36
  624.8728  624.8272  624.7800  624.7311  624.6807  624.6287  624.5751  624.5198  624.4630
  Columns 37 through 38
  624.4045  624.3445
y =
  Columns 1 through 9
  625.4990  625.4966  625.4926  625.4870  625.4798  625.4710  625.4606  625.4486  625.4350
  Columns 10 through 18
  625.4199  625.4031  625.3847  625.3647  625.3431  625.3199  625.2951  625.2687  625.2408
  Columns 19 through 27
  6...
5
Pass
 
%%
x = 288;
y=sumOfSqr(x);
v=y(1)^2 + y(2)^2;
assert(isequal(x,v))
assert(round(y(1))==y(1))
assert(round(y(2))==y(2))
y =
   16.9411
y =
   16.9411   16.8523
y =
   16.9411   16.8523   16.7033
y =
   16.9411   16.8523   16.7033   16.4924
y =
   16.9411   16.8523   16.7033   16.4924   16.2173
y =
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745
y =
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596
y =
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666
y =
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
y =
  Columns 1 through 9
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
  Column 10
   13.7113
y =
  Columns 1 through 9
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
  Columns 10 through 11
   13.7113   12.9228
y =
  Columns 1 through 9
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
  Columns 10 through 12
   13.7113   12.9228   12.0000
y =
  Columns 1 through 9
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
  Columns 10 through 13
   13.7113   12.9228   12.0000   10.9087
y =
  Columns 1 through 9
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
  Columns 10 through 14
   13.7113   12.9228   12.0000   10.9087    9.5917
y =
  Columns 1 through 9
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
  Columns 10 through 15
   13.7113   12.9228   12.0000   10.9087    9.5917    7.9373
y =
  Columns 1 through 9
   16.9411   16.8523   16.7033   16.4924   16.2173   15.8745   15.4596   14.9666   14.3875
  Columns 10 through 16
   13.7113   12.9228   12.0000   10.9087    9.5917    7.9373    5.6569
y =
    12    12
6
Pass
 
%%
x = 1;
y=sumOfSqr(x);
v=y(1)^2 + y(2)^2;
assert(isequal(x,v))
assert(round(y(1))==y(1))
assert(round(y(2))==y(2))
y =
     0
y =
     0     1