Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用于检查矩阵是否可以用Jacobi方法求解的代码无效 def checkJacobi(m): 行=m.shape[0] col=m.shape[1] solv=0 对于范围内的i(行): x=abs(m[i,i]) y=0 对于范围内的j(列): y=y+abs(m[i,j]) y=y-x 如果(y=sum(abs(m[i,j]),对于范围(cols)内的j)-abs(m[i,i])。因此,您的代码应该是: def checkJacobi(m): row = m.shape[0] col = m.shape[1] solv = 0 for i in range(row): x = abs(m[i,i]) y = 0 for j in range(col): y = y + abs(m[i,j]) y = y - x if (y < x): solv = solv + 1 if (solv == col): return True else: return False 如果y_Python_Python 3.x - Fatal编程技术网

Python 用于检查矩阵是否可以用Jacobi方法求解的代码无效 def checkJacobi(m): 行=m.shape[0] col=m.shape[1] solv=0 对于范围内的i(行): x=abs(m[i,i]) y=0 对于范围内的j(列): y=y+abs(m[i,j]) y=y-x 如果(y=sum(abs(m[i,j]),对于范围(cols)内的j)-abs(m[i,i])。因此,您的代码应该是: def checkJacobi(m): row = m.shape[0] col = m.shape[1] solv = 0 for i in range(row): x = abs(m[i,i]) y = 0 for j in range(col): y = y + abs(m[i,j]) y = y - x if (y < x): solv = solv + 1 if (solv == col): return True else: return False 如果y

Python 用于检查矩阵是否可以用Jacobi方法求解的代码无效 def checkJacobi(m): 行=m.shape[0] col=m.shape[1] solv=0 对于范围内的i(行): x=abs(m[i,i]) y=0 对于范围内的j(列): y=y+abs(m[i,j]) y=y-x 如果(y=sum(abs(m[i,j]),对于范围(cols)内的j)-abs(m[i,i])。因此,您的代码应该是: def checkJacobi(m): row = m.shape[0] col = m.shape[1] solv = 0 for i in range(row): x = abs(m[i,i]) y = 0 for j in range(col): y = y + abs(m[i,j]) y = y - x if (y < x): solv = solv + 1 if (solv == col): return True else: return False 如果y,python,python-3.x,Python,Python 3.x,到目前为止,这是我的代码,用于简单地检查矩阵,看看它们是否可以使用雅可比方法求解(雅可比方法只能在每行对角线元素的绝对值支配同一行中其他元素的绝对值之和时使用)。我用应该有效的矩阵进行了测试,结果返回False。我的代码怎么了?RTFM: 测试是abs(m[i,i])>=sum(abs(m[i,j]),对于范围(cols)内的j)-abs(m[i,i])。因此,您的代码应该是: def checkJacobi(m): row = m.shape[0] col = m.shape[

到目前为止,这是我的代码,用于简单地检查矩阵,看看它们是否可以使用雅可比方法求解(雅可比方法只能在每行对角线元素的绝对值支配同一行中其他元素的绝对值之和时使用)。我用应该有效的矩阵进行了测试,结果返回False。我的代码怎么了?

RTFM:

测试是
abs(m[i,i])>=sum(abs(m[i,j]),对于范围(cols)内的j)-abs(m[i,i])
。因此,您的代码应该是:

def checkJacobi(m):
    row = m.shape[0]
    col = m.shape[1]
    solv = 0
    for i in range(row):
        x = abs(m[i,i])
        y = 0
        for j in range(col):
            y = y + abs(m[i,j])
        y = y - x
        if (y < x):
            solv = solv + 1
    if (solv == col):
        return True
    else:
        return False
如果yRTFM:

测试是
abs(m[i,i])>=sum(abs(m[i,j]),对于范围(cols)内的j)-abs(m[i,i])
。因此,您的代码应该是:

def checkJacobi(m):
    row = m.shape[0]
    col = m.shape[1]
    solv = 0
    for i in range(row):
        x = abs(m[i,i])
        y = 0
        for j in range(col):
            y = y + abs(m[i,j])
        y = y - x
        if (y < x):
            solv = solv + 1
    if (solv == col):
        return True
    else:
        return False

如果y主要错误是(y必须是(y主要错误是(y必须是(在减去
x
后,你看不到你在哪里取
y
的绝对值@Adriankeester,这是不需要的:你应该计算绝对值的总和,而不是总和的绝对值。@ForceBru:哦,你说得对。我的错。没有看到你在减去
y
后在哪里取绝对值。@ForceBru:
x
@AdrianKeister,这是不需要的:一个人应该计算绝对值的和,而不是和的绝对值。@ForceBru:哦,你说得对。我的错。雅可比方法只适用于平方矩阵,所以
行==col
。另外,如果你能做
abs(m[i]),为什么要列出(map(abs m[i])
,速度快得多。雅可比方法只适用于方矩阵,因此
行==col
。此外,如果你能做
abs(m[i])
,速度快得多。@m.Ash,例如,这是使用雅可比函数代码时求解的矩阵,a=np.matrix([[6,2,-1,4],[1,5,1,3],[2,1,4,27]))@M.Ash,这个“雅可比函数代码”是不正确的,因为雅可比方法只适用于平方(NxN)矩阵,但你的矩阵是3x4。你说得对。雅可比函数代码是我的教授提供的,所以我不确定他要求编写此代码的目的。我会就错误与他联系。谢谢你的帮助!!@M.Ash,例如?这是一个在使用雅可比函数代码时求解的矩阵,a=np.matrix([[6,2,-1,4],[1,5,1,3],[2,1,4,27]])@M.Ash,此“雅可比函数代码”不正确,因为雅可比方法仅适用于平方(NxN)矩阵,但你的矩阵是3x4。你说得对。雅可比函数代码是我的教授提供的,所以我不确定他要求生成此代码时要做什么。我会就错误与他联系。谢谢你的帮助!!
def checkJacobi(m):
row = m.shape[0]
col = m.shape[1]
solv = 0
for i in range(row):
    m[i] = list(map(abs,m[i]))
    x = m[i,i]
    y = 0
    for j in range(col):
        y = y + m[i,j]
    y = y - x
    if (y <= x):
        solv = solv + 1
if (solv == row):
    return True
else:
    return False