Rev | Line | |
---|
[37] | 1 | function y = mpower(x,d) |
---|
| 2 | %MPOWER (overloaded) |
---|
| 3 | |
---|
| 4 | % Author Johan Löfberg |
---|
| 5 | % $Id: mpower.m,v 1.2 2006/08/11 11:48:15 joloef Exp $ |
---|
| 6 | |
---|
| 7 | %Sanity check |
---|
| 8 | if prod(size(d))>1 | ~((fix(d) == d)) | ~(d>=0) |
---|
| 9 | error('The power must be scalar.'); |
---|
| 10 | end |
---|
| 11 | if x.dim(1)~=x.dim(2) |
---|
| 12 | error('Matrix must be square.') |
---|
| 13 | end |
---|
| 14 | |
---|
| 15 | switch d |
---|
| 16 | case 0 |
---|
| 17 | y = eye(x.dim(1),x.dim(2))^0; |
---|
| 18 | case 1 |
---|
| 19 | y = x; |
---|
| 20 | case 2 |
---|
| 21 | y = x * x; |
---|
| 22 | otherwise |
---|
| 23 | y = x*mpower(x,d-1); |
---|
| 24 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.