"equilibrium problems and circuit analysis"

Upload: lambdastudentepl

Post on 03-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    1/23

    Mathematical Models - DN2266

    Homework 2

    -

    Equilibrium Problems and Circuit Analysis

    Teachers

    Anna-Karin TORNBERG

    Rikard OJALA

    Authors

    Pierre-Alexandre BEAUFORT

    Hadrien VAN LIERDE

    October 2013

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    2/23

    Contents

    1 Least squares problem and Lagrange multipliers . . . . . . . . . . . . . . . . . . 11.1 Linear system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Properties of the matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    2 Linear Electrical Networks: DC Analysis . . . . . . . . . . . . . . . . . . . . . . 22.1 Abstract of the program . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.2 Analysis of a circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    3 The PageRank algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    3.1 Column-stochastic matrix . . . . . . . . . . . . . . . . . . . . . . . . . . 53.2 Ranking soccer teams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    A Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13A.1 Existence of a minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . 13A.2 Perron-Frobenius Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . 13A.3 dc_anal.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13A.4 circuit_solution.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14A.5 DN2266_lab2_Q3a.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14A.6 DN2266_lab2_Q3b.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15A.7 DN2266_lab2_Q3c1.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    A.8 DN2266_lab2_Q3c2.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18A.9 DN2266_lab2_Q3c3.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19A.10 DN2266_lab2_Q3c4.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

    0

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    3/23

    1 Least squares problem and Lagrange multipliers

    We consider the following least squares problem with linear constraints:

    minCx=c

    1

    2Ax a22 (1)

    where A is m n, m > n, rank(A) =n and C is p n, p < n, rank(C) =p. The x-value forwhich the minimum is taken is denoted by x.

    1.1 Linear system

    This equation can be solved as a linear system of equations. The Lagrange function associatedto this problem is given by:

    L(x, ) =1

    2(Ax a)T(Ax a) +T(Cx c) (2)

    where = (1,...,p)T

    .

    As thep constraints are linearly independent, ifxis a solution of the problem, then there existssuch that L(x, ) = 0. The Lagrange function can be rewritten as:

    L(x, ) =1

    2xTATAx xTATa

    1

    2aTa+xTCT Tc (3)

    The gradient of this function is given by:

    xL = ATAx ATa+CT

    L = Cx c (4)

    As this gradient has to be zero, we obtain the following linear system:

    ATA CT

    C 0

    x

    =

    ATa

    c

    (5)

    1.2 Properties of the matrix

    The matrix of the linear system5 is symmetric but it is not necessarily positive definite. Letus consider the following matrices:

    1 00 1

    1 1

    and C= 1 0 (6)

    Then,

    ATA CT

    C 0

    =

    2 1 11 2 01 0 0

    . The eigenvalues of this matrix are 0.4812,1.3111and3.1701.

    It is thus not positive definite and not even positive semi-definite. But, one can show that thisproblem admits one solution (as shown in appendix A.1). This shows us that the minimum ofan optimization problem with constraints is not necessarily a minimum of the lagrange function.

    1

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    4/23

    2 Linear Electrical Networks: DC Analysis

    In this section, we explain and test a program that computes currents and potentials in electricalcircuits.

    2.1 Abstract of the program

    The function we implemented is of the form [e,iV]=dc_anal(AR,AV,AI,R,V,I) where:

    AR, AI, AV are the incidence matrices of the resistive, voltage source and current sourcebranches, respectively of dimensionsbR n, bV n and bI n,

    R, V, I are the vectors of the values of the resistors, voltage sources and current sources,respectively of length bR, bV and bI,

    e is the vector of node voltages of length n(excluding the ground node);

    iv is the vector of currents through the voltage source branches.

    In the program, we first define the following variables:

    1 dimR=s i z e( A R ) ;

    2 dimV=s i z e( A V ) ;

    3 n=dimR(2);

    4 bV=dimV(1);

    5 O= z e r o s ( b V , b V ) ;

    6 C= d i a g (1./R);

    Cnow contains the conductance of each resistive branch in its diagonal, provided that eachresistance is stricly positive.

    We then formulate the linear system and solve the following problem1.

    1 B = [ AR * C * A R - A V ; - A V O ] ;

    2 D=[AI*I;V];

    3 x=B\D;

    Finally, we check if there is actually a voltage source and we assign the correct values to theoutput variables. By default, if there are no voltage sources, iv is an empty matrix.

    1 e = x ( 1 : n ) ;

    2 i f bV>0

    3 iv=x(n+1:n+bV);

    4 e l s e

    5 iv = z e r o s(0,0);

    6 en d

    1As described in the course DN2266.

    2

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    5/23

    2.2 Analysis of a circuit

    Let us analyze the circuit given by figure 1. The values of the elements are: E = 10V,Rs= 0.001, Ra= 100,Rb =Rc=Rd= 10. The resistorRg varies between10 and 200.

    Figure 1: Analyzed Circuit . We do not assign any number at the arrow containing the voltagesource as it is the only source.

    We have n = 4, bR = 6, bI = 0 and bV = 1. The values of the input variables of the functiondc_anal.mare:

    AR =

    1 0 0 11 1 0 01 0 1 00 1 0 00 0 1 00 1 1 0

    AI = zeros(0,4)

    AV = 0 0 0 1R =

    Rs Ra Rb Rc Rd Rg

    V = EI = zeros(0,1)

    (7)

    The definitions ofIandAIare consistent forMATLAB, asATII= zeros(4,1)which makes sense

    since there is no current source.

    The current Ig in resistor Rg is computed by calculating |e3e2|

    Rg. The graph2 shows the current

    Igin resistorRgas a function of the value ofRg. TheMATLABfunctiondc_anal.mis in appendixA.3and the script circuit_solution.mthat computes the solution and displays the graph is

    in appendixA.4.

    3

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    6/23

    0 50 100 150 2000

    0.02

    0.04

    0.06

    0.08

    0.1

    0.12

    0.14

    0.16

    0.18

    Value of Resistor Rg (Ohms)

    CurrentIg(A)

    Figure 2: Plot of the current through resistor Rg as a function of the value ofRg. The graphis computed xith 1000 values ofRg.

    4

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    7/23

    3 The PageRank algorithm

    ThePageRank algorithmis a part of the graph theory since it uses a kind of adjacency matrices2.Each page corresponds to a node and there is a node from a page to another if respectivelythe first page references the second. Actually, the PageRank algorithm uses a normalizedadjacency matrix A RNN for Npages which is built such that :

    rowi : toward node i

    column j : from node j

    L(j) is the number of links from node j

    aij =

    1

    L(j) if there is a link from j to i

    1

    N if there is no link fromj

    0 otherwise

    The adjacency matrix Ais thus column-stochastic, i.e.N

    i=1 aij = 1 j N[1;N].

    First, we are going to study this property. Then, we will attempt to build a mathematicalmodel from the PageRank for the ranking of soccer teams.

    3.1 Column-stochastic matrix

    Here, we are going to observe particular properties of the product between a column-stochasticmatrix and a none-zero vector.

    First, we prove the proposition1.

    Proposition 1

    LetA be an n n column-stochastic matrix. Then,x Rn and||x|| = 0 andk 0 :ni=1(A

    kx)ini=1 xi

    = 1

    Proof : We prove this proposition in few steps :

    First thesis : IfA is column-stochastic, thenni=1(Ax)i =

    ni=1xi.

    Let A=a1 a2 . . . an

    , where ai is thei th column ofA.

    Then, (Ax)i =n

    l=1xl(al)i =

    i(Ax)i =

    i

    lxl(al)i =

    lxl

    i(al)i

    SinceA is column-stochastic,

    i(al)i = 1 =

    i(Ax)i =n

    i=1xi

    Second thesis : If A, B are column-stochastic, then AB is column-stochastic too.

    Let A=

    a11 a12 . . . a1na21

    ... . . .

    an1 . . . ann

    andB =

    b11 b12 . . . b1nb21

    ... . . .

    bn1 . . . bnn

    .

    Then, AB =

    ia1ibi1

    ia1ibi2 . . .

    ia1ibin

    ia2ibi1... . . .

    ianibi1 . . .

    ianibin

    2Here, it is a matrix A Rn s.t. aij represents the number of edge(s) from node j to node i.

    5

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    8/23

    = n

    m(AB)mn =

    m

    iamibin =

    ibin

    mami = 11, sinceA andB are column-

    stochastic.

    A is column stochastic ; A0 =Iis column-stochastic. Let us assumeA is column-stochastic.Third thesis : A+1 is column-stochastic.A+1 =AA is column-stochastic by using the result of the second thesis.

    Therefore, Ak

    is column-stochastic k 0 and then, by using the result of the first thesis, weprove the proposition.

    Now, we want to observe the relationship between w1 and w2 such that :

    limk

    Akxi = wi (8)

    for i= 1, 2 and where xi are non-negative vectors ofRn such that ||xi|| = 0.

    AsAis an n ncolumn-stochasticmatrix with all its entries strictly positive - by the Perron-Frobenius theorem (see appendix A.2) - we know that A has a single eigenvalue 1 = 1 suchthat 1 > i i= 1. Then, the limit of the expression (8) exists.

    We derive equation (8) in order to be able to use the proposition 1:

    limk

    nj=1

    (Akxi)j =n

    j=1

    (wi)j; i= 1, 2

    =

    j(w2

    )jlimk

    j(Akx2)j

    =

    j(w1

    )jlimk

    j(Akx1)j

    Therefore, we use the proposition1:

    j(w2)j

    limk

    j(x2)j

    =

    j(w1)j

    limk

    j(x1)j

    The denominators do not depend on k, the limits are thus obvious. We can thus derive therelationship between w1 and w2 :

    nj=1

    (w2)j =n

    j=1

    (w1)j n

    j=1(x2)jnj=1(x1)j

    (9)

    However, we can derive the relationship further. As we said, according to Perron-Frobeniustheorem, 1 is the eigenvalue of greater magnitude and it is unique. If we also assume thatw1 and w2 have a non-zero component in the direction of the eigenvector associated to theeigenvalue 1, then the limit of the expression (8) exists and is unique up to a normalizationfactor; let zbe this limit:

    = w1=z and w2=z

    As w1 and w2 have a non-zero component in the direction of z, we know that and are

    nonzero. Then, we have another relationship between w1 and w2 :

    w2 =

    w1=w1 (10)

    6

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    9/23

    We use expression (10) in (9) and we get3 :

    =

    nj=1(x2)jnj=1(x1)j

    (11)

    Finally, we use the expression (11) in (10) in order to get the relationship :

    w2=

    nj=1(x2)jnj=1(x1)j

    w1

    3.2 Ranking soccer teams

    In this point, we are wondering how we could ranknsoccer teams, knowing the results about allthe played games. There are n(n 1) games as there are two games between two same teams.We are going to use the graph theory in order to build mathematical model(s) about this matter.

    First, let :

    node i represents the i th team

    there existsoneedge< i;j >for eachlost games by the the i thteam against the j thteam

    We can build an adjacency matrix A for such a graph. From A, we attempt to build a column-stochastic matrix by dividing each column by its sum ; we thus get the B matrix.

    However even if it is quite rare, there could be a team which has never lost a game. Thenin the graph, the corresponding node would not have edge that starts from it. Therefore, the

    corresponding column of the adjacency matrix would be 0, and the sum of the elements of thiscolumn would be 0 and not 1 ! Besides, this example shows that the graph could be reducible4.Therefore, if ai the i th column ofA is 0, then bi should be

    1

    n. B matrix is then column-

    stochastic, but not necessarily irreducible5.Let us talk a little about irreducibility. IfArepresents the adjacency matrix of a graph and eka vector column with 1 on the k th position and 0 elsewhere, then :

    (Aek)i represents the number of ways composed of one single edge from node k towardnode i.

    (A2ek)i represents the number of ways composed of 2 edges, from node k toward node i.

    The first assertion is obvious6. The second one less. Let x:= Aek. Actually, ifxi is none-zero,it means there is/are xi way(s) of one edge from node k toward node i. Furthermore, if we lety := Ax and if yj is none-zero, it means there is/are yj way(s) of one edge from one of thereachable node xi toward node j. Therefore by combinatorial analysis,(A

    2ek)i represents thenumber of ways composed by 2 edges, from node k toward node i. In general, we can provethat (Alek)i represents the number of ways composed ofl edges, from node k toward node i.

    3Since||z|| = 0, we can simplify.4Not irreducible. A graph is irreducible if and only if every node is reachable from every node.5 e.g.: if two teams lose only between them and draw against the other one.6Aek = ak, the k th column ofA. Then, by definition ofA, we get the upper interpretation.

    7

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    10/23

    Proposition 2

    (Ak)ij is the number of paths of length k from j toi

    Proof :

    It is true fork= 1 (by definition ofA) Let us assume it is true for allk l 1 then

    (Al)ij = (Al1A)ij =

    ns=1

    (Al1)is(A)sj

    By induction, we know that (Al1)is is the number of paths of length l 1 from s to i and(A)sj is the number of paths of length 1 from j tos. As we compute the sum over alls, theresult is the number of paths of length k from j toi.

    In order to get an irreducible matrix, we could try to use G, the Google matrix :

    G:= B +1

    N

    1 1 . . . 1

    1 . . .

    ...1 1

    , [0; 1)

    Indeed, G is irreducible. Let us observe that G is column-stochastic ifB is.

    Anyway, we are going to use the B matrix for 2 real situations of ranking soccer teams : the

    Allsvenskanand the Premier League, both season 2012.

    WithMATLAB, we have the information about games in a n(n 1) 4matrix under the form [nrhome team ; nr away team ; home score ; away score]7. We can get the name of a team fromits number, thanks to a n 1 cell8. We can check the information by comparing the result ofthe MATLABscript (see appendixA.5) with the figure3 : we obtain exactly the same scores.

    7matches8team_names

    8

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    11/23

    Figure 3: Scores and ranking of soccer teams for season 2012. On the left, league table ofAllsvenskan ; on the right, Premier League.

    We wrote aMATLABscript (see appendixA.6) that executes the PageRank algorithm for the twosituations. Actually, the script builds the B matrix and then computes the ranking accordingto the PageRank algorithm and B matrix. We implemented a program to see ifB is column-stochastic : in each situation, B is column-stochastic9. In order to check ifB is reducible, weuse the conclusion of our discussion about irreducibility. Let S :=

    ni=1 B

    i. If at least oneentry of S is 0, then S is not irreducible. Otherwise, S is irreducible. The longest needed

    way to run between two nodes contains indeed nedges. If it contains more, it would mean wego through a same node (at least) twice. Our script applies this test : in both situations, Bmatrix is irreducible. For these cases, we do not need to use a damp factor = 0 in order toget irreducible matrices as Bs are irreducible here.

    Now, we can compare the ranking to the PageRank algorithm (see tables1and2) and this tothe league tables (see figure3).

    9It is not a surprise according to the construction of the B matrix.

    9

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    12/23

    Rank According to the PageRank According to the league table1st IF Elfsborg IF Elfsborg2nd Malm FF BK Hcken3rd BK Hcken Malm FF4th IFK Norrkping AIK5th AIK IFK Norrkping

    Table 1: League Allsvenskan. Comparison between the ranking from PageRank algorithm andfrom league table (see figure3).

    Rank According to the PageRank According to the league table1st Chelsea Manchester United2nd Manchester United Manchester City3rd Manchester City Chelsea4th Tottenham Hotspur Arsenal

    5th

    Everton Tottenham HotspurTable 2: League Premier League. Comparison between the ranking from PageRank algorithmand from league table (see figure 3).

    We observe we do not obtain the same ranking for both leagues :

    Allsvenskan : the first one is the same but the second and third are switched, as thefourth and fifth

    Premier League : it is quite shuffled

    in comparison with the point-based rank.

    Now, we are going to see the ranking we obtain with some variants of the PageRank algorithm:

    1. if it is draw between the away team i and home team j : aij = 0.5

    2. if home team j loses against the away team i : aij = 2if home team j wins against the away team i : aji = 1if it is draw between the away team i and home team j : aij = 0.5

    3. if team i wins against team j : aij = margin in terms of goals scored

    if it is draw between the away team i and home team j : aij = 0.5

    4. if home team j loses against the away team i : aij = double margin in terms of goalsscoredif home team j wins against the away team i : aji = margin in terms of goals scoredif it is draw between the away team i and home team j : aij = 0.5

    We wrote MATLAB scripts that computes the ranking according to a variant (see respectivelyappendixA.7,A.8,A.9andA.10). The ranking of league Allsvenskan is available in the table3and this of Premier League in the table4.

    10

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    13/23

    Rank PageRank Variant 1 Variant 2 Variant 3 Variant 4

    1st IF Elfsborg IF Elfsborg BK Hcken BK Hcken BK Hcken2nd Malm FF Malm FF AIK Malm FF Malm FF3rd BK Hcken BK Hcken IFK Norrkping IF Elfsborg IF Elfsborg4th IFK Norrkping AIK IF Elfsborg AIK AIK5th AIK IFK Norrkping Malm FF Helsingborgs IF Kalmar FF

    Table 3: Different rankings for the league Allsvenskan. The variants are described upper.

    Rank PageRank Variant 1 Variant 2 Variant 3 Variant 4

    1st Chelsea Manchester United Chelsea Chelsea Chelsea2nd Manchester U Chelsea Manchester U Manchester C Manchester C3rd Manchester C Manchester C Manchester C Manchester U Manchester U4th Tottenham H Everton Tottenham H Tottenham H Tottenham H5th Everton Tottenham H Everton Everton Arsenal

    Table 4: Different rankings for the league Premier League. The variants are described upper.

    We observe that we generally obtain the same five first teams, even if there are switches betweenthem. Therefore, these variants do not have an effect on the global ranking. Their effects tendto be more local. Anyway, for each variant (and for these 2 leagues), theB matrix is alwayscolumn-stochastic and irreducible10.

    With respect to these tests, can we say that PageRank is a reasonable ranking algorithm forsoccer leagues? Is this algorithm efficient regarding the expectations of the teams and the

    public? Here are a few strenths and weaknesses of this method:

    Strengths:

    It is supposed to reflect the real level of the teams, regardless of the circumstances ofevery match. The ranking we obtain is the most likely if the competition is started againan infinite number of times.

    It is easy to modify the properties of the ranking: for instance, take the draws intoaccount).

    Weaknesses:

    The number of points we attribute to team after a match is based on reasonable ideasbut not on an absolute truth: Why do we attribute 0.5 point to one team for a draw?Why not 0.75 points?

    The levels of the teams are evolving with time. One might think it is thus not reasonableto consider the most likely ranking after an infinite number of competitions.

    To conclude, we may compare the application of PageRank algorithm in this case to its initial

    use by Google. Starting with a vector x with 1n in all its entries, multiplying it one time byA, we obtain the results after one competition (as the pointbased method if we calculate the

    10Checking with our MATLAB scripts.

    11

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    14/23

    points in the same way as when we build matrix A). limk

    Akx gives the ranking if we organize

    an infinite number of competitions11. The bored surfer we talk about in Googles PageRankalgorithm can be viewed as the soccer cup in this case that goes from one team to another aftereach step and gives the winner ultimately. But is this way of thinking right ? Following a linkfor a surfer is easy and quick but organizing a soccer competition is very slow and the levels ofthe teams may vary deeply from one competition to the other due to the exchanges of playersbetween teams. Nevertheless, this ranking gives interesting information because it estimatesthe actual levels of the teams.

    11More accurately, as the number of competitions tends to infinity.

    12

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    15/23

    A Appendix

    A.1 Existence of a minimum

    In this section, we explain why the problem described in section 1 admits at least one solution.The general outlines of the proof are shown but not the details of it.

    The matrix ATA is of full rank (rank(ATA) =rank(A) =n) thus, according to a property oflinear algebra,ATAis positive definite. Thus, the function f(x) = 1

    2Ax a22=

    12

    xTATAxis aconvex quadratic function. The constraint of the problem can be written as g(x) =C x c= 0where g is an affine function. The optimization is thus a convex problem and every localminimum is also a global minimum. Let us show that the problem has at least one localminimum. For a certain real number k, we consider the following set:

    X={x Rn : Ax a k and Cx= c} (12)

    One can show that, for a sufficiently large value of k, this set is closed, bounded and non-empty.

    As f is continuous on this set, it has one minimum and one maximum value on the set. Onecan also show that for a sufficiently large value ofk, this local minimum is necessarily found fora value of x such that Ax a< k. Thus, this local minimum is also a local minimum of theoptimization problemmin f(x) with g(x) = 0. As the problem is convex, this local minimumis also a global minimum.

    A.2 Perron-Frobenius Theorem

    References : [Wikipedia - Perron-Frobenius theorem ] (last modifcation : September 23rd 2013)

    Theorem 1 (Perron-Frobenius Theorem for irreducible matrices)

    Let A be an irreducible non-negativen n matrix and spectral radius(A) =r.Then, r R+ is an eigenvalue of the matrix A, called the Perron-Frobenius eigenvalue.Besides,r is unique.

    A.3 dc_anal.m

    1 f u n c t i o n [ e , i v ] = d c _ a na l ( A R , A V , AI , R , V , I )

    2 % d c _a n al : c o mp u te s t he c u rr e nt i n a b r an c h o f a g iv e n c i rc u it

    3 %4 % @INPUT :

    5 % A R , AV , A I a r e r e s p e ct i ve l y t h e i n c i de n ce m a tr i ce s o f r e si s ta n ce s ,

    6 % v ol ta ge s ou rc es a nd c ur re nt s ou rc es . R i s a v e ct or c on ta in in g t h e

    7 % r es is ta nc es o f t he r es is ti ve b ra nc he s . V c on ta in s t h e p o t en ti al

    8 % d if fe re nc e o f e a ch v ol ta ge s ou rc e a nd I c on ta in s t he v al ue o f t h e

    9 % c ur re nt o f ea ch c ur re nt s o uc e.

    10 %

    11 % @OUTPUT :

    12 % e i s t he t en si on a t e ac h n od e ( as d ef in ed by th e o rd er of t he c ol um ns

    13 % o f t he i nc id en ce m at ri ce s ) . i v c o nt ai ns t he c ur re nt s i n e ac h v o lt ag e

    14 % source .

    15 %

    16 % F or m or e i n f or ma ti on a bo ut t he d im en si on s o f t h e d at a s , s e e t he

    17 % r el at ed pa per .

    18

    19 % % N u mb e r o f r e si s ti v e b r an c he s a nd v o lt a ge s o ur c es

    20 dimR=s i z e( A R ) ;

    21 dimV=s i z e( A V ) ;

    13

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    16/23

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    17/23

    10 n = l e n g t h ( t e a m _ n a m e s ) ;

    11

    12 s c or e = z e r o s ( n , 1 ) ;% t o ta l p o in t s o f e a ch t ea m

    13 W = s co re ; % n u mb e r o f w i nn e d g a me s

    14 D = W; % n u mb e r o f t ie d g a me s

    15 L = D; % n u mb e r o f l os t g a me s

    16 GF = L ; % n u mb e r o f g o al s : - )

    17 GA = G F; % n u mb e r o f g o al s : - (

    18

    19 f o r i = 1 : n * ( n - 1 )

    20

    21 G F ( m a t ch e s ( i , 1 ) ) = G F ( m a t c he s ( i , 1 ) ) + m a t c he s ( i , 3 ) ;

    22 G F ( m a t ch e s ( i , 2 ) ) = G F ( m a t c he s ( i , 2 ) ) + m a t c he s ( i , 4 ) ;

    23 G A ( m a t ch e s ( i , 1 ) ) = G A ( m a t c he s ( i , 1 ) ) + m a t c he s ( i , 4 ) ;

    24 G A ( m a t ch e s ( i , 2 ) ) = G A ( m a t c he s ( i , 2 ) ) + m a t c he s ( i , 3 ) ;

    25

    26 i f m a t c h e s ( i , 3) > m a t c he s ( i , 4 )

    27 s c o re ( m a t c h e s ( i , 1) ) = s c o re ( m a t c h e s ( i , 1) ) + 3 ;

    28 W ( m at c he s ( i ,1 ) ) = W ( m at c he s ( i , 1) ) + 1 ;

    29 L ( m at c he s ( i ,2 ) ) = L ( m at c he s ( i , 2) ) + 1 ;

    30

    31 e l s e i f m a t c h e s ( i , 3) < m a t c he s ( i , 4 )

    32 s c o re ( m a t c h e s ( i , 2) ) = s c o re ( m a t c h e s ( i , 2) ) + 3 ;

    33 W ( m at c he s ( i ,2 ) ) = W ( m at c he s ( i , 2) ) + 1 ;34 L ( m at c he s ( i ,1 ) ) = L ( m at c he s ( i , 1) ) + 1 ;

    35

    36 e l s e

    37 s c or e ( m at c he s ( i ,1 ) ) = s c or e ( m at c he s ( i , 1) ) + 1 ;

    38 s c or e ( m at c he s ( i ,2 ) ) = s c or e ( m at c he s ( i , 2) ) + 1 ;

    39 D ( m a tc h es ( i , 1) ) = D ( m a tc h es ( i , 1) ) + 1 ;

    40 D ( m a tc h es ( i , 2) ) = D ( m a tc h es ( i , 2) ) + 1 ;

    41 en d

    42

    43 en d

    44

    45

    46 GD = GF - GA ; % g o a l d i f f e re n c e

    47 [result, rank ] = s o r t ( s c o r e , d e s c e n d );

    48

    49 f o r i = 1 : n

    50

    51 f p r i n t f ([team_names{ rank (i)} : W = num 2str (W ( rank ( i ) ) ) ] ) ;

    52 f p r i n t f ( [ - D = num 2str (D ( rank (i)))]);

    53 f p r i n t f ( [ - L = num 2str (L ( rank (i)))]);

    54 f p r i n t f ( [ - W F = num 2str ( L( rank (i)))]);

    55 f p r i n t f ( [ - G F = num 2str ( G F ( rank (i)))]);

    56 f p r i n t f ( [ - G A = num 2str ( G A ( rank (i)))]);

    57 f p r i n t f ( [ - G D = num 2str ( G D ( rank (i)))]);

    58 f p r i n t f ( [ - PTS = num 2str ( s c o r e (rank (i)))]);

    59 f p r i n t f ( \n );

    60

    61 en d

    A.6 DN2266_lab2_Q3b.m

    1 % t h is s c ri p t a p pl i es t he p a ge R an k a l go r it h m t o a s et o f l o ad e d d a ta s

    2 %%

    3

    4 % l o a d ( A l l s v e n s k a n 2 0 1 2 d a t a . m a t ) ;

    5 l o a d ( P r e m i e r L e a g u e 2 0 1 2 d a t a . m a t );

    6 n = l e n g t h ( t e a m _ n a m e s ) ;

    7 A = z e r o s ( n , n ) ;

    8 f o r i = 1 : n * ( n - 1 )

    9

    10 % h om e t ea m w in s

    11 i f m a t c h e s ( i , 3) > m a t c he s ( i , 4 )

    12

    15

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    18/23

    13 A ( m a t c h es ( i , 1 ) , m a t c h es ( i , 2 ) ) = A ( m a t c h es ( i , 1 ) , m a t c he s ( i , 2 ) ) + 1 ;

    14

    15 % a wa y t e am l o se s

    16 e l s e i f m a t c h e s ( i , 3) < m a t c he s ( i , 4 )

    17

    18 A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) = A ( m a t c he s ( i , 2 ) , m a t c he s ( i , 1 ) ) + 1 ;

    19

    20 en d

    21

    22 en d

    23

    24 % n o r m a l i z a t i on

    25 D = sum( A ) ;

    26 D ( D == 0 ) = 1 / n;

    27

    28 A = A . / ( D * on es ( 1, n )) ;

    29

    30 %%checking column -stochastic

    31 S u m C o lu m n A = sum(A);

    32

    33 i f m in(SumColumnA~=1)

    34 f p r i n t f ( A i s n ot c ol um n - s t o ch a st i c \ n );

    35 e l s e

    36 f p r i n t f ( A i s c ol um n - s t o ch a st i c \ n ) ;37 en d

    38

    39

    40 % % c h e c k in g i r r e d uc i b l e

    41 S u m P o w A = z e r o s (s i z e( A ) ) ;

    42 f o r i = 1 : n

    43

    44 S u mP o wA = S u mP o wA + A ^ i ;

    45

    46 en d

    47

    48 i f max(max( S u m P o w A = = 0 ) )

    49 f p r i n t f ( A i s n ot i r re d uc i bl e \ n ) ;

    50 e l s e

    51 f p r i n t f ( A i s i r re d uc i bl e \ n ) ;

    52 en d

    53

    54 %%ranking

    55 x ne w = o n es ( n , 1) ;

    56 x ne w = x n ew /norm ( x n e w ) ;

    57 x ol d = x ne w + 1;

    58

    59 w h i l e m ax( a bs ( x ne w - x o ld ) ) > 1 e -4

    60 x o ld = x ne w ;

    61 x n ew = A * x ol d ;

    62 x n ew = x ne w /norm( x n e w ) ;

    63 en d

    64

    65 [ v al , I ] = s o r t (xnew, d e s c e n d ) ;66

    67 f o r i = 1: 5

    68 f p r i n t f ( [ P la ce # num 2str ( i) : ]) ;

    69 d i s p (team_names{I(i)})

    70 f p r i n t f ( \n );

    71 en d

    A.7 DN2266_lab2_Q3c1.m

    1

    % t h is s c ri p t a p p l ie s t he 1 s t v a r i an t o f t h e p a ge R an k a l go r it h m t o a s et o f2 % l o a d ed d at a s

    3 %%

    4

    5 % l o a d ( A l l s v e n s k a n 2 0 1 2 d a t a . m a t ) ;

    16

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    19/23

    6 l o a d ( P r e m i e r L e a g u e 2 0 1 2 d a t a . m a t );

    7 n = l e n g t h ( t e a m _ n a m e s ) ;

    8 A = z e r o s ( n , n ) ;

    9 f o r i = 1 : n * ( n - 1 )

    10

    11 % h om e t ea m w in s

    12 i f m a t c h e s ( i , 3) > m a t c he s ( i , 4 )

    13

    14 A ( m a t c h es ( i , 1 ) , m a t c h es ( i , 2 ) ) = A ( m a t c h es ( i , 1 ) , m a t c he s ( i , 2 ) ) + 1 ;15

    16 % a wa y t e am l o se s

    17 e l s e i f m a t c h e s ( i , 3) < m a t c he s ( i , 4 )

    18

    19 A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) = A ( m a t c he s ( i , 2 ) , m a t c he s ( i , 1 ) ) + 1 ;

    20

    21 % d ra w

    22 e l s e

    23

    24 A ( m a t c h es ( i , 2 ) , m a t c h es ( i , 1 ) ) = A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) + . 5 ;

    25

    26 en d

    27

    28 en d

    29

    30 %normalization

    31 D = sum( A ) ;

    32 D ( D == 0 ) = 1 / n;

    33

    34 A = A . / ( D * on es ( 1, n )) ;

    35

    36 % % c h e c ki n g c o l u m n - s t o c h a s ti c

    37 S u m C o lu m n A = sum(A);

    38 i f m in(SumColumnA~=1)

    39 f p r i n t f ( A i s n ot c ol um n - s t o ch a st i c \ n );

    40 e l s e

    41 f p r i n t f ( A i s c ol um n - s t o ch a st i c \ n ) ;

    42 en d

    43

    44 % % c h e c k i n g i r r e d u c i b le

    45 S u m P o w A = z e r o s (s i z e( A ) ) ;

    46 f o r i = 1 : n

    47

    48 S u mP o wA = S u mP o wA + A ^ i ;

    49

    50 en d

    51

    52

    53 i f max(max( S u m P o w A = = 0 ) )

    54 f p r i n t f ( A i s n ot i r re d uc i bl e \ n ) ;

    55 e l s e

    56 f p r i n t f ( A i s i r re d uc i bl e \ n ) ;

    57 en d

    58

    59 % % r a n ki n g

    60

    61 x ne w = o n es ( n , 1) ;

    62 x ne w = x n ew /norm ( x n e w ) ;

    63 x ol d = x ne w + 1;

    64

    65 w h i l e m ax( a bs ( x ne w - x o ld ) ) > 1 e -4

    66 x o ld = x ne w ;

    67 x n ew = A * x ol d ;

    68 x n ew = x ne w /norm( x n e w ) ;

    69 en d

    70

    71 [ v al , I ] = s o r t (xnew, d e s c e n d ) ;

    72

    73 f o r i = 1: 574 f p r i n t f ( [ P la ce # num 2str ( i) : ]) ;

    75 d i s p (team_names{I(i)})

    76 f p r i n t f ( \n );

    17

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    20/23

    77 en d

    A.8 DN2266_lab2_Q3c2.m

    1 % t h is s c ri p t a p p l ie s t he 2 n d v a r i an t o f t h e p a ge R an k a l go r it h m t o a s et o f

    2 % l o a d ed d at a s

    3 %%

    4

    5 % l o a d ( A l l s v e n s k a n 2 0 1 2 d a t a . m a t ) ;

    6 l o a d ( P r e m i e r L e a g u e 2 0 1 2 d a t a . m a t );

    7 n = l e n g t h ( t e a m _ n a m e s ) ;

    8 A = z e r o s ( n , n ) ;

    9 f o r i = 1 : n * ( n - 1 )

    10

    11 % h om e t ea m w in s

    12 i f m a t c h e s ( i , 3) > m a t c he s ( i , 4 )

    13

    14 A ( m a t c h es ( i , 1 ) , m a t c h es ( i , 2 ) ) = A ( m a t c h es ( i , 1 ) , m a t c he s ( i , 2 ) ) + 1 ;

    15

    16 % a wa y t e am l o se s

    17 e l s e i f m a t c h e s ( i , 3) < m a t c he s ( i , 4 )

    18

    19 A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) = A ( m a t c he s ( i , 2 ) , m a t c he s ( i , 1 ) ) + 2 ;

    20

    21 % d ra w

    22 e l s e

    23

    24 A ( m a t c h es ( i , 2 ) , m a t c h es ( i , 1 ) ) = A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) + . 5 ;

    25

    26 en d

    27

    28 en d

    29

    30 %normalization31 D = sum( A ) ;

    32 D ( D == 0 ) = 1 / n;

    33

    34 A = A . / ( D * on es ( 1, n )) ;

    35

    36 % % c h e c ki n g c o l u m n - s t o c h a s ti c

    37 S u m C o lu m n A = sum(A);

    38

    39 i f m in(SumColumnA~=1)

    40 f p r i n t f ( A i s n ot c ol um n - s t o ch a st i c \ n );

    41 e l s e

    42 f p r i n t f ( A i s c ol um n - s t o ch a st i c \ n ) ;

    43 en d

    44

    45 % % c h e c k i n g i r r e d u c i b le

    46 S u m P o w A = z e r o s (s i z e( A ) ) ;

    47 f o r i = 1 : n

    48

    49 S u mP o wA = S u mP o wA + A ^ i ;

    50

    51 en d

    52

    53

    54 i f max(max( S u m P o w A = = 0 ) )

    55 f p r i n t f ( A i s n ot i r re d uc i bl e \ n ) ;

    56 e l s e

    57 f p r i n t f ( A i s i r re d uc i bl e \ n ) ;

    58 en d

    59

    60 % % r a n ki n g

    61

    62 x ne w = o n es ( n , 1) ;

    63 x ne w = x n ew /norm ( x n e w ) ;

    18

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    21/23

    64 x ol d = x ne w + 1;

    65

    66 w h i l e m ax( a bs ( x ne w - x o ld ) ) > 1 e -4

    67 x o ld = x ne w ;

    68 x n ew = A * x ol d ;

    69 x n ew = x ne w /norm( x n e w ) ;

    70 en d

    71

    72 [ v al , I ] = s o r t (xnew, d e s c e n d ) ;73

    74 f o r i = 1: 5

    75 f p r i n t f ( [ P la ce # num 2str ( i) : ]) ;

    76 d i s p (team_names{I(i)})

    77 f p r i n t f ( \n );

    78 en d

    A.9 DN2266_lab2_Q3c3.m

    1

    % t h is s c ri p t a p p l ie s t he 3 r d v a r i an t o f t h e p a ge R an k a l go r it h m t o a s et o f2 % l o a d ed d at a s

    3 %%

    4

    5 % l o a d ( A l l s v e n s k a n 2 0 1 2 d a t a . m a t ) ;

    6 l o a d ( P r e m i e r L e a g u e 2 0 1 2 d a t a . m a t );

    7 n = l e n g t h ( t e a m _ n a m e s ) ;

    8 A = z e r o s ( n , n ) ;

    9 f o r i = 1 : n * ( n - 1 )

    10

    11 % m a rg i n g o al s

    12 d e lt a = ma t ch e s (i , 3 ) - m a tc h es ( i , 4) ;

    13

    14 % h om e t ea m w in s

    15 i f d e lt a > 0

    16

    17 A ( m a t c h es ( i , 1 ) , m a t c h es ( i , 2 ) ) = A ( m a t c h es ( i , 1 ) , m a t c he s ( i , 2 ) ) + d e l ta ;

    18

    19 % a wa y t e am l o se s

    20 e l s e i f d e lt a < 0

    21

    22 A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) = A ( m a t c he s ( i , 2 ) , m a t c he s ( i , 1 ) ) - d e l ta ;

    23

    24 % d ra w

    25 e l s e

    26

    27 A ( m a t c h es ( i , 2 ) , m a t c h es ( i , 1 ) ) = A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) + 0 . 5 ;

    28

    29 en d

    30

    31 en d

    32

    33 %normalization

    34 D = sum( A ) ;

    35 D ( D == 0 ) = 1 / n;

    36

    37 A = A . / ( D * on es ( 1, n )) ;

    38

    39 % % c h e c ki n g c o l u m n - s t o c h a s ti c

    40 S u m C o lu m n A = sum(A);

    41

    42 i f m in(SumColumnA~=1)

    43 f p r i n t f ( A i s n ot c ol um n - s t o ch a st i c \ n );

    44 e l s e

    45 f p r i n t f ( A i s c ol um n - s t o ch a st i c \ n ) ;

    46 en d

    47

    48

    49 % % c h e c k i n g i r r e d u c i b le

    19

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    22/23

    50 S u m P o w A = z e r o s (s i z e( A ) ) ;

    51 f o r i = 1 : n

    52

    53 S u mP o wA = S u mP o wA + A ^ i ;

    54

    55 en d

    56

    57

    58 i f max(max( S u m P o w A = = 0 ) )59 f p r i n t f ( A i s n ot i r re d uc i bl e \ n ) ;

    60 e l s e

    61 f p r i n t f ( A i s i r re d uc i bl e \ n ) ;

    62 en d

    63

    64 % % r a n ki n g

    65

    66 x ne w = o n es ( n , 1) ;

    67 x ne w = x n ew /norm ( x n e w ) ;

    68 x ol d = x ne w + 1;

    69

    70 w h i l e m ax( a bs ( x ne w - x o ld ) ) > 1 e -4

    71 x o ld = x ne w ;

    72 x n ew = A * x ol d ;

    73 x n ew = x ne w /norm( x n e w ) ;74 en d

    75

    76 [ v al , I ] = s o r t (xnew, d e s c e n d ) ;

    77

    78 f o r i = 1: 5

    79 f p r i n t f ( [ P la ce # num 2str ( i) : ]) ;

    80 d i s p (team_names{I(i)})

    81 f p r i n t f ( \n );

    82 en d

    A.10 DN2266_lab2_Q3c4.m

    1 % t h is s c ri p t a p p l ie s t he 4 t h v a r i an t o f t h e p a ge R an k a l go r it h m t o a s et o f

    2 % l o a d ed d at a s

    3 %%

    4

    5 % l o a d ( A l l s v e n s k a n 2 0 1 2 d a t a . m a t ) ;

    6 l o a d ( P r e m i e r L e a g u e 2 0 1 2 d a t a . m a t );

    7 n = l e n g t h ( t e a m _ n a m e s ) ;

    8 A = z e r o s ( n , n ) ;

    9 f o r i = 1 : n * ( n - 1 )

    10

    11 % m a rg i n g o al s

    12 d e lt a = ma t ch e s (i , 3 ) - m a tc h es ( i , 4) ;

    13

    14 % h om e t ea m w in s

    15 i f d e lt a > 0

    16

    17 A ( m a t c h es ( i , 1 ) , m a t c h es ( i , 2 ) ) = A ( m a t c h es ( i , 1 ) , m a t c he s ( i , 2 ) ) + d e l ta ;

    18

    19 % a wa y t e am l o se s

    20 e l s e i f d e lt a < 0

    21

    22 A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) = A ( m a t c he s ( i , 2 ) , m a t c he s ( i , 1 ) ) - 2 * d e l ta ;

    23

    24 % d ra w

    25 e l s e

    26

    27

    A ( m a t c h es ( i , 2 ) , m a t c h es ( i , 1 ) ) = A ( m a t c h es ( i , 2 ) , m a t c he s ( i , 1 ) ) + . 5 ;28

    29 en d

    30

    31 en d

    20

  • 8/12/2019 "Equilibrium Problems and Circuit Analysis"

    23/23

    32

    33 %normalization

    34 D = sum( A ) ;

    35 D ( D == 0 ) = 1 / n;

    36

    37 A = A . / ( D * on es ( 1, n )) ;

    38

    39 % % c h e c ki n g c o l u m n - s t o c h a s ti c

    40 S u m C o lu m n A = sum(A);41

    42 i f m in(SumColumnA~=1)

    43 f p r i n t f ( A i s n ot c ol um n - s t o ch a st i c \ n );

    44 e l s e

    45 f p r i n t f ( A i s c ol um n - s t o ch a st i c \ n ) ;

    46 en d

    47

    48 % % c h e c k i n g i r r e d u c i b le

    49 S u m P o w A = z e r o s (s i z e( A ) ) ;

    50 f o r i = 1 : n

    51

    52 S u mP o wA = S u mP o wA + A ^ i ;

    53

    54 en d

    55

    56

    57 i f max(max( S u m P o w A = = 0 ) )

    58 f p r i n t f ( A i s n ot i r re d uc i bl e \ n ) ;

    59 e l s e

    60 f p r i n t f ( A i s i r re d uc i bl e \ n ) ;

    61 en d

    62

    63 % % r a n ki n g

    64

    65 x ne w = o n es ( n , 1) ;

    66 x ne w = x n ew /norm ( x n e w ) ;

    67 x ol d = x ne w + 1;

    68

    69 w h i l e m ax( a bs ( x ne w - x o ld ) ) > 1 e -4

    70 x o ld = x ne w ;

    71 x n ew = A * x ol d ;

    72 x n ew = x ne w /norm( x n e w ) ;

    73 en d

    74

    75 [ v al , I ] = s o r t (xnew, d e s c e n d ) ;

    76

    77 f o r i = 1: 5

    78 f p r i n t f ( [ P la ce # num 2str ( i) : ]) ;

    79 d i s p (team_names{I(i)})

    80 f p r i n t f ( \n );

    81 en d