| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 195 人关注过本帖
标题:【求助】c++编写程序无报错但一直算不出结果(两层迭代),球球查错谢谢了
只看楼主 加入收藏
xcs111
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-2-11
  问题点数:0  回复次数:0   
【求助】c++编写程序无报错但一直算不出结果(两层迭代),球球查错谢谢了
前面的类是我直接抄的应该没问题,不知道是不是主函数哪里编写错误,实在算不出结果
#include  <iostream>
#include  <fstream>
#include  <cmath>
#include <vector>

using namespace std;
//lagr1类
class  lagr1
{
private:
    int n, m;
    double  *x, *y, **z, u, v, f;
public:
    lagr1(int nn, int mm)        //声明构造函数
    {
        int k;
        n = nn;  m = mm;
        x = new double[n]; //动态分配内存
        y = new double[m];
        z = new double*[n];        //z是个二维数组指针
        for (k = 0; k < n; k++) { z[k] = new double[m]; }
    }
    void input();          //由文件读入n*m个数据点(x, y, z)
    double interp(double, double);    //执行二元Lagrange插值
    void output();         //输出插值点u,v处的近似值f到文件
 
 
    ~lagr1()        //这是析构函数
    {
        int i;
        for (i = 0; i < n; i++) { delete[] z[i]; }
        delete[] z;
        delete[] x, y;
    }
};
 
 
//class lagr1 的成员函数
void lagr1::input()      //由文件读入n*m个数据点(x, y, z)
{
    int  k, j;
    char str1[20]="comp_pr.txt";
//    cout << "\n输入文件名:  ";
//    cin >> str1;
    ifstream  fin(str1);        ////ifstream fin("c:\\x.123");//以输入的方式打开文件  
    //由于返回0代表程序正常退出,返回1等其他数字通常代表异常终止,在这里表示以输入的方式打开文档fin异常,所以终止
    if (!fin)
    {
        cout << "\n不能打开这个文件 " << str1 << endl; exit(1);
    }
    //如果打开fin正常,那么读入文件
    for (k = 0; k < n; k++) { fin >> x[k]; }        //把数读入 x[k]
    for (k = 0; k < m; k++) { fin >> y[k]; }        //把数读入 y[k]
 
    for (k = 0; k < n; k++)                   //读入n*m个数据点
        for (j = 0; j < m; j++)  { fin >> z[k][j]; }        //把二维数读入 z[k][j]
    fin.close();
}
 
 
//class lagr1 的成员函数
double lagr1::interp(double uu, double vv)        //构造函数的定义
{
    int ip, ipp, i, j, kk, iq, iqq, k;
    double h, b[10];
    u = uu;  v = vv;
    if (u <= x[0]) { ip = 1; ipp = 4; }
    else if (u >= x[n - 1]) { ip = n - 3; ipp = n; }
    else
    {
        i = 1; j = n;
        while (((i - j) != 1) && ((i - j) != -1))
        {
            kk = (i + j) / 2;
            if (u < x[kk - 1]) j = kk;
            else i = kk;
        }
        ip = i - 3; ipp = i + 4;
    }
    if (ip < 1) ip = 1;
    if (ipp > n) ipp = n;
    if (v <= y[0]) { iq = 1; iqq = 4; }
    else if (v >= y[m - 1]) { iq = m - 3; iqq = m; }
    else
    {
        i = 1; j = m;
        while (((i - j) != 1) && ((i - j) != -1))
        {
            kk = (i + j) / 2;
            if (v < y[kk - 1]) j = kk;
            else i = kk;
        }
        iq = i - 3; iqq = i + 4;
    }
    if (iq < 1) iq = 1;
    if (iqq > m) iqq = m;
    for (i = ip - 1; i <= ipp - 1; i++)
    {
        b[i - ip + 1] = 0.0;
        for (j = iq - 1; j <= iqq - 1; j++)
        {
            h = z[i][j];
            for (k = iq - 1; k <= iqq - 1; k++)
                if (k != j) h = h*(v - y[k]) / (y[j] - y[k]);
            b[i - ip + 1] = b[i - ip + 1] + h;
        }
    }
    f = 0.0;
    for (i = ip - 1; i <= ipp - 1; i++)
    {
        h = b[i - ip + 1];
        for (j = ip - 1; j <= ipp - 1; j++)
            if (j != i) h = h*(u - x[j]) / (x[i] - x[j]);
        f = f + h;
    }
    return f;        //返回f值
}
 
 
//class lagr1 的成员函数
void lagr1::output()       //输出插值点u,v处的近似值f到文件
{
    char str2[20]="a.txt";
//    cout << "\n输出文件名:  ";
//    cin >> str2;
    ofstream fout(str2, ios::app);
    if (!fout)
    {
        cout << "\n不能打开这个文件 " << str2 << endl; exit(1);
    }
    fout << endl << u << "  " << v << "     " << f << endl;        //上面空一行,下面空一行
    fout.close();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//lagr2类
class  lagr2
{
private:
    int n, m;
    double  *x, *y, **z, u, v, f;
public:
    lagr2(int nn, int mm)        //声明构造函数
    {
        int k;
        n = nn;  m = mm;
        x = new double[n]; //动态分配内存
        y = new double[m];
        z = new double*[n];        //z是个二维数组指针
        for (k = 0; k < n; k++) { z[k] = new double[m]; }
    }
    void input();          //由文件读入n*m个数据点(x, y, z)
    double interp(double, double);    //执行二元Lagrange插值
    void output();         //输出插值点u,v处的近似值f到文件
 
 
    ~lagr2()        //这是析构函数
    {
        int i;
        for (i = 0; i < n; i++) { delete[] z[i]; }
        delete[] z;
        delete[] x, y;
    }
};
 
 
//class lagr2 的成员函数
void lagr2::input()      //由文件读入n*m个数据点(x, y, z)
{
    int  k, j;
    char str1[20]="comp_eff.txt";
//    cout << "\n输入文件名:  ";
//    cin >> str1;
    ifstream  fin(str1);        ////ifstream fin("c:\\x.123");//以输入的方式打开文件  
    //由于返回0代表程序正常退出,返回1等其他数字通常代表异常终止,在这里表示以输入的方式打开文档fin异常,所以终止
    if (!fin)
    {
        cout << "\n不能打开这个文件 " << str1 << endl; exit(1);
    }
    //如果打开fin正常,那么读入文件
    for (k = 0; k < n; k++) { fin >> x[k]; }        //把数读入 x[k]
    for (k = 0; k < m; k++) { fin >> y[k]; }        //把数读入 y[k]
 
    for (k = 0; k < n; k++)                   //读入n*m个数据点
        for (j = 0; j < m; j++)  { fin >> z[k][j]; }        //把二维数读入 z[k][j]
    fin.close();
}
 
 
//class lagr2 的成员函数
double lagr2::interp(double uu, double vv)        //构造函数的定义
{
    int ip, ipp, i, j, kk, iq, iqq, k;
    double h, b[10];
    u = uu;  v = vv;
    if (u <= x[0]) { ip = 1; ipp = 4; }
    else if (u >= x[n - 1]) { ip = n - 3; ipp = n; }
    else
    {
        i = 1; j = n;
        while (((i - j) != 1) && ((i - j) != -1))
        {
            kk = (i + j) / 2;
            if (u < x[kk - 1]) j = kk;
            else i = kk;
        }
        ip = i - 3; ipp = i + 4;
    }
    if (ip < 1) ip = 1;
    if (ipp > n) ipp = n;
    if (v <= y[0]) { iq = 1; iqq = 4; }
    else if (v >= y[m - 1]) { iq = m - 3; iqq = m; }
    else
    {
        i = 1; j = m;
        while (((i - j) != 1) && ((i - j) != -1))
        {
            kk = (i + j) / 2;
            if (v < y[kk - 1]) j = kk;
            else i = kk;
        }
        iq = i - 3; iqq = i + 4;
    }
    if (iq < 1) iq = 1;
    if (iqq > m) iqq = m;
    for (i = ip - 1; i <= ipp - 1; i++)
    {
        b[i - ip + 1] = 0.0;
        for (j = iq - 1; j <= iqq - 1; j++)
        {
            h = z[i][j];
            for (k = iq - 1; k <= iqq - 1; k++)
                if (k != j) h = h*(v - y[k]) / (y[j] - y[k]);
            b[i - ip + 1] = b[i - ip + 1] + h;
        }
    }
    f = 0.0;
    for (i = ip - 1; i <= ipp - 1; i++)
    {
        h = b[i - ip + 1];
        for (j = ip - 1; j <= ipp - 1; j++)
            if (j != i) h = h*(u - x[j]) / (x[i] - x[j]);
        f = f + h;
    }
    return f;        //返回f值
}
 
 
//class lagr2 的成员函数
void lagr2::output()       //输出插值点u,v处的近似值f到文件
{
    char str2[20]="a.txt";
//    cout << "\n输出文件名:  ";
//    cin >> str2;
    ofstream fout(str2, ios::app);
    if (!fout)
    {
        cout << "\n不能打开这个文件 " << str2 << endl; exit(1);
    }
    fout << endl << u << "  " << v << "     " << f << endl;        //上面空一行,下面空一行
    fout.close();
}
 


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//lagr3类
class  lagr3
{
private:
    int n, m;
    double  *x, *y, **z, u, v, f;
public:
    lagr3(int nn, int mm)        //声明构造函数
    {
        int k;
        n = nn;  m = mm;
        x = new double[n]; //动态分配内存
        y = new double[m];
        z = new double*[n];        //z是个二维数组指针
        for (k = 0; k < n; k++) { z[k] = new double[m]; }
    }
    void input();          //由文件读入n*m个数据点(x, y, z)
    double interp(double, double);    //执行二元Lagrange插值
    void output();         //输出插值点u,v处的近似值f到文件
 
 
    ~lagr3()        //这是析构函数
    {
        int i;
        for (i = 0; i < n; i++) { delete[] z[i]; }
        delete[] z;
        delete[] x, y;
    }
};
 
 
//class lagr3 的成员函数
void lagr3::input()      //由文件读入n*m个数据点(x, y, z)
{
    int  k, j;
    char str1[20]="comp_m1.txt";
//    cout << "\n输入文件名:  ";
//    cin >> str1;
    ifstream  fin(str1);        ////ifstream fin("c:\\x.123");//以输入的方式打开文件  
    //由于返回0代表程序正常退出,返回1等其他数字通常代表异常终止,在这里表示以输入的方式打开文档fin异常,所以终止
    if (!fin)
    {
        cout << "\n不能打开这个文件 " << str1 << endl; exit(1);
    }
    //如果打开fin正常,那么读入文件
    for (k = 0; k < n; k++) { fin >> x[k]; }        //把数读入 x[k]
    for (k = 0; k < m; k++) { fin >> y[k]; }        //把数读入 y[k]
 
    for (k = 0; k < n; k++)                   //读入n*m个数据点
        for (j = 0; j < m; j++)  { fin >> z[k][j]; }        //把二维数读入 z[k][j]
    fin.close();
}
 
 
//class lagr3 的成员函数
double lagr3::interp(double uu, double vv)        //构造函数的定义
{
    int ip, ipp, i, j, kk, iq, iqq, k;
    double h, b[10];
    u = uu;  v = vv;
    if (u <= x[0]) { ip = 1; ipp = 4; }
    else if (u >= x[n - 1]) { ip = n - 3; ipp = n; }
    else
    {
        i = 1; j = n;
        while (((i - j) != 1) && ((i - j) != -1))
        {
            kk = (i + j) / 2;
            if (u < x[kk - 1]) j = kk;
            else i = kk;
        }
        ip = i - 3; ipp = i + 4;
    }
    if (ip < 1) ip = 1;
    if (ipp > n) ipp = n;
    if (v <= y[0]) { iq = 1; iqq = 4; }
    else if (v >= y[m - 1]) { iq = m - 3; iqq = m; }
    else
    {
        i = 1; j = m;
        while (((i - j) != 1) && ((i - j) != -1))
        {
            kk = (i + j) / 2;
            if (v < y[kk - 1]) j = kk;
            else i = kk;
        }
        iq = i - 3; iqq = i + 4;
    }
    if (iq < 1) iq = 1;
    if (iqq > m) iqq = m;
    for (i = ip - 1; i <= ipp - 1; i++)
    {
        b[i - ip + 1] = 0.0;
        for (j = iq - 1; j <= iqq - 1; j++)
        {
            h = z[i][j];
            for (k = iq - 1; k <= iqq - 1; k++)
                if (k != j) h = h*(v - y[k]) / (y[j] - y[k]);
            b[i - ip + 1] = b[i - ip + 1] + h;
        }
    }
    f = 0.0;
    for (i = ip - 1; i <= ipp - 1; i++)
    {
        h = b[i - ip + 1];
        for (j = ip - 1; j <= ipp - 1; j++)
            if (j != i) h = h*(u - x[j]) / (x[i] - x[j]);
        f = f + h;
    }
    return f;        //返回f值
}
 
 
//class lagr3 的成员函数
void lagr3::output()       //输出插值点u,v处的近似值f到文件
{
    char str2[20]="a.txt";
//    cout << "\n输出文件名:  ";
//    cin >> str2;
    ofstream fout(str2, ios::app);
    if (!fout)
    {
        cout << "\n不能打开这个文件 " << str2 << endl; exit(1);
    }
    fout << endl << u << "  " << v << "     " << f << endl;        //上面空一行,下面空一行
    fout.close();
}
     
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//一元插值函数
inline double newton_solution(double x[], double y[], int n, double num, int newton_time)
{
    vector<vector<double> > table(n + 1);
    for (int i = 0; i <= n; i++) {
        table[i].resize(n + 1);
    }
    for ( i = 0; i <= n; i++) table[0][i] = y[i];
    for ( i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            table[i][j] = (table[i - 1][j] - table[i - 1][j - 1]) / (x[j] - x[j - i]);
        }
    }

    double res = 0.0;
    for ( i = 0; i <= newton_time; i++) {
        double temp = table[i][i];
        for (int j = 0; j < i; j++) {
            temp *= num - x[j];
        }
        res += temp;
    }

    return res;

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double air_H(double T) //空气焓值计算函数(kw)
{
    double C0, C1, C2, C3, C4;  
    double H;
    if (T<800)
    {
        C0=0.24336328;
        C1=-0.32921648*pow(10,-4);
        C2=0.4739514*pow(10,-7);
        C3=0.10126855*pow(10,-9);
        C4=-0.89883655*pow(10,-13);
    }
    else
    {
        C0=0.19075549;
        C1=0.12752498*pow(10,-3);
        C2=-0.54651988*pow(10,-7);
        C3=0.89378182*pow(10,-11);
        C4=0;
    }
    H=4.185*(C0*T+(C1*pow(T,2))/2+(C2*pow(T,3))/3+(C3*pow(T,4))/4+(C4*pow(T,5))/5);
    return H;
}

double gas_H(double T,double f) //燃气焓值计算函数(kw)
{
    double c0, c1, c2, c3, c4, c5;
    double G=f/(1+f);
    double theta;
    double H;
    if (T<800)
    {
        c0=14.96069;
        c1=-0.12635675;
           c2=0.76971033*pow(10,-3);
        c3=-0.51758509*pow(10,-6);
        c4=0.5959612*pow(10,-10);
        c5=0.83337678*pow(10,-13);
    }
    else
    {
        c0=-42.23753;
        c1=0.19989167;
        c2=0.87121923*pow(10,-4);
        c3=0.60082756*pow(10,-7);
        c4=-0.29954469*pow(10,-10);
        c5=0.39185699*pow(10,-14);
    }
    theta=c0+c1*T+c2*pow(T,2)+c3*pow(T,3)+c4*pow(T,4)+c5*pow(T,5);
    H=air_H(T)+G*theta;
    return H;
}

double air_Cp(double T) //空气定压比热容计算函数(kJ/(kg*K))
{
    double C0, C1, C2, C3, C4;  
    double Cp;
    if (T<800)
    {
        C0=0.24336328;
        C1=-0.32921648*pow(10,-4);
        C2=0.4739514*pow(10,-7);
        C3=0.10126855*pow(10,-9);
        C4=-0.89883655*pow(10,-13);
    }
    else
    {
        C0=0.19075549;
        C1=0.12752498*pow(10,-3);
        C2=-0.54651988*pow(10,-7);
        C3=0.89378182*pow(10,-11);
        C4=0;
    }
    Cp=4.185*(C0+C1*T+C2*pow(T,2)+C3*pow(T,3)+C4*pow(T,4));
    return Cp;
}

double gas_Cp(double T,double f) //燃气定压比热容计算函数(kJ/(kg*K))
{
    double c0, c1, c2, c3, c4, c5;
    double G=f/(1+f);
    double theta;
    double Cpg;
    if (T<800)
    {
        c0=-0.085863702;
        c1=0.10787235*pow(10,-2);
        c2=0.67154771*pow(10,-6);
        c3=-0.51850414*pow(10,-8);
        c4=0.68521981*pow(10,-11);
        c5=-0.29202103*pow(10,-14);
    }
    else
    {
        c0=0.26004518;
        c1=-0.33817793*pow(10,-4);
        c2=0.45763254*pow(10,-6);
        c3=-0.29619121*pow(10,-9);
        c4=0.73252744*pow(10,-13);
        c5=-0.62379644*pow(10,-17);
    }
    theta=c0+c1*T+c2*pow(T,2)+c3*pow(T,3)+c4*pow(T,4)+c5*pow(T,5);
    Cpg=air_Cp(T)+G*theta;  
    return Cpg;

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()      //主函数
{
    int i;
    lagr1  solution(5, 10);        //这是用到了lagr1 类 的构造函数
    ofstream ft("comp_pr.txt");        //ofstream file3("c:\\x.123");//以输出方式打开文件  
    if (!ft)
    {
        cout << "\n不能打开文件comp_pr.txt " << endl; exit(1);
    }
    ft << 30300 << "  "<<36107.5<< "  "<<40400<< "  "<<45450<< "  "<<50500<< "  ";
    ft << endl;
    for (i = 1; i < 11; i++)  ft << i << "  ";
    ft << endl;
    ft << 1.72<< "  "<< 1.73<< "  "<< 1.75<< "  "<< 1.77<< "  "<< 1.792<< "  "<< 1.792<< "  "<< 1.8<< "  "<< 1.8<< "  "<< 1.802<< "  "<< 1.615 << "  ";
    ft << endl;
    ft << 2.01<< "  "<< 2.03<< "  "<< 2.04<< "  "<< 2.05<< "  "<< 2.065<< "  "<< 2.07<< "  "<< 2.09<< "  "<< 2.105<< "  "<< 2.11<< "  "<< 1.83<< "  ";
    ft << endl;
    ft << 2.43<< "  "<< 2.45<< "  "<< 2.46<< "  "<< 2.47<< "  "<< 2.46<< "  "<< 2.47<< "  "<< 2.48<< "  "<< 2.49<< "  "<< 2.48<< "  "<< 2.17<< "  ";
    ft << endl;
    ft << 2.99<< "  "<< 3.0<< "  "<< 3.01<< "  "<< 3.02<< "  "<< 3.03<< "  "<< 3.035<< "  "<< 3.035<< "  "<< 3.04<< "  "<< 3.048<< "  "<< 2.49<< "  ";
    ft << endl;
    ft << 3.58<< "  "<< 3.6<< "  "<< 3.6<< "  "<< 3.61<< "  "<< 3.62<< "  "<< 3.625<< "  "<< 3.63<< "  "<< 3.63<< "  "<< 3.635<< "  "<< 3.62<< "  ";
    ft << endl;
    ft.close();        //就把ft相连的文件关闭。


    lagr2  solution1(5, 10);        //这是用到了lagr2 类 的构造函数
    ofstream ft1("comp_eff.txt");        //ofstream file3("c:\\x.123");//以输出方式打开文件  
    if (!ft1)
    {
        cout << "\n不能打开文件comp_eff.txt " << endl; exit(1);
    }
    ft1 << 30300 << "  "<<36107.5<< "  "<<40400<< "  "<<45450<< "  "<<50500<< "  ";
    ft1 << endl;
    for (i = 1; i < 11; i++)  ft1 << i << "  ";
    ft1 << endl;
    ft1 << 0.745 << "  "<< 0.767 << "  "<< 0.772 << "  "<< 0.784 << "  "<< 0.804 << "  "<< 0.819 << "  "<< 0.833 << "  "<< 0.85 << "  "<< 0.853 << "  "<< 0.722 << "  ";
    ft1 << endl;
    ft1 << 0.75 << "  "<< 0.762 << "  "<< 0.777 << "  "<< 0.792 << "  "<< 0.802 << "  "<< 0.818 << "  "<< 0.823 << "  "<< 0.835 << "  "<< 0.84 << "  "<< 0.682 << "  ";
    ft1 << endl;
    ft1 << 0.763 << "  "<< 0.778 << "  "<< 0.782 << "  "<< 0.795 << "  "<< 0.8 << "  "<< 0.809 << "  "<< 0.812 << "  "<< 0.819 << "  "<< 0.821 << "  "<< 0.679 << "  ";
    ft1 << endl;
    ft1 << 0.769 << "  "<< 0.778 << "  "<< 0.788 << "  "<< 0.792 << "  "<< 0.796 << "  "<< 0.799 << "  "<< 0.8 << "  "<< 0.802 << "  "<< 0.85 << "  "<< 0.8663 << "  ";
    ft1 << endl;
    ft1 << 0.75 << "  "<< 0.758 << "  "<< 0.76 << "  "<< 0.762 << "  "<< 0.767 << "  "<< 0.772 << "  "<< 0.775 << "  "<< 0.776 << "  "<< 0.777 << "  "<< 0.778 << "  ";
    ft1 << endl;
    ft1.close();        //就把ft相连的文件关闭。
    //输入文件结束。
 

    lagr3  solution2(5, 10);        //这是用到了lagr3 类 的构造函数
    ofstream ft2("comp_m1.txt");        //ofstream file3("c:\\x.123");//以输出方式打开文件  
    if (!ft2)
    {
        cout << "\n不能打开文件comp_m1.txt " << endl; exit(1);
    }
    ft2 << 30300 << "  "<<36107.5<< "  "<<40400<< "  "<<45450<< "  "<<50500<< "  ";
    ft2 << endl;
    for (i = 1; i < 11; i++)  ft2 << i << "  ";
    ft2 << endl;
    ft2 << 7.9 << "  "<< 8.3 << "  "<< 8.4 << "  "<< 9.4 << "  "<< 9.88 << "  "<< 10.26 << "  "<< 10.9 << "  "<< 11.35 << "  "<< 12 << "  "<< 12.55<< "  ";
    ft2 << endl;
    ft2 << 10.3 << "  "<< 10.9 << "  "<< 11.5 << "  "<< 12.01 << "  "<< 12.59 << "  "<< 13.02 << "  "<< 13.52 << "  "<< 13.93 << "  "<< 14.25 << "  "<< 14.83 << "  ";
    ft2 << endl;
    ft2 << 13.25 << "  "<< 13.8 << "  "<< 14.2 << "  "<< 14.68 << "  "<< 15.13 << "  "<< 15.66 << "  "<< 16.03 << "  "<< 16.47 << "  "<< 17 << "  "<< 17.26 << "  ";
    ft2 << endl;
    ft2 << 16.6 << "  "<< 17.2 << "  "<< 17.65 << "  "<< 18.05 << "  "<< 18.47 << "  "<< 18.7 << "  "<< 19 << "  "<< 19.58 << "  "<< 20.8 << "  "<< 20.25 << "  ";
    ft2 << endl;
    ft2 << 18.4 << "  "<< 18.9 << "  "<< 19.1 << "  "<< 19.28 << "  "<< 19.65 << "  "<< 20.05 << "  "<< 20.38 << "  "<< 20.9 << "  "<< 21.1 << "  "<< 21.6 << "  ";
    ft2 << endl;
    ft2.close();        //就把ft相连的文件关闭。
    //输入文件结束。

    double H;
    H=6;    //高度(km)
    double T0;
    double P0;
    if (H<11)
    {   
        T0=288.15-6.5*H;
        P0=101325*pow(1-H/44.308,5.2553);
    }
    else
    {
        T0=216.7;
        P0=22700*exp((11-H)/6.338);
    }
   
    double k=1.4;
    double kg=1.33;
    double const1=(k-1)/k;
    double const2=-kg/(kg-1);
    double EFFb=0.98;
    double EFFm=0.98;
    double deltaH=43000; //KJ/kg
    double ccloss=0.03;
    double exloss=0.215; //燃烧室压损和排气压损
    double P5=P0/(1-exloss);
    double ERfpt=2;
    double ERfptacl=1;
    double ERmap=1.5;
    double ERcal=1.1;

    double RPM=50500;
    double BETA=1;
    double f;
    double m3[10]={7.78, 8, 8.5, 9, 9.5, 10, 10.5, 11, 11.5, 12};
    double erggt[10]={1.183, 1.195, 1.218, 1.238, 1.278, 1.322, 1.385, 1.468, 1.552, 1.722};
    double effggt[10]={0.736, 0.743, 0.771, 0.792, 0.818, 0.831, 0.842, 0.857, 0.86, 0.842};
    double m4[10]={13, 14, 15, 16, 17, 18, 19, 20, 21, 22};
    double erfpt[10]={1.081, 1.099, 1.12, 1.155, 1.2, 1.255, 1.303, 1.36, 1.478, 1.5};
    double efffpt[10]={0.8, 0.81, 0.82, 0.825, 0.83, 0.835, 0.84, 0.845, 0.84, 0.825};
    double PR;
    double EFF;
    double M1;
    double EFFggt;
    double M3;
    double M4;
    double T2;
    double P2;
    double T3;
    double T4;
    double P3;
    double P4;

    double Cp2;
    double PWRc;
    double t;
    double AAA;
    double PWRggt;
    double tt;
    double pwrggt;

    double T1=T0;
    double P1=P0;


    while (fabs(ERfptacl-ERfpt)/ERfpt>0.01 && BETA<10.1)
    {
        BETA=BETA+0.05;
        solution.input();    //由文件读入n*m个数据点(x, y, z)   
        PR = solution.interp(RPM, BETA);
        solution.output();          //输出插值点u,v处的近似值f到文件
        
        solution1.input();    //由文件读入n*m个数据点(x, y, z)   
        EFF = solution1.interp(RPM, BETA);
        solution1.output();          //输出插值点u,v处的近似值f到文件
        
        solution2.input();    //由文件读入n*m个数据点(x, y, z)   
        M1 = solution2.interp(RPM, BETA);
        solution2.output();          //输出插值点u,v处的近似值f到文件
        
        P2=P1*PR;;
        T2=T1*(1+(pow(PR,const1)-1)/EFF);
        PWRc=air_H(T2)-air_H(T1);  //压气机功(kw)
        Cp2=air_Cp(T2);
        P3=P2*(1-ccloss);
        f=0.19;
        while (fabs(ERmap-ERcal)/ERmap>0.01)
        {
            f=f+0.0005;
            T3=T2;
            t=1100;
            while(abs(T3-t)/t>0.001)
            {
                t=T3;
                AAA=(1+f)*gas_Cp(t,f);
                T3=(Cp2*T2+EFFb*f*deltaH)/AAA;
            }
            
            PWRggt=PWRc/(EFFm*(1+f));
            T4=T3;
            pwrggt=PWRggt/2;
            while (fabs(PWRggt-pwrggt)/PWRggt>0.01)
            {
                tt=T4;
                pwrggt=gas_H(T3,f)-gas_H(tt,f);
                T4=tt-1;
            }
            M3=M1*(1+f)*pow(T3/T1,0.5)*(P1/P3);
            ERmap=newton_solution(m3, erggt, 9, M3, 9);
            EFFggt=newton_solution(m3, effggt, 9, M3, 9);
            ERcal=pow((1-(1-T4/T3)/EFFggt),const2);
        }

        P4=P3/ERcal;
        M4=M3*pow(T4/T3,0.5)*(P3/P4);
        ERfpt=newton_solution(m4, efffpt, 9, M4, 9);
        ERfptacl=P4/P5;
    }
   
    cout <<"PR= "<< PR << endl;
    cout <<"EFF= "<< EFF << endl;
    cout <<"M1= "<< M1 << endl;
    cout<<"f= "<<f<<endl;
    cout<<"T2= "<<T2<<endl;
    cout<<"M3= "<<M3<<endl;
    cout<<"T3= "<<T3<<endl;
    cout<<"T4= "<<T4<<endl;
    cout<<"ERcal= "<<ERcal<<endl;
    cout<<"ERfpt= "<<ERfpt<<endl;
    cout<<"ERfptacl= "<<ERfptacl<<endl;
    return 0;
}
2019-02-11 11:41







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.167452 second(s), 9 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved