C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 306,789 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,608 people online right now. Registration is fast and FREE... Join Now!




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

 

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

umer_alvi

25 Feb, 2007 - 02:46 PM
Post #1

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 7


My Contributions
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
+Quote Post


NickDMax

RE: To Derive Eigen Values And Eigen Vectors For Matrix Upto Order Of 5*5

25 Feb, 2007 - 09:47 PM
Post #2

Can grep dead trees!
Group Icon

Joined: 18 Feb, 2007
Posts: 5,265



Thanked: 293 times
Dream Kudos: 1175
Expert In: Java/C++

My Contributions
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
+Quote Post

Reply to this topicStart new topic

Time is now: 11/20/09 08:07PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month