Cody

# Problem 42854. Crunch that matrix!

Solution 1942867

Submitted on 19 Sep 2019 by Augusto Mazzei
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)

ans = 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)

ans = 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)

ans = 2.6791 2.0959 1.6253 1.8312 1.7730 1.2873 1.7030 2.2373 0.6972 2.2979 2.0195 1.8805 0.9277 1.3071 2.4929 1.8651 1.1952 1.7365 2.2145 1.7147 1.0408 1.4227 1.7350 1.6491 1.4839 1.1619 1.4904 1.0918 1.1566 1.9000 0.7517 1.7149 1.5553 1.9618 1.1948 0.7579 1.5094 1.9338 1.2866 2.2131 2.0579 0.2531 0.5180 0.2650 1.2449 1.3190 1.0589 1.7779

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

ans = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 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)

ans = 1.0e+02 * 4.1541 + 3.6900i 5.6799 + 5.2200i 2.4123 + 4.3500i 1.5429 + 1.0800i 3.0797 + 2.6100i 4.6343 + 3.3600i 6.1690 + 4.7400i 0.6411 + 6.1200i 2.0280 + 0.6000i 3.4059 + 2.1300i 5.1207 + 2.8800i 4.3928 + 4.2600i 0.9813 + 5.7900i 2.5017 + 2.3700i 3.8774 + 1.6500i 5.6032 + 2.5500i 2.6192 + 3.7800i 1.4528 + 5.3100i 2.9866 + 4.1400i 4.2142 + 1.1700i 6.0696 + 2.0700i 0.7029 + 3.3000i 1.9331 + 4.8300i 3.4577 + 6.0600i 4.7006 + 0.6900i 4.2988 + 1.7400i 1.1897 + 2.8200i 2.4199 + 4.3500i 3.9436 + 5.5800i 5.0367 + 2.4600i 2.5430 + 1.2600i 1.5210 + 2.3400i 2.8941 + 3.8700i 4.4347 + 5.2500i 5.5004 + 4.2300i 0.7661 + 0.7800i 1.9958 + 2.0100i 3.3843 + 3.3900i 4.7572 + 4.7700i 5.9830 + 6.0000i 1.2420 + 2.5500i 2.3157 + 1.5300i 3.8613 + 2.9100i 5.2395 + 4.4400i 4.2090 + 5.5200i 1.7286 + 4.3200i 2.7985 + 1.2000i 4.3324 + 2.4300i 5.5589 + 3.9600i 2.4418 + 5.0400i