Created
October 3, 2024 14:54
-
-
Save sujyrokimora/d00e743fa482cae4fab2b3edde920973 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| import numpy as np | |
| def calc(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3): | |
| """ | |
| Representa um sistema de equações lineares com três incógnitas através de listas. | |
| Args: | |
| a1, b1, c1, d1: Coeficientes da primeira equação. | |
| a2, b2, c2, d2: Coeficientes da segunda equação. | |
| a3, b3, c3, d3: Coeficientes da terceira equação. | |
| Returns: | |
| A: Lista de listas representando a matriz dos coeficientes. | |
| B: Lista representando o vetor de constantes. | |
| """ | |
| A = [ | |
| [a1, b1, c1], | |
| [a2, b2, c2], | |
| [a3, b3, c3] | |
| ] | |
| B = [d1, d2, d3] | |
| print("{:+}".format(a1)+"x"+"{:+}".format(b1)+"y"+"{:+}".format(c1)+"z="+str(d1)) | |
| print("{:+}".format(a2)+"x"+"{:+}".format(b2)+"y"+"{:+}".format(c2)+"z="+str(d2)) | |
| print("{:+}".format(a3)+"x"+"{:+}".format(b3)+"y"+"{:+}".format(c3)+"z="+str(d3)) | |
| A_np = np.array(A) | |
| B_np = np.array(B) | |
| # Resolvendo o sistema de equações | |
| solucao = np.linalg.solve(A_np, B_np) | |
| return solucao | |
| def main(): | |
| t1= time.time() | |
| print(calc(1, 1, 1, 2, 6, -4, 5, 31, 5, 2, 2, 13)) | |
| t2 = time.time() | |
| t3= t2 - t1 | |
| print("Took the cpu "+str(t3)+" to solve the system") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment