time | Calls | line |
---|
| | 1 | function Z = mpower(X,Y)
|
| | 2 | %^ Matrix power.
|
| | 3 | % Z = X^y is X to the y power if y is a scalar and X is square. If y
|
| | 4 | % is an integer greater than one, the power is computed by repeated
|
| | 5 | % squaring. For other values of y the calculation involves
|
| | 6 | % eigenvalues and eigenvectors.
|
| | 7 | %
|
| | 8 | % Z = x^Y is x to the Y power if Y is a square matrix and x is a scalar.
|
| | 9 | % Computed using eigenvalues and eigenvectors.
|
| | 10 | %
|
| | 11 | % Z = X^Y, where both X and Y are matrices, is an error.
|
| | 12 | %
|
| | 13 | % C = MPOWER(A,B) is called for the syntax 'A ^ B' when A or B is an
|
| | 14 | % object.
|
| | 15 | %
|
| | 16 | % See also POWER.
|
| | 17 |
|
| | 18 | % Copyright 1984-2018 The MathWorks, Inc.
|
| | 19 |
|
< 0.001 | 1 | 20 | if isscalar(X) && isscalar(Y)
|
| | 21 | Z = X.^Y;
|
< 0.001 | 1 | 22 | else
|
< 0.001 | 1 | 23 | if isinteger(X) || isinteger(Y)
|
| | 24 | error(message('MATLAB:mpower:integerNotSupported'));
|
< 0.001 | 1 | 25 | end
|
| | 26 |
|
< 0.001 | 1 | 27 | if ~ismatrix(X) || ~ismatrix(Y)
|
| | 28 | error(message('MATLAB:mpower:inputsMustBe2D'));
|
< 0.001 | 1 | 29 | end
|
| | 30 |
|
< 0.001 | 1 | 31 | if isa(X,'single') || isa(Y, 'single')
|
| | 32 | try
|
| | 33 | X = single(X);
|
| | 34 | Y = single(Y);
|
| | 35 | catch err
|
| | 36 | if (strcmp(err.identifier, 'MATLAB:unimplementedSparseType'))
|
| | 37 | error(message('MATLAB:mpower:sparseSingleNotSupported'))
|
| | 38 | else
|
| | 39 | rethrow(err);
|
| | 40 | end
|
| | 41 | end
|
< 0.001 | 1 | 42 | else
|
< 0.001 | 1 | 43 | X = double(X);
|
< 0.001 | 1 | 44 | Y = double(Y);
|
< 0.001 | 1 | 45 | end
|
| | 46 |
|
< 0.001 | 1 | 47 | if isscalar(Y) && isreal(Y) && isfinite(Y) && round(Y) == Y ...
|
| 1 | 48 | && size(X,1) == size(X,2)
|
0.002 | 1 | 49 | Z = integerMpower(X,Y);
|
| | 50 | else
|
| | 51 | Z = generalMpower(X,Y);
|
< 0.001 | 1 | 52 | end
|
< 0.001 | 1 | 53 | end
|
Other subfunctions in this file are not included in this listing.