⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d8r4.cpp

📁 Visual C++ 常用数值算法集 源代码
💻 CPP
字号:
# include <math.h>
# include <iomanip.h>
# include <iostream.h>

void main()
{
    //program d8r4
    //driver for routine tqli
    int np,k,i,j;
    double tiny,a[4][4], c[4][4], d[4], e[4], f[4];;
	np = 3;
	tiny = 0.000001;
    a[1][1] = 1.0; a[1][2] = 2.0; a[1][3] = 3.0;
    a[2][1] = 2.0; a[2][2] = 2.0; a[2][3] = 3.0;
    a[3][1] = 3.0; a[3][2] = 3.0; a[3][3] = 3.0;
    for (i = 1; i<=np; i++)
	{
        for (j = 1; j<=np; j++)
		{
            c[i][j] = a[i][j];
        }
    }
    tred2(c, np, d, e);
    tqli(d, e, np, c);
    cout<<endl;
    cout<< "Eigenvectors for a real symmetric matrix";
    for (i = 1; i<=np; i++)
	{
        for (j = 1; j<=np; j++)
		{
            f[j] = 0.0;
            for (k = 1; k<=np; k++)
			{
                f[j] = f[j] + a[j][k] * c[k][i];
            }
		}
        cout<<endl;
        cout<< "Eigenvalue "<< i<< " = ";
        cout<< setw(10)<<d[i];
        cout<<endl;
        cout<<endl;
        cout<<  "       vector     mtrx*vect.    ratio"<<endl;
        cout<<endl;
        for (j = 1; j<=np; j++)
		{
            if (fabs(c[j][i]) < tiny )
			{
                cout<<setw(10)<<c[j][i];
                cout<< setw(10)<<f[j];
                cout<< "div. by 0";
			    cout<<endl;
			}
            else
			{
                cout<<setw(13)<<c[j][i];
                cout<<setw(13)<<f[j];
                cout<<setw(13)<<(f[j] / c[j][i])<<endl;
            }
		}
	
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -