Hi I am trying to calculate the matrix square root (lets say B) of a Matrix (A) which is an array. A = array([[1,2],[3,4]]) such that A = matrixmultiply(B,B) are there any functions in SciPy to do that ? Thanks Stuart -- Stuart Murdock Ph.D, Research Fellow, Dept. of Chemistry / E-Science, University of Southampton, Highfield, Southampton, SO17 1BJ, United Kingdom http://www.biosimgrid.org
Stuart Murdock wrote:
Hi
I am trying to calculate the matrix square root (lets say B) of a Matrix (A) which is an array.
A = array([[1,2],[3,4]])
such that
A = matrixmultiply(B,B)
are there any functions in SciPy to do that ?
Thanks
Stuart
AFAIK there is no direct support for sqrtm but you may use funm.
a = array(([1,2],[3,4])) b = linalg.funm(a,sqrt) b array([[ 0.55368857+0.46439416j, 0.80696073-0.21242648j], [ 1.21044109-0.31863972j, 1.76412966+0.14575444j]]) dot(b,b)-a array([[ 2.22044605e-16 -3.19839641e-17j, 0.00000000e+00 -2.83518868e-17j], [ 4.44089210e-16 -1.06821019e-16j, 0.00000000e+00 -1.69677640e-17j]])
HTH, Nils -- Dr.-Ing. Nils Wagner Institut A für Mechanik Universität Stuttgart Pfaffenwaldring 9 D-70550 Stuttgart Tel.: (+49) 0711 685 6262 Fax.: (+49) 0711 685 6282 E-mail: nwagner@mecha.uni-stuttgart.de URL : http://www.mecha.uni-stuttgart.de
Nils Wagner wrote:
Stuart Murdock wrote:
Hi
I am trying to calculate the matrix square root (lets say B) of a Matrix (A) which is an array.
A = array([[1,2],[3,4]])
such that
A = matrixmultiply(B,B)
are there any functions in SciPy to do that ?
Thanks
Stuart
AFAIK there is no direct support for sqrtm but you may use funm.
BTW, some algorithms for sqrtm can be found at http://www.ma.man.ac.uk/~higham/pap-mf.html This might be a starting point for an implementation of sqrtm in scipy. Any comments ? Nils
a = array(([1,2],[3,4])) b = linalg.funm(a,sqrt) b array([[ 0.55368857+0.46439416j, 0.80696073-0.21242648j], [ 1.21044109-0.31863972j, 1.76412966+0.14575444j]]) dot(b,b)-a array([[ 2.22044605e-16 -3.19839641e-17j, 0.00000000e+00 -2.83518868e-17j], [ 4.44089210e-16 -1.06821019e-16j, 0.00000000e+00 -1.69677640e-17j]])
HTH, Nils
On Mon, 4 Oct 2004, Nils Wagner wrote:
AFAIK there is no direct support for sqrtm but you may use funm.
I just discovered that there might be a bug in funm. I have added a test to scipy.linalg.test_matfuncs that demonstrates the bug. So, be aware to check the results of funm(..,sqrt). Pearu
Pearu Peterson wrote:
On Mon, 4 Oct 2004, Nils Wagner wrote:
AFAIK there is no direct support for sqrtm but you may use funm.
I just discovered that there might be a bug in funm. I have added a test to scipy.linalg.test_matfuncs that demonstrates the bug. So, be aware to check the results of funm(..,sqrt).
That might give a reason to implement sqrtm seperately. What is your opinion ? Nils
Pearu
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.net http://www.scipy.net/mailman/listinfo/scipy-user
On Mon, 4 Oct 2004, Nils Wagner wrote:
Pearu Peterson wrote:
On Mon, 4 Oct 2004, Nils Wagner wrote:
AFAIK there is no direct support for sqrtm but you may use funm.
I just discovered that there might be a bug in funm. I have added a test to scipy.linalg.test_matfuncs that demonstrates the bug. So, be aware to check the results of funm(..,sqrt).
That might give a reason to implement sqrtm seperately. What is your opinion ?
The fact that funm is buggy does not give a good reason to implement sqrtm. The following tasks are independent: funm must be fixed and sqrtm must be implemented. Pearu
Pearu Peterson wrote:
On Mon, 4 Oct 2004, Nils Wagner wrote:
AFAIK there is no direct support for sqrtm but you may use funm.
I just discovered that there might be a bug in funm. I have added a test to scipy.linalg.test_matfuncs that demonstrates the bug. So, be aware to check the results of funm(..,sqrt).
As far as I undertand, the idea of a general purpose matrix function has precision problems. The algorithm in scipy is based on a published algorithm using the Schur decomposition. That is why it is usually a good idea to write separate algorithms for special matrix functions if possible. Is this really a bug, or just a problem with using the generic funm algorithm when a more accurate algorithm exists. The fact that you can return a reasonable square root for non-special matrices makes me believe that it is not a bug in funm, but a demonstration that the generic funm algorithm does not always produce the best results for specific functions of matrices. -Travis O.
participants (4)
-
Nils Wagner
-
Pearu Peterson
-
Stuart Murdock
-
Travis Oliphant