Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 86,403 C++ Programmers. There are 1,518 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a C++ Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

To derive eigen values and eigen vectors for matrix upto order of 5*5

 
Reply to this topicStart new topic

To derive eigen values and eigen vectors for matrix upto order of 5*5, Source code Should be in C language

umer_alvi
post 25 Feb, 2007 - 03:46 PM
Post #1


New D.I.C Head

*
Joined: 21 Feb, 2007
Posts: 7



I want to derive a program that calculates the eigen values and vectors for matrix upto order of 5 X 5. But im not finding a general program and i have to use the switch statement that makes my program extremely lengthy and also it is very difficult to solve it for 5 X 5 matrix. Here is my work.
CODE

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main(void)
{


    int matrix;
    printf ("Press 1 for eigen values of 2 X 2 Matrix\n");
    printf ("Press 2 for eigen values of 3 X 3 Matrix\n");
    scanf ("%d",&matrix);
    printf("\t\n");
    switch(matrix)
    { case 1:
    int a,b,c,d;
    printf ("Enter the values of Matrix\n");
    scanf("%d",&a);
    scanf("%d",&b);
    printf("\n");
    scanf("%d",&c);
    scanf("%d",&d);
   printf("\t\n");
    int l,l1;

    l=((a+d)+sqrt((a+d)*(a+d)-4*((a*d)-(b*c))))/2;
    l1=((a+d)-sqrt((a+d)*(a+d)-4*((a*d)-(b*c))))/2;
    printf("The First  Eigen Value is %d\n",l);
    printf("The Second Eigen Value is %d\n",l1);
    break;
     case 2:
    int a1,b1,c1,d1,e1,f1,g1,h1,i1;
    printf("Enter the values of Matrix\n");
    scanf("%d\n",&a1);
    scanf("%d\n",&b1);
    scanf("%d",&c1);
    printf("\n");
    scanf("%d\n",&d1);
    scanf("%d\n",&e1);
    scanf("%d",&f1);
    printf("\n");
    scanf("%d\n",&g1);
    scanf("%d\n",&h1);
    scanf("%d"  ,&i1);
    printf("\n");
    int p,q,r;
    p = a1+e1+i1;
    q = -(a1*e1)-(a1*i1)-(e1*i1)-(f1*h1)+(b1*d1)+(c1*g1);
    r = (a1*e1*i1)-(a1*f1*h1)-(b1*d1*i1)+(b1*f1*g1)+(c1*d1*h1)-(c1*g1*e1);
    int l2,l3,l4;
    l2 = r;
    l3 = ( p + sqrt(p*p+ 4*(q+r) ) )/2;
    l4 = ( p - sqrt(p*p+ 4*(q+r) ) )/2;
    printf(" First  Eigen Value is %d\n",l2 );
    printf(" Second Eigen Value is %d\n",l3 );
    printf(" Third  Eigen Value is %d\n",l4 );
    break;
    default:
    printf("You Are Supposed To Enter the Values from 1 & 2 only");
    break;
    }





    
}
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


NickDMax
post 25 Feb, 2007 - 10:47 PM
Post #2


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,024

Ok I am sorry a never got arround to an example of converting a matrix to an upper triangular matrix. Here is some information on the subject from a ver good book "Numerical Recipes in C: The Art of Scientific Computing" This book is a great resource. (I miss the school library).

You want to look at chapter 11: here is the link. The book covers matrix methods in earlier chapters.

Basicly the process is not very hard and it can be automated to different size matricies. The problem comes in solving the resultant equations, which can be done with other numeric methods such as bisection and newtons method.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
Time is now: 5/17/08 07:26AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month