Matlab与Mathematica,特征向量? [英] Matlab vs Mathematica, eigenvectors?

查看:187
本文介绍了Matlab与Mathematica,特征向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function H = calcHyperlinkMatrix(M)
    [r c] = size(M);
    H = zeros(r,c);
    for i=1:r,
        for j=1:c,
            if (M(j,i) == 1)
                colsum = sum(M,2);
                H(i,j) = 1 / colsum(j);
            end;
        end;
    end;
    H     


function V = pageRank(M)
    [V D] = eigs(M,1);
    V

function R = google(links)
    R = pageRank(calcHyperlinkMatrix(links));
    R

M=[[0 1 1 0 0 0 0 0];[0 0 0 1 0 0 0 0];[0 1 0 0 1 0 0 0];[0 1 0 0 1 1 0 0];
    [0 0 0 0 0 1 1 1];[0 0 0 0 0 0 0 1];[1 0 0 0 1 0 0 1];[0 0 0 0 0 1 1 0];]
google(M)

ans =

   -0.1400
   -0.1576
   -0.0700
   -0.1576
   -0.2276
   -0.4727
   -0.4201
   -0.6886


Mathematica:

calculateHyperlinkMatrix[linkMatrix_] := {
  {r, c} = Dimensions[linkMatrix];
  H = Table[0, {a, 1, r}, {b, 1, c}];
  For[i = 1, i < r + 1, i++,
   For[j = 1, j < c + 1, j++,
    If[linkMatrix[[j, i]] == 1, H[[i, j]] = 1/Total[linkMatrix[[j]]], 
     0]
    ]
   ];
  H
  }


H = {{0, 0, 0, 0, 0, 0, 1/3, 0}, {1/2, 0, 1/2, 1/3, 0, 0, 0, 0}, {1/2,
     0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 1/2, 1/3, 
    0, 0, 1/3, 0}, {0, 0, 0, 1/3, 1/3, 0, 0, 1/2}, {0, 0, 0, 0, 1/3, 
    0, 0, 1/2}, {0, 0, 0, 0, 1/3, 1, 1/3, 0}};
R = Eigensystem[H];
VR = {R[[1, 1]], R[[2, 1]]}
PageRank = VR[[2]]


{1, {12/59, 27/118, 6/59, 27/118, 39/118, 81/118, 36/59, 1}}

Matlab和Mathematica没有使用特征值1给出相同的特征向量.尽管两者都起作用...哪一个是正确的,为什么又不同?如何处理所有特征值为1的特征向量?

Matlab and Mathematica doesn't give the same eigenvector with the eigenvalue 1. Both works though...which one is correct and why are they different? How do I gte all eigenvectors with the eigenvalue 1?

推荐答案

特征向量 X是一些满足的向量X

The Definition of an Eigenvector X is some vector X that satisfies

AX = kX

其中,A是矩阵,k是常数.从定义中可以很清楚地看到,对于任何不等于0ccX也是本征向量.因此,存在一些常量c,例如X_matlab = cX_mathematica.

where A is a matrix and k is a constant. It is pretty clear from the definition that cX is also an Eigenvector for any c not equal to 0. So there is some constant c such that X_matlab = cX_mathematica.

看起来第一个是正常的(欧氏长度为1,即加上坐标平方的总和,然后取平方根,您将得到1),第二个被规范化,因此最终坐标为1(找到任何特征向量,然后将所有坐标除以最终坐标.

It looks like the first is normal (has Euclidean length 1, i.e. add the sums of the squares of the coordinates then take the square root and you will get 1) and the second is normalised so that the final coordinate is 1 (any Eigenvector was found and then all coordinates were divided by the final coordinate).

如果需要的只是特征向量,则可以使用任意一个.

You can use whichever one you want, if all you need is an Eigenvector.

这篇关于Matlab与Mathematica,特征向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆