[Numpy-discussion] ValueError: matrices are not aligned!!!
Happyman
bahtiyor_zohidov at mail.ru
Wed Sep 18 14:11:42 EDT 2013
Hello,
I am trying to solve linear Ax=b problem, but some error occurs in the process like:
----------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Conjugate_Gradient.py", line 66, in <module>
x, iter_number = conjGrad(Av,A, x, b)
File "C:\Python27\Conjugate_Gradient.py", line 51, in conjGrad
u = Av(A,s)
File "C:\Python27\Conjugate_Gradient.py", line 41, in Av
return np.dot(A,v)
ValueError: matrices are not aligned
----------------------------------------------- I put the code below to check it.
import numpy as np
import math
def Av(A,v):
return np.dot(A,v)
def conjGrad(Av,A, x, b, tol=1.0e-9):
n = len(x)
r = b - Av(A,x)
s = r.copy()
for i in range(n):
u = Av(A,s)
alpha = np.dot(s,r)/np.dot(s,u)
x = x + aplha*s
r = b - Av(A,x)
if (math.sqrt(np.dot(r,r))) < tol:
break
else:
beta = - np.dot(r,u)/np.dot(s,u)
s = r + beta * s
return x,i
if __name__ == '__main__':
# Input values
A = np.arange(32, dtype=float).reshape((4,8))
x = np.zeros(8)
b = np.array([2.5, 4.5, 6.5, 8.0])
x, iter_number = conjGrad(Av,A, x, b) I would appreciate any solution to this problem...
Thanks in advance
--
happy man
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130918/cf710761/attachment.html>
More information about the NumPy-Discussion
mailing list