Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 2x2 matrix determinant
- def det2x2(m):
- a,b = m[0]
- c,d = m[1]
- return 1 / (a*d - b*c)
- # 2x2 matrix inverse
- def inv2x2(m):
- det = det2x2(m)
- a,b = m[0]
- c,d = m[1]
- return [[d*det,-b*det],[-c*det,a*det]]
- # Vec2 times 2x2 matrix
- def vec2Mul(v,m):
- x = v[0]*m[0][0] + v[1]*m[0][1]
- y = v[0]*m[1][0] + v[1]*m[1][1]
- return [x, y]
- # Solve
- # 4p+q=6
- # 2p-q=–3
- v = [6, -3]
- m = [[4, 1], [2, -1]]
- u = vec2Mul(v,inv2x2(m))
- print("p = ",u[0])
- print("q = ",u[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement