Linear Equations — Solve by CREMER RULE
How To Use Python to Solve Linear System #PySeries#Episode 33
To solve a system of linear equations we going to use this methods:
CREMER RULE
Cramer’s rule is an explicit formula for the solution of a system of linear equations with as many equations as unknowns, valid whenever the system has a unique solution. It expresses the solution in terms of the determinants of the (square) coefficient matrix and of matrices obtained from it by replacing one column by the column vector of right-hand-sides of the equations. (from https://en.wikipedia.org/wiki/Cramer%27s_rule)
Here is the problem to solve:
THE PROBLEM EQUATIONS SYSTEMS
A production engineer from an electronics industry analyzes an industrial process in which he considers the assembly time (t), the number of employees (x) and the number of components (n) used in the final product, and reached this system of equations.
The system equation to solve in this methods: CREMER RULE
The engineer wants to reach an ideal condition for all goals to be achieved, with an estimated accuracy of 0.01 (one hundredth of each variable).
HOW TO SOLVE THIS PROBLEM USING CREMER RULE?
LET’S GET IT ON !!!
Click to GOTO colab’s notebook solution BELOW :)
01#Step —# cremer rule method initialization (libs):
from numpy import matrix, linalg
import numpy as np
02#Step — creating the matrices (printing the logic used):
matrix_A
matrix_A = np.array([[2.0, 1.0, 1.0],[0.30, 2.0, 0.25],[1.0, 1.0, 2.0]])
print(matrix_A)[[2. 1. 1. ]
[0.3 2. 0.25]
[1. 1. 2. ]]
matrix_B
matrix_B = np.array([[39.0],[13.0],[45.0]])
print(matrix_B)[[39.]
[13.]
[45.]]
03#Step — Calculating the determinant of the matrix_A:
det_A = linalg.det(matrix_A)
Is it possible TO USE cremer rule?
if(det_A == 0):
print('This equation CANNOT BE SOLVED by CREMER RULE:/')
else:
print('det_A = ', det_A )det_A = 5.45
04#Step — Fetching matrix_B’s elements:
b1=matrix_B[0,0]
b2=matrix_B[1,0]
b3=matrix_B[2,0]
05#Step —Fetching each element in matrix_A:
a11=matrix_A[0,0]
a21=matrix_A[1,0]
a31=matrix_A[2,0]
a12=matrix_A[0,1]
a22=matrix_A[1,1]
a32=matrix_A[2,1]
a13=matrix_A[0,2]
a23=matrix_A[1,2]
a33=matrix_A[2,2]
06#Step —Redefining each matrices, A1, A2 and A3:
print("By substituting column 'i' at the matrix 'Ai', we got:")matrix_A1 = np.array([[b1, a12, a13],
[b2, a22, a23],
[b3, a32, a33]])print(matrix_A1)[[39. 1. 1. ]
[13. 2. 0.25]
[45. 1. 2. ]]matrix_A2 = np.array([[a11, b1, a13],
[a21, b2, a23],
[a31, b3, a33]])print(matrix_A2)[[ 2. 39. 1. ]
[ 0.3 13. 0.25]
[ 1. 45. 2. ]]matrix_A3 = np.array([[a11, a12, b1],
[a21, a22, b2],
[a31, a32, b3]])print(matrix_A2)[[ 2. 1. 39. ]
[ 0.3 2. 13. ]
[ 1. 1. 45. ]]
07#Step — Calculating the determinants:
det_A1 = linalg.det(matrix_A1)
det_A2 = linalg.det(matrix_A2)
det_A3 = linalg.det(matrix_A3)
08#Step — The Solution:
t = det_A1/det_A
x = det_A2/det_A
n = det_A3/det_Aprint('t = ', t)
print('x = ', x)
print('n = ', n)t = 10.000000000000005
x = 2.9999999999999987
n = 16.00000000000001
That’s it:
print(“That’s it! Thanks for reading the post!”)That's it! Thanks for reading the post!
👉Colab notebook: link
Credits & References
Based on: Uninter Course Computer Engeneer Graduation — Date Aug/2021
Thanks to:
Fernanda Fonseca — Doctoral Student in Education, Master in Science and Mathematics Education and Degree in Physics and Philosophy — UNINTER — Brazil — PR
Related Posts:
32#PySeries#Episode — Linear Equations — GAUSS JORDAN — How To Use Python to Solve Linear System
33#PySeries#Episode — Linear Equations — CREMER RULE — How To Use Python to Solve Linear System (this one:)
34#PySeries#Episode — Linear Equations — Linear Equations — GAUSS SEIDEL — How To Use Python to Solve Linear System
01#Episode — #ElectricSeries — Electricity — Classroom Notes — Electricity — Working Out A Solution! — How to Calculate Circuits Efficiently Online. (look for https://matrixcalc.org/en/)
Jungletronics
J of Jungle + 3 Plats Arduino/RPi/Pic = J3
Following