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 148702

Submitted on 15 Oct 2012 by James

Correct

56Size
Leading solution size is 29.
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
 
%%
for n=4:6;
   sq=squares(n);
   assert(length(sq)==n)
   for k=1:n
      assert(sq(k)>0)
      assert(round(sqrt(sq(k)))==sqrt(sq(k)))
   end
   assert(round(sqrt(sum(sq)))==sqrt(sum(sq)))
end
b =
    25
q =
    12
sq =
     3     4    12
b =
   169
q =
    84
sq =
     3     4    12    84
sq =
           9          16         144        7056
b =
    25
q =
    12
sq =
     3     4    12
b =
   169
q =
    84
sq =
     3     4    12    84
b =
        7225
q =
        3612
sq =
           3           4          12          84        3612
sq =
           9          16         144        7056    13046544
b =
    25
q =
    12
sq =
     3     4    12
b =
   169
q =
    84
sq =
     3     4    12    84
b =
        7225
q =
        3612
sq =
           3           4          12          84        3612
b =
    13053769
q =
     6526884
sq =
  Columns 1 through 5
           3           4          12          84        3612
  Column 6
     6526884
sq =
   1.0e+13 *
    0.0000    0.0000    0.0000    0.0000    0.0000    4.2600