Python solve linear equation with substitution
I am trying to learn Python for a physics class, but I have tried to code the function of
E1 - i1R1 + i3R3 = 0;
-i3R3 - i2R2 - E2 = 0;
and E1 - i1R1 - i2R2 - E2 = 0.
And solve it by using a matrix. The variables are given to be E1 = 5V, E2 = 3V, R1 = 10 Ohms, R2 = 15 Ohms, and R3 = 5 Ohms.
Find i1, i2, and i3. Please help me. This is a homework question.
I use this code but it kept saying
linalg error due to 1 dimension, it require 2.
import numpy as np A = np.array([[5,10,5],[-5,-2,-3],[5,-10,-15,-3]]) print(A) c = np.array([0,0,0]) y = np.linalg.solve(A,c) print(y)