Lines 60
matrices (2)
##### Permissions
Viewable by Everyone
Editable by All Siafoo Users

# Eigenvectors and Eigenvalues 0

 In Brief Numerically find the eigenvectors and eigenvalues of a matrix using the Power Method.
 Language C
# 's
` 1//powermethod.c 2//A program to find the largest eigenvector of a matrix 3//By David Isaacson, 2003 4//Released into the Public Domain 5 6#include <stdio.h> 7#include <math.h> 8 9int main ()10{11    float A[4][4]={{.8,.6,.4,.2},{.6,1.2,.8,.4},{.4,.8,1.2,.6},{.2,.4,.6,.8}};12    float newx[4]={1,1,1,1};13    float oldx[4]={0,0,0,0};14    float eigen;15    int i,j,done=0;			1617    while (!done)18    //repeat until all values within 10%19    {20	//set old=new21	for(i=0;i<4;i++)22	    oldx[i]=newx[i];2324	25	//multiply26	for(i=0;i<4;i++)27	{28	    newx[i]=0;29	    for(j=0;j<4;j++)30	    {31		newx[i]=newx[i]+(A[i][j])*(oldx[j]);32	    }33	}3435	//normalize36	j=0;		//j=smallest value37	for(i=1;i<4;i++)38	{39	    if (fabs(newx[j])>fabs(newx[i])&&newx[1]!=0)40		j=i;41	}42	eigen=fabs(newx[j]);43	for(i=0;i<4;i++)44	    newx[i]=newx[i]/eigen;4546	if ((fabs(((newx[0]-oldx[0])/oldx[0]))<=0.1)47          &&(fabs(((newx[1]-oldx[1])/oldx[1]))<=0.1)48          &&(fabs(((newx[2]-oldx[2])/oldx[2]))<=0.1)49          &&(fabs(((newx[3]-oldx[3])/oldx[3]))<=0.1))50	{51	    done=1;52	}53	54	    55    }56    57    printf("The eigenvector is about ");58    printf("{%f,%f,%f,%f}^T\n",newx[0],newx[1],newx[2],newx[3]);59    printf("The largest eigenvalue is about %f",eigen);6061    return 0;62}6364/*OUTPUT:6566The eigenvector is about {1.000000,1.600000,1.600000,1.000000}^T67The largest eigenvalue is about 2.5000006869*/70    `

Numerically find the eigenvectors and eigenvalues of a matrix using the Power Method.