'''
resistor.py
Eric Ayars
June 2016
A demonstration program for solving a system of linear equations using Python.
'''
import numpy as np
# Start by getting the values of R and V
R1 = float(input("R1 = "))
R2 = float(input("R2 = "))
R3 = float(input("R3 = "))
V1 = float(input("V1 = "))
V2 = float(input("V2 = "))
# Use these values to build the matrix M. Note that this matrix
# will vary depending on the equation set selected to solve the
# problem: here I use the equations from the PICUP webpage.
# Here is the matrix M:
M = np.array([ [R1, 0, R3],
[0,-R2, R3],
[1, -1, -1] ])
# here is the right-hand-side b:
b = np.array([V1,V2,0])
# And this is all it takes to get a solution:
x = np.linalg.solve(M,b)
# show the result.
print(x)
# The result is an array of currents:
# [-0.09090909 -0.45454545 0.36363636]
# The first one is I_1, the second is I_2, etc.