#!/usr/bin/perl

print "Content-Type: text/html\n\n<pre>\n";

$damp = 0.85;
$a = 0;
$b = 0;
$i = 40; # loop 10 times

# forward links
# a -> b - 1 outgoing link
# b -> a - 1 outgoing link

# i.e. "backward" links (what's pointing to me?)
# a <= b
# b <= a

# I've rounded to 5 decimal places to make the output easier to read

while ($i--) {
    printf("a: %.5f b: %.5f\n", $a, $b);
	$a = (1 - $damp) + $damp * ($b);
	$b = (1 - $damp) + $damp * ($a);
}
printf("Average pagerank = %.4f\n", ($a + $b) / 2);

Outputs

a: 0.00000 b: 0.00000
a: 0.15000 b: 0.27750
a: 0.38588 b: 0.47799
a: 0.55629 b: 0.62285
a: 0.67942 b: 0.72751
a: 0.76838 b: 0.80313
a: 0.83266 b: 0.85776
a: 0.87909 b: 0.89723
a: 0.91265 b: 0.92575
a: 0.93689 b: 0.94635
a: 0.95440 b: 0.96124
a: 0.96705 b: 0.97200
a: 0.97620 b: 0.97977
a: 0.98280 b: 0.98538
a: 0.98757 b: 0.98944
a: 0.99102 b: 0.99237
a: 0.99351 b: 0.99449
a: 0.99531 b: 0.99602
a: 0.99661 b: 0.99712
a: 0.99755 b: 0.99792
a: 0.99823 b: 0.99850
a: 0.99872 b: 0.99891
a: 0.99908 b: 0.99922
a: 0.99933 b: 0.99943
a: 0.99952 b: 0.99959
a: 0.99965 b: 0.99970
a: 0.99975 b: 0.99979
a: 0.99982 b: 0.99985
a: 0.99987 b: 0.99989
a: 0.99991 b: 0.99992
a: 0.99993 b: 0.99994
a: 0.99995 b: 0.99996
a: 0.99996 b: 0.99997
a: 0.99997 b: 0.99998
a: 0.99998 b: 0.99998
a: 0.99999 b: 0.99999
a: 0.99999 b: 0.99999
a: 0.99999 b: 0.99999
a: 0.99999 b: 1.00000
a: 1.00000 b: 1.00000
Average pagerank = 1.0000

  >

This page and its contents are copyright © 2020, Ian Rogers. Theme derived from Prav