我要加入 登录
声振论坛 返回首页

friendchj的个人空间 http://home.vibunion.com/?89781 [收藏] [复制] [分享] [RSS]

日志

matlab polyval与polyvalm的区别是什么?

已有 1490 次阅读2010-1-13 06:25 |个人分类:matlab|

在坛子里发个网址真费劲,感谢原帖的几位大侠。
http://www.ilovematlab.cn/viewthread.php?tid=2538
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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]
np = length(p);
[m,n] = size(X);

Y = zeros(m,m)
i = 1
    Y = X * Y + diag(p(i) * ones(m,1))

i = 2
    Y = X * Y + diag(p(i) * ones(m,1))
    
    
i = 3
    Y = X * Y + diag(p(i) * ones(m,1))
你再运行:

p=[1 2 3]
X=[1 2; 3 4]
polyvalm(p,X)
(By math)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
总结一下:
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
(By lyqmath)

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 我要加入

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-4-28 15:38 , Processed in 0.033441 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部