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 | 5 | 20 | if isscalar(X) && isscalar(Y)
|
< 0.001 | 5 | 21 | Z = X.^Y;
|
| | 22 | else
|
| | 23 | if isinteger(X) || isinteger(Y)
|
| | 24 | error(message('MATLAB:mpower:integerNotSupported'));
|
| | 25 | end
|
| | 26 |
|
| | 27 | if ~ismatrix(X) || ~ismatrix(Y)
|
| | 28 | error(message('MATLAB:mpower:inputsMustBe2D'));
|
| | 29 | end
|
| | 30 |
|
| | 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
|
| | 42 | else
|
| | 43 | X = double(X);
|
| | 44 | Y = double(Y);
|
| | 45 | end
|
| | 46 |
|
| | 47 | if isscalar(Y) && isreal(Y) && isfinite(Y) && round(Y) == Y ...
|
| | 48 | && size(X,1) == size(X,2)
|
| | 49 | Z = integerMpower(X,Y);
|
| | 50 | else
|
| | 51 | Z = generalMpower(X,Y);
|
| | 52 | end
|
< 0.001 | 5 | 53 | end
|
Other subfunctions in this file are not included in this listing.