2

I have a piece of code in Fortran 90 in which I have to solve both a non-linear (for which I have to invert the Jacobian matrix) and a linear system of equations. When I say small I mean n unknowns for both operations, with n<=4. Unfortunately, n is not known a priori. What do you think is the best option?

I thought of writing explicit formulas for cases with n=1,2 and using other methods for n=3,4 (e.g. some functions of the Intel MKL libraries), for the sake of performance. Is this sensible or should I write explicit formulas for the inverse matrix also for n=3,4?

user2078621
  • 111
  • 3
  • 12
  • 2
    If “best” means “fastest”, probably explicit formulas. To get quantitative, you will just have to test. Related: http://stackoverflow.com/questions/1148309/inverting-a-4x4-matrix?rq=1 – xebtl Sep 24 '15 at 10:08
  • Yes, I meant fastest. After googleing a bit I am not entirely sure explicit formulas are always the best. I was trying to find a performance comparison chart for the latest MKL version apllying to small matrix but with no success. So testing is probably the only option for _n=3,4_ – user2078621 Sep 24 '15 at 10:13
  • It is part of a Finite Element Analysis, with maybe hundreds of thousands of elements, with, say, 8 integration points each, and it is called once per iteration per integration point per each element so, yes, It IS called many many times, indeed. My question is about performance. Is any method faster than solving explicit expressions for n=_3,4_? Thanks for your replies. – user2078621 Sep 24 '15 at 10:18
  • 1
    Often you do not want the inverted matrix, but the LU decomposition or something else. I thing it might be more sensible to ask at http://scicomp.stackexchange.com where many specialists for numerical linear algebra meet. Your problem is not really Fortran specific, you need the best algorithm. – Vladimir F Героям слава Sep 24 '15 at 11:00
  • 3
    I'm voting to close this question as off-topic because it is better suited for Scientific Computation http://scicomp.stackexchange.com and has been now asked there as http://scicomp.stackexchange.com/questions/20812/efficently-invert-tiny-matrix-in-fortran . – Vladimir F Героям слава Sep 24 '15 at 13:32
  • 3
    According to [this page](http://eigen.tuxfamily.org/dox-devel/group__TutorialLinearAlgebra.html) it seems to utilize explicit inverse formulas for very small matrices (at most 4x4). Some related pages are http://stackoverflow.com/questions/18553210/how-to-implement-matlabs-mldivide-a-k-a-the-backslash-operator/18553768#18553768 http://scicomp.stackexchange.com/questions/3262/how-to-choose-a-method-for-solving-linear-equations http://stackoverflow.com/questions/32720478/simulating-matlabs-mrdivide-with-2-square-matrices/32728983#32728983 – roygvib Sep 24 '15 at 13:50

0 Answers0