Is there any Fortran code for solving such a linear system with least square method?

Dear all:

For a standard linear system, y(n*1)=A(n*n)x(n*1)

If y is exact and A is well-conditioned, it is easy to calculate x.

However, if y has some disturbances or some errors, at the same time, A matrix is ill-conditioned. It is difficult to accurately obtain vector x. Alternatively, we can measure more components of y (becomes m*1, where m>n) and use the least square method to calculate the approximate x vector.

It is a common problem so I guess there should be some ready-to-use Fortran codes. Anybody knows where can I find this algorithms or codes? Any advice or suggestion is welcomed!

Thank you very much and with best wishes,
Thomas
 

jasonRF

Science Advisor
Gold Member
1,190
241
Re: Is there any Fortran code for solving such a linear system with least square meth

LAPACK is the standard Fortran package to do this. The subroutines you will want end in GELS or GELSS (SGELS is single precision real; DGELS is double precision real, CGELS is single complex, ZGELS is double complex) . LAPACK is free - google will find the package and all the documentation you should need.

_GELS uses QR factorization, I believe. _GELSS uses SVD.

Good luck.

jason
 

The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving

Members online

Top