Sorting eigenvectors using symbolic toolbox for PageRank algorithm
2 次查看(过去 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(vpa(M))
[U,D] = eig((M))
[d,ind] = sort(diag(D))
Ds = D(ind,ind)
Vs = V(:,ind)
end
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.
0 个评论
采纳的回答
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.
For example:
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!