Linear Algebra and the C Language/a04g


Network analysis

We can write:

           Input = Output
A = x1           = 20 + x2
B = x2 + x3 + x5 = 60
C = x4           = 20 + x3
D = 100          = x1 + x4 + x5


We write: x2 = 10 and x5 = 30

A = x1           = 20 + 10
B = 10 + x3 + 30 = 60
C = x4           = 20 + x3
D = 100          = x1 + x4 + 30


Let's rectify the system

 x1           =   20 + 10
 x3           =   60 - 10 -30
 x4 - x3      =   20
-x1 - x4      = -100 + 30

Now:

     x1       +0      +0        +0      20 + 10       // A
     +0       x3      +0        +0      60 - 10 -30   // B
     +0      -x3      x4        +0      +20           // C
    -x1       +0     -x4        +0     -100 + 30      // D

The code in C language:

double ab[RA*(CA+Cb)]={
//  x1   x3   x4       
    +1,  +0,  +0,  +0,  +20+10,      // A
    +0,  +1,  +0,  +0,  +60 -10 -30, // B   
    +0,  -1,  +1,  +0,  +20,         // C
    -1,  +0,  -1,  +0,  -100+30,     // D  
};


The solution is given by solving the system:

  x1    x3    x4 
  +1    +0    +0    +0   +30 
  +0    +1    +0    +0   +20 
  +0    +0    +1    +0   +40 
  +0    +0    +0    +0    +0 
  x1 = +30;    x3 = +20;    x4 = +40;
  
 With      x2 = +10;    x5 = +30;