Sorting eigenvectors using symbolic toolbox for PageRank algorithm
조회 수: 1(최근 30일)
I wondering how I can sort the eigenvectors when I am using "d" as a symbolic from the symbolic toolbox? I tried using [U,D]= eig(vpa(M)), but that didn't work. Do I perhaps have to decide how the symbolic roots are sorted when solving for the eigenvectors? I am not quite sure how to do this in Matlab.
The code is given below where I have written a function and what I have in the script separately.
function [Vs] = pagerank_function(linkMatrix,d)
n = size(linkMatrix,1)
M = d * linkMatrix + (1-d)/n * ones(n)
% diagonal matrix eigenvalues D, eigenvectors mtx U
[U,D] = eig((M))
[d,ind] = sort(diag(D))
Ds = D(ind,ind)
Vs = V(:,ind)
Which takes the following matrix
L2 = [0 1/2 1/3 0 0 0 0;
1/3 0 0 0 1/2 0 0;
1/3 1/2 0 1 0 0 0;
1/3 0 1/3 0 1/2 0 0;
0 0 0 0 0 0 0;
0 0 1/3 0 0 1 0;
0 0 0 0 0 0 1];
d = sym('d');
[Vs] = pagerank_function(L2,d);
The general goal I want to achieve is to study how the damping factor 'd' influences all the eigenvectors produced in 'pagerank_function'. Any help would be appreciated as I am quite new to matlab.
Christine Tobler 2022년 5월 5일
There's an unknown variable in the value you pass to sort, so this won't be sorted by magnitude as the magnitude isn't known.
Here's a small example:
syms a b c d
sort([b c a])
So the sort function for arrays of symbolic variables is sorting them lexicographically, not based on value.
That gets us to the key issue with symbolically finding the largest eigenvalue of a matrix: If you have a formula for each of the eigenvalues of a matrix, depending on parameter d, then which of these eigenvalues is largest will depend on that parameter.
eigvals = eig([d d; 2 -d])
dvec = -10:10;
plot(dvec, subs(eigvals, dvec))
So depending on your choice of d, the first or the second of the formulas for the eigenvalue could the the larger one.