Support our Blind Hand Charity by donating at 9818291723. Your contribution has the potential to bring about significant positive change for humanity.

Search This Blog

Saturday, March 8, 2025

SOLUTION OF LINEAR EQUATION IN 3 VARIABLE

print("Enter the value of coefficients of ax₁+by₁+cz₁=d₁")

a1=int(input("Enter the coefficient of x₁ = "))

b1=int(input("Enter the coefficient of y₁ = "))

c1=int(input("Enter the coefficient of z₁ = "))

d1=int(input("Enter the value of d₁ = "))


print("Enter the value of coefficients of ax₂+by₂+cz₂=d₂")

a2=int(input("Enter the coefficient of x₂ = "))

b2=int(input("Enter the coefficient of y₂ = "))

c2=int(input("Enter the coefficient of z₂ = "))

d2=int(input("Enter the value of d₂ = "))


print("Enter the value of coefficients of ax₃+by₃+cz₃=d₃")

a3=int(input("Enter the coefficient of x₃ = "))

b3=int(input("Enter the coefficient of y₃ = "))

c3=int(input("Enter the coefficient of z₃ = "))

d3=int(input("Enter the value of d₃ = "))


a=[[a1,b1,c1],[a2,b2,c2],[a3,b3,c3]]

x=[]

b=[d1,d2,d3]

mij=[[],[],[]]

for n in range(0,3):

    for i in range(0,3):

        sa=[]

        mul=0

        for j in range(0,3):

            for k in range(0,3):

                if k!=n and j!=i:

                    sa.append(a[j][k])

        mul+=sa[0]*sa[3]-sa[1]*sa[2]

        mij[i].append(mul)


cij=[[],[],[]]

for i in range(0,3):

    for j in range(0,3):

        cij[i].append(mij[i][j]*(-1)**(i+j))


adja=[[],[],[]]

for i in range(0,3):

    for j in range(0,3):

        adja[j].append(cij[i][j])


det=a[0][0]*mij[0][0]-a[0][1]*mij[0][1]+a[0][2]*mij[0][2]


val=[]

for i in range(0,3):

    pr=0

    for j in range(0,3):

        pr+=adja[i][j]*b[j]

    val.append(pr)

print()

vr=['x','y']

for i in range(0,3):

    for j in range(0,2):

        if a[i][j]==abs(a[i][j]):

            print(a[i][j],vr[j]+'+',end='',sep='')

        else:

            print(a[i][j],vr[j]+'-',end='',sep='')

    print('z=',b[i],sep='')

print()

print("A")

for i in range(0,3):

    for j in range(0,3):

        print(a[i][j],end=' ')

    print()

print()

print("|A| =",det)

print("\nMij")

for i in range(0,3):

    for j in range(0,3):

        print(mij[i][j],end=' ')

    print()


print("\nCij")

for i in range(0,3):

    for j in range(0,3):

        print(cij[i][j],end=' ')

    print()


print("\nAdj(A)")

for i in range(0,3):

    for j in range(0,3):

        print(adja[i][j],end=' ')

    print()


if det==0:

    print("\nB")

    for i in range(0,3):

        print(b[i])

    print()

    print("\nAdj(A)B")

    for i in range(0,3):

        print(val[i])

    print()

    if val[0]==val[1]==val[2]==0:

        print("The system is consistent")

        print("It has infinite solution")

    else:

        print("The system is inconsistent")

        print("It has no solution")

else:

    a_1=[[],[],[]]

    for i in range(0,3):

        for j in range(0,3):

            a_1[i].append(round(adja[i][j]/det,2))

    print()

    print("\nA-¹")

    for i in range(0,3):

        for j in range(0,3):

            print(a_1[i][j],end=' ')

        print()

    print("\nA-¹B")

    print(round(val[0]/det,2))

    print(round(val[1]/det,2))

    print(round(val[2]/det,2))

    print()

    print("The system is consistent")

    print("It has unique solution")

    print()

    print("X =",round(val[0]/det,2))

    print("Y =",round(val[1]/det,2))

    print("Z =",round(val[2]/det,2))