School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,105 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,746 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 Rate Topic: -----

#1 umer_alvi  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 7
  • Joined: 21-February 07


Dream Kudos: 0

Posted 25 February 2007 - 02:46 PM

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.
#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;
	}





	
}

Was This Post Helpful? 0
  • +
  • -


#2 NickDMax  Icon User is online

  • Can grep dead trees!
  • Icon
  • View blog
  • Group: Moderators
  • Posts: 6,311
  • Joined: 18-February 07


Dream Kudos: 1200

Expert In: Java/C++

Posted 25 February 2007 - 09:47 PM

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.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month