Thread: Determination of eigenvalues and their condition number with C

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    3

    Determination of eigenvalues and their condition number with C

    Hello,


    I'm pretty new to the forum.
    I have the following problem:


    I would like to calculate eigenvalues with a C program code. Now I suspect that the eigenvalue problem is wrongly conditioned. For this reason I would like to calculate the condition number. does anyone know how to program this?

    Therefore I have inserted a part of the program here:

    Code:
    double c,f,g,r,s;
        int i,j,k,l,done;
            /* search for rows isolating an eigenvalue and push them down */
        for (k = n - 1; k >= 0; k--) {
            for (j = k; j >= 0; j--) {
                for (i = 0; i <= k; i++) {
                    if (i != j && fabs(mat[pos(j,i,n)]) != 0) break;
                }
    
    
                if (i > k) {
                    scale[k] = j;
    
    
                    if (j != k) {
                        for (i = 0; i <= k; i++) {
                           c = mat[pos(i,j,n)];
                           mat[pos(i,j,n)] = mat[pos(i,k,n)];
                           mat[pos(i,k,n)] = c;
                        }
    
    
                        for (i = 0; i < n; i++) {
                           c = mat[pos(j,i,n)];
                           mat[pos(j,i,n)] = mat[pos(k,i,n)];
                           mat[pos(k,i,n)] = c;
                        }
                    }
                    break;
                }
            }
            if (j < 0) break;
        }
    I would be very grateful for your help!


    Best regards

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,066
    Welcome! Do you know how to compute that on paper? If so, how would you do it, step by step? If not, then you should be looking for a maths forum first.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    3
    Thanks for your answer.
    So the condition indicates how well a problem is solved with an algorithm on a computer. Since we calculate eigenvalues it would be useful to look at the respective matrices. Let me give you an example:

    Calculation of the condition of the matrix

    Code:
    A:=\begin{pmatrix}
    -2 & 1 & 0 \\ 
    1 & -2 & 1\\ 
    0 & 1 & -2
    \end{pmatrix}


    The eigenvalues are
    Code:
    \lambda _{1} = -2, \lambda _{2} = -2+\sqrt{2} and \lambda _{3}= -2-\sqrt{2}
    .

    This makes the condition
    Code:
    \kappa(A) = \left | \frac{\lambda _{max}}{\lambda _{min}} \right | = \left | \frac{-2-\sqrt{2}}{-2+\sqrt{2}} \right | = 5.8
    .

    The system of equations or the matrix is thus well conditioned.

    I hope you can read the latex code. Is there any way to convert this into a program code? Or is it useful to look at the matrix here? Are there any other ways how I can check if the program delivers good results?

  4. #4
    Registered User
    Join Date
    Feb 2019
    Posts
    498

  5. #5
    Registered User
    Join Date
    Apr 2019
    Posts
    3
    Thanks for the book tip.
    Here are some examples of how to calculate eigenvalues. Like e.g. with the QR-method or with intererations. But it is not given how to test the efficiency of these methods. So how well they can solve the eigenvalue problem. Do you know any other sources?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iteration bound determination
    By progmateur in forum C Programming
    Replies: 6
    Last Post: 03-27-2013, 01:47 PM
  2. Prime number determination?
    By frankp124 in forum C Programming
    Replies: 3
    Last Post: 10-17-2012, 06:22 PM
  3. [HELP] Eigenvalues in C
    By Arbyn Acosta in forum C Programming
    Replies: 3
    Last Post: 09-23-2012, 12:16 AM
  4. Matrix Determination calculation
    By disruptivetech in forum C Programming
    Replies: 1
    Last Post: 04-17-2008, 06:46 AM
  5. Path Determination
    By AMAN GABA in forum Windows Programming
    Replies: 5
    Last Post: 10-08-2001, 02:26 AM

Tags for this Thread