Cody

# Problem 42590. Divide elements by sum of elements

Solution 2655584

Submitted on 5 Jul 2020
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   Fail
filetext = fileread('divideElements.m'); assert(isempty(strfind(filetext, 'for'))) assert(isempty(strfind(filetext, 'while')))

Assertion failed.

2   Pass
x = magic(3); y_correct = [0.53 0.07 0.4; 0.20 0.33 0.47; 0.27 0.60 0.13]; assert(isequal(divideElements(x),y_correct))

m = 3 n = 3 y = 0 0 0 0 0 0 0 0 0 z1 = 8 3 4 z2 = 15 y = 0.5300 0 0 0.2000 0 0 0.2700 0 0 z1 = 1 5 9 z2 = 15 y = 0.5300 0.0700 0 0.2000 0.3300 0 0.2700 0.6000 0 z1 = 6 7 2 z2 = 15 y = 0.5300 0.0700 0.4000 0.2000 0.3300 0.4700 0.2700 0.6000 0.1300

3   Pass
x = magic(4); y_correct = [0.47 0.06 0.09 0.38 0.15 0.32 0.29 0.24 0.26 0.21 0.18 0.35 0.12 0.41 0.44 0.03]; assert(isequal(divideElements(x),y_correct))

m = 4 n = 4 y = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 z1 = 16 5 9 4 z2 = 34 y = 0.4700 0 0 0 0.1500 0 0 0 0.2600 0 0 0 0.1200 0 0 0 z1 = 2 11 7 14 z2 = 34 y = 0.4700 0.0600 0 0 0.1500 0.3200 0 0 0.2600 0.2100 0 0 0.1200 0.4100 0 0 z1 = 3 10 6 15 z2 = 34 y = 0.4700 0.0600 0.0900 0 0.1500 0.3200 0.2900 0 0.2600 0.2100 0.1800 0 0.1200 0.4100 0.4400 0 z1 = 13 8 12 1 z2 = 34 y = 0.4700 0.0600 0.0900 0.3800 0.1500 0.3200 0.2900 0.2400 0.2600 0.2100 0.1800 0.3500 0.1200 0.4100 0.4400 0.0300

4   Pass
x = ones(2); y_correct = repmat(0.5,2,2); assert(isequal(divideElements(x),y_correct))

m = 2 n = 2 y = 0 0 0 0 z1 = 1 1 z2 = 2 y = 0.5000 0 0.5000 0 z1 = 1 1 z2 = 2 y = 0.5000 0.5000 0.5000 0.5000

5   Pass
x = [1 0.5; 2 1]; y_correct = [0.33 0.33; 0.67 0.67]; assert(isequal(divideElements(x),y_correct))

m = 2 n = 2 y = 0 0 0 0 z1 = 1 2 z2 = 3 y = 0.3300 0 0.6700 0 z1 = 0.5000 1.0000 z2 = 1.5000 y = 0.3300 0.3300 0.6700 0.6700