Cody

Solution 2195224

Submitted on 6 Apr 2020 by Nikolaos Nikolaou
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 24 27 30 33 36 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 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

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.2129 1.1985 0.5509 1.9424 1.9358 2.6344 1.9146 1.6456 1.7272 1.5398 1.6376 1.8644 y = 2.2129 0.5374 1.1985 1.3734 0.5509 1.1892 1.9424 2.4200 1.9358 1.6179 2.6344 2.4505 1.9146 2.0192 1.6456 2.0195 1.7272 1.7118 1.5398 2.8710 1.6376 0.9443 1.8644 1.2258 y = 2.2129 0.5374 1.2354 1.1985 1.3734 1.5080 0.5509 1.1892 0.9343 1.9424 2.4200 0.5790 1.9358 1.6179 1.5886 2.6344 2.4505 1.9203 1.9146 2.0192 1.0284 1.6456 2.0195 2.0027 1.7272 1.7118 1.4002 1.5398 2.8710 2.2904 1.6376 0.9443 1.1851 1.8644 1.2258 1.3829 y = 2.2129 0.5374 1.2354 1.9719 1.1985 1.3734 1.5080 2.6492 0.5509 1.1892 0.9343 1.5979 1.9424 2.4200 0.5790 1.8096 1.9358 1.6179 1.5886 1.6741 2.6344 2.4505 1.9203 1.1326 1.9146 2.0192 1.0284 1.8360 1.6456 2.0195 2.0027 1.4644 1.7272 1.7118 1.4002 1.1344 1.5398 2.8710 2.2904 2.3551 1.6376 0.9443 1.1851 1.5944 1.8644 1.2258 1.3829 1.7337

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 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

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.1506 + 3.6900i 4.6274 + 3.3600i 5.1206 + 2.8800i 5.5909 + 2.5500i 6.0687 + 2.0700i 4.2990 + 1.7400i 2.5311 + 1.2600i 0.7619 + 0.7800i 1.2456 + 2.5500i 1.7219 + 4.3200i y = 1.0e+02 * 4.1506 + 3.6900i 5.6835 + 5.2200i 4.6274 + 3.3600i 6.1527 + 4.7400i 5.1206 + 2.8800i 4.3886 + 4.2600i 5.5909 + 2.5500i 2.6294 + 3.7800i 6.0687 + 2.0700i 0.7021 + 3.3000i 4.2990 + 1.7400i 1.1918 + 2.8200i 2.5311 + 1.2600i 1.5116 + 2.3400i 0.7619 + 0.7800i 1.9870 + 2.0100i 1.2456 + 2.5500i 2.3211 + 1.5300i 1.7219 + 4.3200i 2.7994 + 1.2000i y = 1.0e+02 * 4.1506 + 3.6900i 5.6835 + 5.2200i 2.4142 + 4.3500i 4.6274 + 3.3600i 6.1527 + 4.7400i 0.6524 + 6.1200i 5.1206 + 2.8800i 4.3886 + 4.2600i 0.9730 + 5.7900i 5.5909 + 2.5500i 2.6294 + 3.7800i 1.4432 + 5.3100i 6.0687 + 2.0700i 0.7021 + 3.3000i 1.9259 + 4.8300i 4.2990 + 1.7400i 1.1918 + 2.8200i 2.4054 + 4.3500i 2.5311 + 1.2600i 1.5116 + 2.3400i 2.8888 + 3.8700i 0.7619 + 0.7800i 1.9870 + 2.0100i 3.3699 + 3.3900i 1.2456 + 2.5500i 2.3211 + 1.5300i 3.8604 + 2.9100i 1.7219 + 4.3200i 2.7994 + 1.2000i 4.3331 + 2.4300i y = 1.0e+02 * 4.1506 + 3.6900i 5.6835 + 5.2200i 2.4142 + 4.3500i 1.5475 + 1.0800i 4.6274 + 3.3600i 6.1527 + 4.7400i 0.6524 + 6.1200i 2.0218 + 0.6000i 5.1206 + 2.8800i 4.3886 + 4.2600i 0.9730 + 5.7900i 2.5012 + 2.3700i 5.5909 + 2.5500i 2.6294 + 3.7800i 1.4432 + 5.3100i 2.9850 + 4.1400i 6.0687 + 2.0700i 0.7021 + 3.3000i 1.9259 + 4.8300i 3.4676 + 6.0600i 4.2990 + 1.7400i 1.1918 + 2.8200i 2.4054 + 4.3500i 3.9455 + 5.5800i 2.5311 + 1.2600i 1.5116 + 2.3400i 2.8888 + 3.8700i 4.4237 + 5.2500i 0.7619 + 0.7800i 1.9870 + 2.0100i 3.3699 + 3.3900i 4.7636 + 4.7700i 1.2456 + 2.5500i 2.3211 + 1.5300i 3.8604 + 2.9100i 5.2432 + 4.4400i 1.7219 + 4.3200i 2.7994 + 1.2000i 4.3331 + 2.4300i 5.5591 + 3.9600i y = 1.0e+02 * 4.1506 + 3.6900i 5.6835 + 5.2200i 2.4142 + 4.3500i 1.5475 + 1.0800i 3.0729 + 2.6100i 4.6274 + 3.3600i 6.1527 + 4.7400i 0.6524 + 6.1200i 2.0218 + 0.6000i 3.4052 + 2.1300i 5.1206 + 2.8800i 4.3886 + 4.2600i 0.9730 + 5.7900i 2.5012 + 2.3700i 3.8878 + 1.6500i 5.5909 + 2.5500i 2.6294 + 3.7800i 1.4432 + 5.3100i 2.9850 + 4.1400i 4.2209 + 1.1700i 6.0687 + 2.0700i 0.7021 + 3.3000i 1.9259 + 4.8300i 3.4676 + 6.0600i 4.6868 + 0.6900i 4.2990 + 1.7400i 1.1918 + 2.8200i 2.4054 + 4.3500i 3.9455 + 5.5800i 5.0326 + 2.4600i 2.5311 + 1.2600i 1.5116 + 2.3400i 2.8888 + 3.8700i 4.4237 + 5.2500i 5.5020 + 4.2300i 0.7619 + 0.7800i 1.9870 + 2.0100i 3.3699 + 3.3900i 4.7636 + 4.7700i 5.9794 + 6.0000i 1.2456 + 2.5500i 2.3211 + 1.5300i 3.8604 + 2.9100i 5.2432 + 4.4400i 4.2196 + 5.5200i 1.7219 + 4.3200i 2.7994 + 1.2000i 4.3331 + 2.4300i 5.5591 + 3.9600i 2.4415 + 5.0400i