File size: 1,319 Bytes
389d072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from visma.io.tokenize import tokenizer
from visma.matrix.structure import SquareMat


def cramerMatrices(coefficients):
    '''
    Arguments:
    coefficients -- 3 X 4 list -- each each row contains coefficients for x, y, z and constant term respectively

    Returns:
    Dx, Dy, Dz, D -- 3 X 4 list -- Cramer's Matrices for implementing Cramer's Rule.
    '''
    D = [[0] * 3 for _ in range(3)]
    Dx = [[0] * 3 for _ in range(3)]
    Dy = [[0] * 3 for _ in range(3)]
    Dz = [[0] * 3 for _ in range(3)]
    for i in range(3):
        for j in range(3):
            D[i][j] = coefficients[i][j]
            Dx[i][j] = coefficients[i][j]
            Dy[i][j] = coefficients[i][j]
            Dz[i][j] = coefficients[i][j]
    for k in range(3):
        Dx[k][0] = coefficients[k][3]
        Dy[k][1] = coefficients[k][3]
        Dz[k][2] = coefficients[k][3]
    for i in range(3):
        for j in range(3):
            D[i][j] = tokenizer(str(D[i][j]))
            Dx[i][j] = tokenizer(str(Dx[i][j]))
            Dy[i][j] = tokenizer(str(Dy[i][j]))
            Dz[i][j] = tokenizer(str(Dz[i][j]))
    matD = SquareMat()
    matD.value = D
    matDx = SquareMat()
    matDx.value = Dx
    matDy = SquareMat()
    matDy.value = Dy
    matDz = SquareMat()
    matDz.value = Dz
    return matD, matDx, matDy, matDz