【发布时间】:2013-04-03 02:46:23
【问题描述】:
我正在尝试在 Python 中取矩阵的逆并不断收到语法错误。我是 Python 新手。在进行了互联网搜索并尝试了多种方法之后,我仍然没有得到它。有人可以看看我的代码并指出我正确的方向吗? 错误信息: python2.6 test.py 文件“test.py”,第 39 行 逆 = mat1.I*mat2 ^ SyntaxError: 无效语法
谢谢!
#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)
.
.
.
【问题讨论】:
-
在寻求异常帮助时,例如
SyntaxError,通常最好至少发布所涉及的引用的最后一部分,因为这样可以减少我们发现错误所需的时间.
标签: python geometry interpolation matrix-inverse