Cody

# Problem 42854. Crunch that matrix!

Solution 891019

Submitted on 18 May 2016 by Pramit Biswas
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
a=magic(9)-30; b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2)]; assert(isequal(matrix_crunch(a),b));

y = 84 114 63 12 -48 -18 3 33 54 y = 84 3 114 -48 63 -27 12 3 -48 33 -18 63 3 93 33 114 54 63 y = 84 3 12 114 -48 33 63 -27 63 12 3 84 -48 33 114 -18 63 54 3 93 3 33 114 -48 54 63 -18

2   Pass
a=rand(12); b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2) sum(a(:,10:12),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-8)

y = 1.7474 2.1392 1.4474 1.4881 1.0755 2.6989 1.1637 1.2905 0.8415 1.3694 0.6519 0.4778 y = 1.7474 1.2831 2.1392 1.5362 1.4474 0.7869 1.4881 1.9095 1.0755 1.5807 2.6989 1.6020 1.1637 1.3015 1.2905 1.1117 0.8415 0.6872 1.3694 1.4407 0.6519 1.4611 0.4778 1.6710 y = 1.7474 1.2831 1.4094 2.1392 1.5362 1.1590 1.4474 0.7869 1.1125 1.4881 1.9095 1.2038 1.0755 1.5807 1.9557 2.6989 1.6020 1.8478 1.1637 1.3015 2.6749 1.2905 1.1117 1.4418 0.8415 0.6872 1.1027 1.3694 1.4407 1.7013 0.6519 1.4611 2.1093 0.4778 1.6710 1.7488 y = 1.7474 1.2831 1.4094 0.7678 2.1392 1.5362 1.1590 1.3787 1.4474 0.7869 1.1125 1.1178 1.4881 1.9095 1.2038 0.8083 1.0755 1.5807 1.9557 0.9559 2.6989 1.6020 1.8478 1.9439 1.1637 1.3015 2.6749 1.8522 1.2905 1.1117 1.4418 2.1494 0.8415 0.6872 1.1027 1.1760 1.3694 1.4407 1.7013 1.0304 0.6519 1.4611 2.1093 2.2487 0.4778 1.6710 1.7488 0.7787

3   Pass
a=ones(18); b=3*ones(18,6); assert(isequal(matrix_crunch(a),b))

y = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 y = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 y = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 y = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 y = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 y = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

4   Pass
a=magic(15)+j.*flipud(magic(15)); a=a(1:10,:)-rand(10,15); b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2) sum(a(:,10:12),2) sum(a(:,13:15),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-8)

y = 1.0e+02 * 4.1506 + 3.6900i 4.6337 + 3.3600i 5.1116 + 2.8800i 5.6006 + 2.5500i 6.0736 + 2.0700i 4.3082 + 1.7400i 2.5303 + 1.2600i 0.7723 + 0.7800i 1.2473 + 2.5500i 1.7190 + 4.3200i y = 1.0e+02 * 4.1506 + 3.6900i 5.6867 + 5.2200i 4.6337 + 3.3600i 6.1576 + 4.7400i 5.1116 + 2.8800i 4.3911 + 4.2600i 5.6006 + 2.5500i 2.6294 + 3.7800i 6.0736 + 2.0700i 0.7021 + 3.3000i 4.3082 + 1.7400i 1.1824 + 2.8200i 2.5303 + 1.2600i 1.5079 + 2.3400i 0.7723 + 0.7800i 1.9903 + 2.0100i 1.2473 + 2.5500i 2.3252 + 1.5300i 1.7190 + 4.3200i 2.8093 + 1.2000i y = 1.0e+02 * 4.1506 + 3.6900i 5.6867 + 5.2200i 2.4219 + 4.3500i 4.6337 + 3.3600i 6.1576 + 4.7400i 0.6438 + 6.1200i 5.1116 + 2.8800i 4.3911 + 4.2600i 0.9673 + 5.7900i 5.6006 + 2.5500i 2.6294 + 3.7800i 1.4568 + 5.3100i 6.0736 + 2.0700i 0.7021 + 3.3000i 1.9360 + 4.8300i 4.3082 + 1.7400i 1.1824 + 2.8200i 2.4119 + 4.3500i 2.5303 + 1.2600i 1.5079 + 2.3400i 2.8989 + 3.8700i 0.7723 + 0.7800i 1.9903 + 2.0100i 3.3678 + 3.3900i 1.2473 + 2.5500i 2.3252 + 1.5300i 3.8525 + 2.9100i 1.7190 + 4.3200i 2.8093 + 1.2000i 4.3319 + 2.4300i y = 1.0e+02 * 4.1506 + 3.6900i 5.6867 + 5.2200i 2.4219 + 4.3500i 1.5441 + 1.0800i 4.6337 + 3.3600i 6.1576 + 4.7400i 0.6438 + 6.1200i 2.0303 + 0.6000i 5.1116 + 2.8800i 4.3911 + 4.2600i 0.9673 + 5.7900i 2.5047 + 2.3700i 5.6006 + 2.5500i 2.6294 + 3.7800i 1.4568 + 5.3100i 2.9909 + 4.1400i 6.0736 + 2.0700i 0.7021 + 3.3000i 1.9360 + 4.8300i 3.4595 + 6.0600i 4.3082 + 1.7400i 1.1824 + 2.8200i 2.4119 + 4.3500i 3.9489 + 5.5800i 2.5303 + 1.2600i 1.5079 + 2.3400i 2.8989 + 3.8700i 4.4193 + 5.2500i 0.7723 + 0.7800i 1.9903 + 2.0100i 3.3678 + 3.3900i 4.7456 + 4.7700i 1.2473 + 2.5500i 2.3252 + 1.5300i 3.8525 + 2.9100i 5.2383 + 4.4400i 1.7190 + 4.3200i 2.8093 + 1.2000i 4.3319 + 2.4300i 5.5652 + 3.9600i y = 1.0e+02 * 4.1506 + 3.6900i 5.6867 + 5.2200i 2.4219 + 4.3500i 1.5441 + 1.0800i 3.0782 + 2.6100i 4.6337 + 3.3600i 6.1576 + 4.7400i 0.6438 + 6.1200i 2.0303 + 0.6000i 3.4057 + 2.1300i 5.1116 + 2.8800i 4.3911 + 4.2600i 0.9673 + 5.7900i 2.5047 + 2.3700i 3.8806 + 1.6500i 5.6006 + 2.5500i 2.6294 + 3.7800i 1.4568 + 5.3100i 2.9909 + 4.1400i 4.2200 + 1.1700i 6.0736 + 2.0700i 0.7021 + 3.3000i 1.9360 + 4.8300i 3.4595 + 6.0600i 4.6882 + 0.6900i 4.3082 + 1.7400i 1.1824 + 2.8200i 2.4119 + 4.3500i 3.9489 + 5.5800i 5.0245 + 2.4600i 2.5303 + 1.2600i 1.5079 + 2.3400i 2.8989 + 3.8700i 4.4193 + 5.2500i 5.5035 + 4.2300i 0.7723 + 0.7800i 1.9903 + 2.0100i 3.3678 + 3.3900i 4.7456 + 4.7700i 5.9800 + 6.0000i 1.2473 + 2.5500i 2.3252 + 1.5300i 3.8525 + 2.9100i 5.2383 + 4.4400i 4.2192 + 5.5200i 1.7190 + 4.3200i 2.8093 + 1.2000i 4.3319 + 2.4300i 5.5652 + 3.9600i 2.4429 + 5.0400i