Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB To FORTRAN Troubles (eig.m equivalent?)

  1. Jun 7, 2010 #1
    Hello all, first time I post here. I'm doing a PhD in Plasma Physics at the moment and have always been using MATLAB. It seems the research industry however does not look kindly on MATLAB and develops solely on FORTRAN (!!)..

    Anyway, I don't need to go into a lot of detail. I have a big 10x10 matrix that is real. There is no particular symmetry, just real numbers (positive and negative). I need a piece of code to get me the eigenvalues and the eigenvectors for this matrix. I only deal with square matrices in my work. In MATLAB I could use the trusty eig.m function, which was perfect. Now that I have to code in FORTRAN, I'm stumped..

    Thanks for any help you can provide.
     
  2. jcsd
  3. Jun 7, 2010 #2
    If you're working with Fortran in plasma physics, you'll almost certainly be working with people who use BLAS/LAPACK or NAG to solve such things. These are industry-standard libraries and you'll need to become familiar with them.
     
  4. Jun 7, 2010 #3
    I have just been looking through LAPACK actually, yeah. My biggest issue with this is that it doesn't simply take in a square matrix and return eigenvalues and eigenvectors. It's a messier than this..
     
  5. Jun 7, 2010 #4
    Well, that's one of the things you're going to have to deal with if you work in Fortran. :)

    The reason I suggested LAPACK and NAG is that these really are standard libraries that you will presumably be expected to know if you're working in plasma physics. You should probably therefore just bite the bullet and learn the one that your group uses.

    On the other hand, if you're really opposed to abandoning the convenience of a high-level language like Matlab, there are several other approaches you might try, including the following:

    • Matlab can interface with languages like C/C++ and Fortran using Matlab's engine library. The Matlab documentation contains all you need to know about this under "C/C++ and Fortran API reference".
    • You could choose to generate the necessary Fortran code automatically using something like f2py or SWIG, calling the resulting code from something like Python. This is actually quite common for rapidly testing out an idea without having to commit to developing the Fortran code first yourself. Again, there's lots of information out there on how to do things like this. Petter Langtangen's https://www.amazon.com/Python-Scrip...=sr_1_5?ie=UTF8&s=books&qid=1275945730&sr=1-5 gives a great introduction to this and your group may very well already have a copy you can read.
     
    Last edited by a moderator: May 4, 2017
  6. Jun 8, 2010 #5
    Thanks for your replies! :)
    I guess that's just what I'll have to do, unless there's a good and easy method for calculating such eigenvalues and eigenvectors, in which case it might be less cluttered if I just write my own routine for that particular purpose.
     
    Last edited by a moderator: May 4, 2017
  7. Jul 1, 2010 #6

    jasonRF

    User Avatar
    Science Advisor
    Gold Member

    I'm guessing most plasma physics folks don't want to use matlab because in general they are solving pdes, and matlab will typically be much slower. I was in plasma physics too, although in the 1990s, and back then it was mostly fortran as well. However there were some folks who used C for their work.

    Note that Matlab is built on top of lapack. There is a good reason why even after about 20 years or so Mathworks didn't spend the resources to home-brew their own numerics for this. Writing your own eig routine for general matrices is not easy. If I recall correctly, the book Numerical Recipes advises readers to write their own code for everything except eigen routines, because they can be a beast.

    I think you should bite the bullet and learn lapack, unless you can find another such standard library that will work for you. If you think the inputs/outputs of lapack are too messy to deal with, simply write you own wrapper functions that provide inputs/outputs to your liking. Then you just have to deal with the lapack interface once for each lapack routine.

    Of course, if you don't mind extending your graduate carreer a bit, you can delve into the world of numerical linear algebra and build your own. This might be fun but be warned that it is a non-trivial exercise and is certainly harder than learning lapack!

    best of luck.

    jason
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook