Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 175001

Submitted on 8 Dec 2012 by Khaled Hamed

Correct

17Size
Leading solution size is 15.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

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

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

                    
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)

                    
5
Pass
 
%%
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)