Cody

# Problem 42854. Crunch that matrix!

Solution 1561731

Submitted on 16 Jun 2018 by Akash Srivastav
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 = 2.3439 2.0096 1.5319 0.8467 2.2525 1.6709 1.3832 1.5453 1.4660 1.0504 2.0428 2.6359 1.7404 1.5282 1.4831 1.8690 2.0869 1.4486 1.9627 1.9643 1.1612 1.3652 0.9722 1.6866 0.9843 1.4659 0.6017 2.3266 1.3637 1.3665 0.9513 1.5339 1.6615 1.1376 1.8692 2.0619 1.0701 1.5296 1.5612 1.7925 2.2460 1.7804 0.5872 1.3165 1.9726 1.4168 2.0923 1.9378

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.1599 + 3.6900i 5.6801 + 5.2200i 2.4230 + 4.3500i 1.5430 + 1.0800i 3.0773 + 2.6100i 4.6374 + 3.3600i 6.1721 + 4.7400i 0.6468 + 6.1200i 2.0234 + 0.6000i 3.4075 + 2.1300i 5.1197 + 2.8800i 4.3955 + 4.2600i 0.9776 + 5.7900i 2.5019 + 2.3700i 3.8913 + 1.6500i 5.5959 + 2.5500i 2.6305 + 3.7800i 1.4593 + 5.3100i 2.9962 + 4.1400i 4.2166 + 1.1700i 6.0775 + 2.0700i 0.7066 + 3.3000i 1.9429 + 4.8300i 3.4578 + 6.0600i 4.6998 + 0.6900i 4.3094 + 1.7400i 1.1766 + 2.8200i 2.4087 + 4.3500i 3.9380 + 5.5800i 5.0275 + 2.4600i 2.5361 + 1.2600i 1.5236 + 2.3400i 2.8951 + 3.8700i 4.4180 + 5.2500i 5.5096 + 4.2300i 0.7552 + 0.7800i 1.9974 + 2.0100i 3.3726 + 3.3900i 4.7538 + 4.7700i 5.9750 + 6.0000i 1.2460 + 2.5500i 2.3257 + 1.5300i 3.8578 + 2.9100i 5.2267 + 4.4400i 4.2204 + 5.5200i 1.7201 + 4.3200i 2.8004 + 1.2000i 4.3248 + 2.4300i 5.5713 + 3.9600i 2.4490 + 5.0400i

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!