polyval 只是计算一个多项式,这个你应该明白吧,help里的例子很清楚:
就是把x值带进去。
polyvalm比较特别的。但是明白这个之前,你需要明白什么是 characteristic polynomial:
In linear algebra , one associates a polynomial to every square matrix , its characteristic polynomial . This polynomial encodes several important properties of the matrix , most notably its eigenvalues , its determinant and its trace .
Suppose we want to compute the characteristic polynomial of the matrix
We have to compute the determinant of
and this determinant is
The latter is the characteristic polynomial of
A
.
现在回到我们自己的问题, 对于Y = polyvalm(p,X), 他的计算方法是:
Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1)*I
如果写出for循环是:
for i = 1:np %多项式长度,m是X的维数
Y = X * Y + diag(p(i) * ones(m,1));
end
这个循环比较简单,不要我解释吧?
举个例子给你看,我把循环拆开: 你再运行:
p=[1 2 3]
X=[1 2; 3 4]
polyvalm(p,X)

就是把x值带进去。
polyvalm比较特别的。但是明白这个之前,你需要明白什么是 characteristic polynomial:
In linear algebra , one associates a polynomial to every square matrix , its characteristic polynomial . This polynomial encodes several important properties of the matrix , most notably its eigenvalues , its determinant and its trace .
Suppose we want to compute the characteristic polynomial of the matrix



现在回到我们自己的问题, 对于Y = polyvalm(p,X), 他的计算方法是:
Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1)*I
如果写出for循环是:
for i = 1:np %多项式长度,m是X的维数
Y = X * Y + diag(p(i) * ones(m,1));
end
这个循环比较简单,不要我解释吧?
举个例子给你看,我把循环拆开: 你再运行:
p=[1 2 3]
X=[1 2; 3 4]
polyvalm(p,X)
看看,结果是不是一样的。
总结一下:
polyval(p, t)是计算出来:
p(1)*t^n + p(2)*t^(n-1) + .... + p(n)
polyvalm(p, X)是计算出来:
p(1)*X^n + p(2)*X^(n-1) + .... + p(n)*I
这里要注意最后的I就是单位阵,不要忘了,否则会出错,比如:
>> p=[1 2 3];
>> X=[1 2; 3 4];
>> polyvalm(p, X)
ans =
12 14
21 33
>> p(1)*X*X+p(2)*X+p(3)
ans =
12 17
24 33
>> p(1)*X*X+p(2)*X+p(3)*eye(2, 2)
ans =
12 14
21 33
多谢各位,认真研究了下帖子,终于明白了,就是将矩阵X整体带入多项式中,求矩阵的多项式值:lol