<HTML><BODY>Hello,<br><br>I am trying to solve linear Ax=b problem, but some error occurs in the process like: <br>----------------------------------------------<br><p>Traceback (most recent call last):<br> File "C:\Python27\Conjugate_Gradient.py", line 66, in <module><br> x, iter_number = conjGrad(Av,A, x, b)<br> File "C:\Python27\Conjugate_Gradient.py", line 51, in conjGrad<br> u = Av(A,s)<br> File "C:\Python27\Conjugate_Gradient.py", line 41, in Av<br> return np.dot(A,v)<br>ValueError: matrices are not aligned<br>----------------------------------------------- </p>I put the code below to check it.<br><br><p>import numpy as np<br>import math</p><p>def Av(A,v):<br>     return np.dot(A,v)</p><p>def conjGrad(Av,A, x, b, tol=1.0e-9):<br>    n = len(x)<br>    r = b - Av(A,x)<br>    s = r.copy()<br>    for i in range(n):<br>         u = Av(A,s)<br>         alpha = np.dot(s,r)/np.dot(s,u)<br>         x = x + aplha*s<br>         r = b - Av(A,x)<br>         if (math.sqrt(np.dot(r,r))) < tol:<br>                     break<br>         else:<br>                     beta = - np.dot(r,u)/np.dot(s,u)<br>                     s = r + beta * s<br>    return x,i</p><p>if __name__ == '__main__':<br>     # Input values<br>     A = np.arange(32, dtype=float).reshape((4,8))<br>     x = np.zeros(8)<br>     b = np.array([2.5, 4.5, 6.5, 8.0])<br>     x, iter_number = conjGrad(Av,A, x, b)</p>I would appreciate any solution to this problem... <br>Thanks in advance<br>-- <br>happy man</BODY></HTML>