Cody

# Problem 1108. Raise Matrix to Power

Solution 1992622

Submitted on 27 Oct 2019
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
filetext = fileread('matpow.m'); assert(isempty(strfind(filetext, '^'))) assert(isempty(strfind(filetext, 'mpower')))

2   Pass
x=[1 2; -1 2]; y_correct=x^5; y=matpow(x,5); assert(max(abs(y(:)-y_correct(:)))<1e-5)

y = 1 2 -1 2 y = -1 6 -3 2 y = -7 10 -5 -2 y = -17 6 -3 -14 y = -23 -22 11 -34

3   Fail
x=[1 2; -1 2]; y_correct=x^-3.5; y=matpow(x,-3.5); assert(max(abs(y(:)-y_correct(:)))<1e-5)

y = 1 2 -1 2

Assertion failed.

4   Pass
x=[1 2 3; 4 2 -1; -2 4 -3]; y_correct=x^6; y=matpow(x,6); assert(max(abs(y(:)-y_correct(:)))<1e-5)

y = 1 2 3 4 2 -1 -2 4 -3 y = 3 18 -8 14 8 13 20 -8 -1 y = 91 10 15 20 96 -5 -10 20 71 y = 101 262 218 414 212 -21 -72 304 -263 y = 713 1598 -613 1304 1168 1093 1670 -588 269 y = 8331 2170 2380 3790 9316 -535 -1220 3240 4791

5   Fail
x=[1 2 3; 4 2 -1; -2 4 -3]; y_correct=x^-4; y=matpow(x,-4); assert(max(abs(y(:)-y_correct(:)))<1e-5)

y = 1 2 3 4 2 -1 -2 4 -3

Assertion failed.