单纯形法的c语言实现

单纯形法的c语言实现

#include
#define m 3//行
#define n 5//列
int min(float a[n],int l){
float min=+9999;
int i,t;
for(i=0;i {
if(a[i] {
min=a[i];
t=i;
}
}
return t;
}

int pd(float a[n]){
int i,j=0;
for(i=0;i if(a[i]>=0)
j++;
if(j==n)
return 0;
else
return 1;
}

void main(){
float s[m][n+3]={{0.25,0.5,1,0,0,120,3,0},{0.5,0.5,0,1,0,150,4,0},{0.25,0,0,0,1,50,5,0}};
float x[5]={-12,-15,0,0,0};
float y[n+1];
float q[m];
int i,j,my,mq;
float tem;
float chu,ru,cs;
printf("------------------------------------------------------------\n");
for(i=0;i y[i]=-1;
printf(“cb xb b x1 x2 x3 x4 x5 “);
while(pd(y))
{
printf(”\n------------------------------------------------------------\n”);
for(i=0;i {
tem=0;
for(j=0;j tem=tem+s[j][n+2]*s[j][i];
y[i]=x[i]-tem;
//printf("%f",y[i]);
}
for(i=0;i<3;i++)
{
printf("%-8.2f",s[i][n+2]);
printf("%-8.2f",s[i][n+1]);
printf("%-8.2f",s[i][n]);
for(j=0;j<5;j++)
printf("%-8.2f",s[i][j]);
printf("\n");
}
printf(" -z: “);
y[n]=0;
for(i=0;i y[n]=y[n]+s[i][n]*s[i][n+2];
printf(”%-8.2f",-y[n]);

	for(i=0;i<5;i++)
	{
		printf("%-8.2f",y[i]);
	}				
	my=min(y,5);
	ru=my+1;//确定入基变量
	//printf("%d",my);
	for(i=0;i

}

你可能感兴趣的:(单纯形法)