473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Numeric Python, variable types and my sanity

I'm writing a simulation of a problem in quantum mechanics, which boils down
to populating a huge matrix, then finding its eigenvalues and eigenvectors
using MLab.eig() (or LinearAlgebra.eigenvectors()). One of the key facts
about matrices related to quantum operators is that they are Hermitian, and
therefore have definitely real eigenvalues.

In fact, the matrices I create are real and symmetric; in my code I raise an
exception should this not be so and this never happens unless I
deliberately break something to test the exception handler :-). Now a real
symmetric matrix *really* ought to have both real eigenvalues and real
eigenvectors, but there are certain values of the parameters in my program
(unfortunately, many of which I want to investigate) in which this is not
the case.

I know exactly what's happening here; precision error. An eigenvalue that
*ought* to be zero is coming out as something along the lines of
xe-15+ye-15j. The problem I have is that such a squiffy eigenvalue has a
near-arbitrary argument, and this *really* screws up the associated
eigenvector, so much so that it's useless. So far I've just been throwing
out any eigenvectors associated with complex artefacts, and converting the
remainder to pure reals on the fly. However I'm conscious that I could be
throwing away signal here.

Is there a way to force MLab to deal solely in real numbers? I'd like to
get it to not even try to compute the imaginary part of any results, so
that these artefacts do not occur and the eigenvalues retrieved by the
program are at least usable, even if they still have the precision error in
the real part.

Cheers,

leeg.
--
I am leeg, for we are many.
http://users.ox.ac.uk/~wadh1342
Jul 18 '05 #1
2 1359
At some point, leeg <le**@teaching.physics.ox.ac.uk.valid> wrote:
In fact, the matrices I create are real and symmetric; in my code I raise an
exception should this not be so and this never happens unless I
deliberately break something to test the exception handler :-). Now a real
symmetric matrix *really* ought to have both real eigenvalues and real
eigenvectors, but there are certain values of the parameters in my program
(unfortunately, many of which I want to investigate) in which this is not
the case.

I know exactly what's happening here; precision error. An eigenvalue that
*ought* to be zero is coming out as something along the lines of
xe-15+ye-15j. The problem I have is that such a squiffy eigenvalue has a
near-arbitrary argument, and this *really* screws up the associated
eigenvector, so much so that it's useless. So far I've just been throwing
out any eigenvectors associated with complex artefacts, and converting the
remainder to pure reals on the fly. However I'm conscious that I could be
throwing away signal here.


I have a similiar use case, and ended up wrapping the LAPACK routine
DSYEVD myself (which does real, symmetric matrices), and using that.
Much better to use this than trying to coerce complex to real.

With f2py that should be pretty painless to do (I handwrote a C wrapper).

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #2
David M. Cooke wrote:

I have a similiar use case, and ended up wrapping the LAPACK routine
DSYEVD myself (which does real, symmetric matrices), and using that.
Much better to use this than trying to coerce complex to real.

With f2py that should be pretty painless to do (I handwrote a C wrapper).

I don't have too much Fxx knowledge, and it's mainly F90. But I'll look
into that method. Thanks :-)
--
I am leeg, for we are many.
http://users.ox.ac.uk/~wadh1342
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: beliavsky | last post by:
I have been looking at the speed of Python with the Numeric module by simulating some random numbers and computing some statistics. Here is the code. Line (1) is replaced as shown in the table. ...
24
by: Matt Feinstein | last post by:
Hi all-- I'm new to Python, and was somewhat taken aback to discover that the core language lacks some basic numerical types (e.g., single-precision float, short integers). I realize that there...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
4
by: Dimitrios Charitatos | last post by:
Hello, I suspect that there is a quite straight forward answer to this, but I can't find it... I want to import an image and extract a matrix (or array) from it with elements showing the RGB...
13
by: Salvatore | last post by:
Hello, I've read several articles where it's said that Python is weakly typed. I'm a little surprised. All objects seem to have a perfectly defined type Am i wrong? Regards
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 380 open (-36) / 3658 closed (+65) / 4038 total (+29) Bugs : 965 open ( -9) / 6555 closed (+35) / 7520 total (+26) RFE : 272 open...
29
by: Gerald | last post by:
Hi ,Im a BSc4 Maths/Computer Science student.Unfortunately my curriculum did not include Python programming yet I see many vacancies for Python developers.I studied programming Pascal,C++ and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.