This is an example I got about eigenvalues...
Maybe a specific example, suppose you have the matrix A:
[ 2 4 ]
[ 3 5 ]
We turn this into the matrix A-xI
[ 2-x 4 ]
[ 3 5-x]
This has determinant det (A-xI) = (2-x)(5-x)-(3)(4) = x^2-7x-2. You can then solve this quadratic equation using whatever method you like to use to solve quadratic equations. Note: you did this in your linear algebra class, so dig that book back out.
---------------------
Here is my code:
Code:
#include <stdio.h>
int main()
{
float a[2][3], b[2][1], mean[2][1], after[2][3], afterT[3][2], cov[2][2];
int i, j, k, h, p;
printf("\nEnter three 2D vectors in form of 2x3 matrix A: ");
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
{
printf("\n Enter a[%d][%d]: ", i,j);
scanf("%f", &a[i][j]);
}
}
/*Compute the Mean*/
b[0][0]= a[0][0]+a[0][1]+a[0][2];
b[1][0]= a[1][0]+a[1][1]+a[1][2];
for(i=0; i<2; i++)
{
for(j=0; j<1; j++)
{
mean[i][j]= b[i][j]*(1.0/3.0);
}
}
/*Subtract each vector by the mean vector*/
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<1; k++)
{
after[i][j]=a[i][j]-mean[i][k];
}
}
}
/*Transpose after (afterT)*/
for(i=0; i<2; i++)
{
for(j=0; j<3; j++)
{
afterT[j][i]=after[i][j];
}
}
/*Compute and Display Covariance*/
cov[0][0]= (after[0][0]*afterT[0][0])+(after[0][1]*afterT[1][0])+(after[0][2]*afterT[2][0]);
cov[0][1]= (after[0][0]*afterT[0][1])+(after[0][1]*afterT[1][1])+(after[0][2]*afterT[1][2]);
cov[1][0]= (after[1][0]*afterT[0][0])+(after[1][1]*afterT[1][0])+(after[1][2]*afterT[2][0]);
cov[1][1]= (after[1][0]*afterT[0][1])+(after[1][1]*afterT[1][1])+(after[1][2]*afterT[2][1]);
cov[0][0]=(.5)*cov[0][0];
cov[0][1]=(.5)*cov[0][1];
cov[1][0]=(.5)*cov[1][0];
cov[1][1]=(.5)*cov[1][1];
printf("\n Their product is :\n");
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
{
printf("%.1f ", cov[i][j]);
}
printf("\n");
}
/*Determinants*/
cov[0][0]=cov[0][0]-x;
cov[1][1]=cov[1][1]-x;
det=(cov[0][0]*cov[1][1])-(cov[1][0]*cov[0][1])
return(0);
}
The thing I can't figure out is because the eigenvalues are the roots of the determinant, how to compute the eigenvalues...As seen above I have variable "det" as the determinant of the 2x2 covariance matrix....
can someone help? thanks
PS- I can only use the library functions sqrt, printf, scanf