我试图在 Python 中取矩阵的逆并不断收到语法错误。我是 Python 新手。在进行了互联网搜索并尝试了多种方法之后,我仍然没有得到它。有人可以看看我的代码并指出我正确的方向吗?错误消息:python2.6 test.py 文件“test.py”,第 39 行 inverse = mat1.I*mat2 ^ SyntaxError: invalid syntax
谢谢!
#import all of the needed libraries
import math
import matplotlib.pyplot as plt
import numpy
import array
import itertools
from numpy import linalg as LA
#variables and defs
x = []
y = []
h1 = 1
h2 = 5
h3 = 10
x1 = .5
x2 = 9.5
x3 = 4.5
y1 = .5
y2 = 2.5
y3 = 9.5
#create a 10x10 grid
for i in range(10):
for j in range(10):
x.append(i)
y.append(j)
j=0
#Triangle Interpolation Method 3
for i in range(100):
xp = x(i)
yp = y(i)
mat1 = ([[(x1-x3),(x2-x3)],[(y1-y3), (y2-y3)]])
mat2 = ([(xp-x3), (yp-y3)]
inverse = (LA.inv(mat1))*mat2
w1 = inverse(1)
w2 = inverse(2)
w3 = 1-w1-w2
#check to see if the points fall within the triangle
if((w1 <=1 && w1 >=0) && (w2 <=1 && w2 >=0) && (w3 <=1 && w3>=0))
z = (h1*w1)+(h2*w2)+(h3*w3)
.
.
.