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

📄 d11r10.cpp

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

void main()
{
	//program d11r10
    //driver for routine simplx
    //incorporates  examples discussed in text
    int icase,i,j,jj,jmax,nm1m2,n = 4;
	int m = 4;
    int np = 5;
    int mp = 6;
    int m1 = 2;
    int m2 = 1;
    int m3 = 1;
    nm1m2 = n + m1 + m2;
    double a[7][6],anum[6],a1[31];
	int izrov[5], iposv[5];
	char* txt[8];
	char* alpha[6];

    txt[1] = "x1"; txt[2] = "x2"; txt[3] = "x3"; txt[4] = "x4";
    txt[5] = "y1"; txt[6] = "y2"; txt[7] = "y3";
    a[1][1]=0.0; a[1][2]=1.0; a[1][3]=1.0; a[1][4]=3.0; a[1][5]=-0.5;
    a[2][1]=740; a[2][2]=-1.0;a[2][3]=0.0; a[2][4]=-2.0;a[2][5]=0.0;
    a[3][1]=0.0; a[3][2]=0.0; a[3][3]=-2.; a[3][4]=0.0; a[3][5]=7.0;
    a[4][1]=0.5; a[4][2]=0.0; a[4][3]=-1.; a[4][4]=1.0; a[4][5]=-2.0;
    a[5][1]=9.0; a[5][2]=-1.0;a[5][3]=-1.; a[5][4]=-1.0;a[5][5]=-1.0;
    a[6][1]=0.0; a[6][2]=0.0; a[6][3]=0.0; a[6][4]=0.0; a[6][5]=0.0;
	
	for (i=1; i<=mp; i++)
	{
		for (j=1; j<=np; j++)
		{
			a1[(i-1)*np+j]=a[i][j];
		}
	}
    simplx(a1, m, n, mp, np, m1, m2, m3, icase, izrov, iposv);
    if (icase == 1)
	{
        cout<<"unbounded objective function"<<endl;
	}
    else
	{
		if (icase == -1)
		{
			cout<<"no solutions satisfy constraints given"<<endl;
		}
		else
		{
			jj = 1;
			for (i = 1; i<=n; i++)
			{
				if (izrov[i] <= n + m1 + m2)
				{
					alpha[jj]=txt[izrov[i]];
					jj = jj + 1;
				}
			}
			jmax = jj - 1;
			cout.setf(ios::fixed|ios::left);
			cout.precision(3);
			cout<<endl;
			cout<<"                       ";
			for (jj = 1; jj<=jmax; jj++)
			{
				cout<<alpha[jj];
				cout<<"          ";
			}
			cout<<endl;
			for (i = 1; i<=m + 1; i++)
			{
				if (i > 1)
				{
					alpha[1]=txt[iposv[i - 1]];
				}
				else
				{
					alpha[1]="  ";
				}
				anum[1] = a1[(i-1)*np+1];
				jj = 2;
				for (j = 2; j<=n + 1; j++)
				{
					if (izrov[j - 1] <= (n + m1 + m2))
					{
						anum[jj] = a1[(i-1)*np+j];
						jj = jj + 1;
					}
				}
				jmax = jj - 1;
				cout<<alpha[1]<<"      ";
				for (jj = 1; jj<=jmax; jj++)
				{
					cout.width(12);
					cout<<anum[jj];
				}
				cout<<endl;
			}
		}
	}
}

⌨️ 快捷键说明

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