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

📄 d10r11.cpp

📁 工程计算中经常用到的数值vc算法
💻 CPP
字号:
# include<math.h>
# include<iomanip.h>
# include<iostream.h>
# include<stdlib.h>
# include<process.h>
# include<stdio.h>

void main()
{
    //program d10r11
    //driver for routine zroots
	int m,m1,i,j,polish;
    m = 4;
    m1 = m + 1;
    double  a[3][6], roots[3][5];
    for (j = 1; j<=m1; j++)
	{
        for (i = 1; i<=2; i++)
		{
            a[i][j] = 0.0;
		}
	}
    a[2][1] = 2.0;
    a[1][3] = -1.0;
    a[2][3] = -2.0;
    a[1][5] = 1.0;
    cout<<endl;
    cout<< setw(5)<<"Roots of polynomial x^4-(1+2i)*x^2+2i"<<endl;
    cout<<endl;
    polish = 0;
    zroots(a, m, roots, polish);
    cout<< setw(5)<<"Unpolished roots:"<<endl;
    cout<< setw(5)<<"  root #       real           imag."<<endl;
	cout<<setprecision(4)<<setiosflags(ios::fixed);
    for (i = 1 ; i<= m; i++)
	{
        cout<< setw(5)<< i;
        cout<< setw(15)<< roots[1][i];
        cout<< setw(15)<< roots[2][i]<<endl;
    }
    cout<< endl;
    cout<< "Corrupted roots:"<<endl;
    for (i = 1; i<=m; i++)
	{
        roots[1][i] = roots[1][i] * (1.0 + 0.01 * i);
        roots[2][i] = roots[2][i] * (1.0 + 0.01 * i);
    }
    cout<<  "  roots #      real           imag."<<endl;
    for (i = 1; i<=m; i++)
	{
        cout<< setw(5)<< i;
        cout<< setw(15)<< roots[1][i];
        cout<< setw(15)<< roots[2][i]<<endl;
    }
    polish = -1;
    zroots(a, m, roots, polish);
    cout<< endl;
    cout<< "Polished roots:"<<endl;
    cout<< "  roots #      real           imag."<<endl;
    for (i = 1; i<=m; i++)
	{
        cout<< setw(5)<< i;
        cout<< setw(15)<< roots[1][i];
        cout<< setw(15)<< roots[2][i]<<endl;
    }
}

⌨️ 快捷键说明

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