NA-PTA-NA Lab5 正则化幂法求矩阵特征值

该博客介绍了一种使用正则化幂法来近似计算给定方阵A的特征值及其对应特征向量的方法。函数接受矩阵大小、初始特征值近似、初始向量、容差和最大迭代次数作为参数,并在满足精度要求或达到最大迭代次数时返回结果。如果初始值已经非常接近准确的特征值,函数将返回-1,否则返回1表示找到解,0表示超过最大迭代次数。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值