📄 mpower.m
字号:
function Pn = mpower(P,n)
% MPOWER -- power of matrix polynomial
%
% Pn = P^n
% Pn = mpower(P,n)
%
% This function is not meant to be called by the user. It is called by
% Matlab if an expression of the form P^N is encountered, where P
% is a matrix polynomial.
%
% N must be an integer. For N=0, the result is a unit matrix of the
% correct size. For N>0, the result is computed by repeated
% application of P*P. For N<0, the routine attempts inv(P)^N.
% Copyright (c) 2004 by Fritz Keinert (keinert@iastate.edu),
% Dept. of Mathematics, Iowa State University, Ames, IA 50011.
% This software may be freely used and distributed for non-commercial
% purposes, provided this copyright statement is preserved, and
% appropriate credit for its use is given.
%
% Last update: Feb 20, 2004
% check that n is integer
if (length(n) ~= 1 | round(n) ~= n)
error('exponent must be integer');
end
if (n == 0)
Pn = P;
Pn.coef = eye(size(P));
if (isa(P,'sym'))
Pn.coef = sym(Pn.coef);
end
Pn.min = 0;
elseif (n > 0)
Pn = P;
for i = 2:n
Pn = Pn * P;
end
else % n < 0
Pinv = inv(P);
Pn = Pinv;
for i = 2:-n
Pn = Pn * Pinv;
end
end
Pn = trim(Pn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -