Cody

# Problem 42854. Crunch that matrix!

Solution 910821

Submitted on 17 Jun 2016 by Alexander
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=reshape(1:36,6,[]); b=[sum(a(:,1:3),2) sum(a(:,4:6),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-10)

y = 21 75 24 78 27 81 30 84 33 87 36 90

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

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

3   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-10)

y = 1.9250 2.6155 1.4404 1.3169 2.3625 1.4063 2.0004 1.5925 1.5322 1.6235 0.6118 2.4632 1.5225 2.3854 1.8653 1.9876 1.5654 2.0351 1.7982 1.2725 0.5384 0.7741 1.4815 1.1986 1.5269 1.6015 1.7771 2.1069 1.3801 1.1821 0.5101 1.4887 2.0919 1.5610 0.8432 1.6242 1.2091 1.5415 2.3905 1.6850 1.7185 1.3031 1.0693 2.2139 1.6280 0.9630 1.0048 1.0157

4   Pass
a=ones(18); b=3*ones(18,6); m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-10)

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

5   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-10)

y = 1.0e+02 * 4.1464 + 3.6900i 5.6813 + 5.2200i 2.4090 + 4.3500i 1.5411 + 1.0800i 3.0710 + 2.6100i 4.6351 + 3.3600i 6.1660 + 4.7400i 0.6495 + 6.1200i 2.0220 + 0.6000i 3.4007 + 2.1300i 5.1128 + 2.8800i 4.3943 + 4.2600i 0.9774 + 5.7900i 2.5061 + 2.3700i 3.8865 + 1.6500i 5.6024 + 2.5500i 2.6334 + 3.7800i 1.4553 + 5.3100i 2.9734 + 4.1400i 4.2231 + 1.1700i 6.0792 + 2.0700i 0.7005 + 3.3000i 1.9339 + 4.8300i 3.4701 + 6.0600i 4.6977 + 0.6900i 4.3025 + 1.7400i 1.1805 + 2.8200i 2.4088 + 4.3500i 3.9508 + 5.5800i 5.0228 + 2.4600i 2.5356 + 1.2600i 1.5073 + 2.3400i 2.8881 + 3.8700i 4.4282 + 5.2500i 5.5113 + 4.2300i 0.7694 + 0.7800i 1.9984 + 2.0100i 3.3796 + 3.3900i 4.7615 + 4.7700i 5.9819 + 6.0000i 1.2459 + 2.5500i 2.3224 + 1.5300i 3.8535 + 2.9100i 5.2349 + 4.4400i 4.2095 + 5.5200i 1.7194 + 4.3200i 2.8056 + 1.2000i 4.3306 + 2.4300i 5.5663 + 3.9600i 2.4425 + 5.0400i