Approximating Eigenvalues
Approximate an eigenvalue and an associated eigenvector of a given n×n matrix A near a given value p and a nonzero vector x =(x1 ,⋯,xn )T .
Format of function:
int EigenV(int n, double a[][MAX_SIZE], double *lambda, double v[], double TOL, int MAXN);
where int n is the size of the matrix of which the entries are in the array double a[][MAX_SIZE] and MAX_SIZE is a constant defined by the judge; double *lambda is passed into the function as an initial approximation p of the eigenvalue and is supposed to be returned as a more accurate eigenvalue; double v[] is passed into the function as the initial vector x and is supposed to be returned as the associated eigenvector with unit∥⋅∥∞ norm; double TOL is the tolerance for the eigenvalue; and finally int MAXN is the maximum number of iterations.
The function must return:
1 if there is a solution;
0 if maximum number of iterations exceeded;
−1 if p is just the accurate eigenvalue.
Sample program of judge:
#include <stdio.h>
#define MAX_SIZE 10
int EigenV(int n, double a[][MAX_SIZE], double *lambda, double v[], double TOL, int MAXN);
int main()
{
int n, MAXN, m, i, j, k;
double a[MAX_SIZE][MAX_SIZE], v[MAX_SIZE];
double lambda, TOL;
scanf("%d", &n);
for (i=0; i<n; i++)
for (j=0; j<n; j++)
scanf("%lf", &a[i][j]);
scanf("%lf %d", &TOL, &MAXN);
scanf("%d", &m);
for (i=0; i<m; i++) {
scanf("%lf", &lambda);
for (j=0; j<n; j++)
scanf("%lf", &v[j]);
switch (EigenV(n, a, &lambda