Revised Simplex Method

This is a discussion on Revised Simplex Method within the C Programming forums, part of the General Programming Boards category; Hey im having trouble coding a program to caculate the revised simplex method of a nxm matrix and was wondering ...

  1. #1
    CJM
    CJM is offline
    Registered User
    Join Date
    Dec 2010
    Posts
    5

    Revised Simplex Method

    Hey im having trouble coding a program to caculate the revised simplex method of a nxm matrix and was wondering if anyone has any code to do so.

    so you dont think im just wanting CWK help here is my current program im working on that sorta works
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    #include<stdlib.h>
    
    int bMATRIX[10][10];
    void DETINV(int mSIZE, double **MATB);
    void arg(int *a,int *b,int *n,int x,int y);
    int det(int *p,int *n);
    double **MATa;
    double **MATB;
    double *MATb;
    double *MATc;
    double *MATcBT;
    
    int main()
    {
      int nSIZE = 1;
      int mSIZE = 1;
      int n1SIZE = 1;
    
      int i, j;
    
          printf("REVERSE SIMPLEX METHOD \n\nEnter size [n] : ");
          scanf("%d", &nSIZE);
    	  printf("Enter size [m] : ");
          scanf("%d", &mSIZE);
    
    	  n1SIZE = nSIZE-mSIZE;
    	  while ( n1SIZE <= 0 )
    	  {
    		printf("\n!!INVALID MATRIX SIZE!!\nPlease reenter size [n] : ");
    		scanf("%d", &nSIZE);
    		printf("Please reenter size [m] : ");
    		scanf("%d", &mSIZE);
    		n1SIZE = nSIZE-mSIZE;
    	  }
    
    ////////////////////////////////////////////
          MATa = malloc(mSIZE*sizeof*MATa);
    
          for(i=0;i<mSIZE;++i)
    	  {
    		  MATa[i]=malloc(nSIZE*sizeof**MATa);
    	  }
    ////////////////////////////////////////////
    	  MATB = malloc(mSIZE*sizeof*MATB);
    
          for(i=0;i<mSIZE;++i)
    	  {
    		  MATB[i]=malloc(mSIZE*sizeof**MATB);
    	  }
    
    ////////////////////////////////////////////	
    	  MATc = malloc(nSIZE*sizeof*MATc);
    ////////////////////////////////////////////	
    	  MATb = malloc(mSIZE*sizeof*MATb);
    ////////////////////////////////////////////
    
    ////////////////////////////////////////////
          printf("Please enter values of\n");
    	  for(i=0;i<mSIZE;i++)
    	  {
    		for(j=0;j<nSIZE;j++)
    		  {	
    			printf("a%d,%d: ", i+1, j+1);
    			scanf( "%lf", &MATa[i][j]);
    		  }
    	  }
    
          printf("Please enter values of\n");
    	  for(i=0;i<mSIZE;i++)
    	  {
    		printf("b%d,1: ", i+1);
    		scanf( "%lf", &MATb[i]);
    	  }
    	  printf("Please enter the coefficients of x in Zequation\n");
    	  for(i=0;i<nSIZE;i++)
    	  {
    		printf("x%d: ", i+1);
    		scanf( "%lf", &MATc[i]);
    	  }
    ///////////////////////////////////////
    	  printf("This is called matrix 'A'=\n");
    	  for(i=0;i<mSIZE;i++)
    		{
    			for(j=0;j<nSIZE;j++)
    				{
    					printf("%1.0lf  ", MATa[i][j]);
    				}
    			printf("\n");
    		}
    	  printf("\n");
    	  printf("This is called matrix 'b'=\n");
    	  for(i=0;i<mSIZE;i++)
    		{
    			printf("%1.0lf", MATb[i]);
    			printf("\n");
    		}
    	  	  printf("This is called matrix 'c'=\n");
    	  for(i=0;i<nSIZE;i++)
    		{
    			printf("%1.0lf  ", MATc[i]);
    			
    		}
    ////////////////////////////////////////
    
    ////////////////////////////////////////
    	  printf("\nThis gives matrix 'B':\n");
    	  for(i=0;i<mSIZE;i++)
    	  {
    		for(j=n1SIZE;j<nSIZE;j++)
    		{
    			MATB[i][j] = MATa[i][j];
    			printf("%1.0lf  ", MATB[i][j]);
    		}
    	    printf("\n");
    	  }
    	  printf("\n");	
    //////////////////////////////////////////	  
    	  printf("\nThis gives matrix 'K':\n");
    	  for(i=0;i<mSIZE;i++)
    	  {
    		for(j=0;j<n1SIZE;j++)
    		{
    			printf("%1.0lf  ", MATa[i][j]);
    		}
    	    printf("\n");
    	  }
    	  printf("\n");
    ///////////////////////////////////////
    
    ///////////////////////////////////////
    
    printf("\nNow to caculate matrix 'cB'/L=\n");
    	  for(i=0;i<n1SIZE;i++)
    		{
    			printf("%1.0lf  ", MATc[i]);
    			
    		}
    printf("\nTransposing matrix 'cB' gives 'cBT'=\n");
    	  MATcBT = malloc(n1SIZE*sizeof*MATcBT);
    	  for(i=0;i<n1SIZE;i++)
    		{
    			MATcBT[i] = MATc[i];
    			printf("%1.0lf\n", MATcBT[i]);
    		}
    
    printf("\n\n\n!!ALL WORKING TO HERE!!\n\n\n");
    DETINV(mSIZE, MATB);//this function call doesnt work :(
    
    
        //  for(i=0;i<mSIZE;++i) free(MATa[i]);
         // free(MATa);
        }
       
    void DETINV(int mSIZE, double **MATB)
    {
    int a[10][10],b[10][10],c[10][10];
    int n,n1,i,j,m,d,q;
    n = mSIZE;
    n1= mSIZE;
    	  for(i=1;i<(mSIZE+1);i++)
    	  {
    		for(j=1;j<(mSIZE+1);j++)
    		{
    			q = (double)MATB[i][j];
    
    		}
    	    printf("\n");
    	  }
    
    	   printf("\setting up data for the functions\n");
    	  for(i=1;i<(mSIZE+1);i++)
    	  {
    		for(j=1;j<(mSIZE+1);j++)
    		{
    			printf("[%d] [%d] ", i, j); 
    			printf("%d ", a[i][j]);
    			a[i][j] = q;
    
    		}
    	    printf("\n");
    	  }
    
    if(n==2)
    {
    c[0][0]=a[1][1];
    c[1][1]=a[0][0];
    c[0][1]=-a[0][1];
    c[1][0]=-a[1][0];
    d=a[0][0]*a[1][1]-a[0][1]*a[1][0];
    printf("Determinant is:%d\n",d);
    if(d==0)
    {
    getch();
    exit(d-'0');
    }
    
    for(i=0;i<n;i++)
    {
    printf("\n");
    for(j=0;j<n;j++)
    printf(" %f",c[i][j]/(float)d);
    
    }
    }
    else
    {
    m=n;
    for(i=0;i<m;i++)
    {
    for(j=0;j<m;j++)
    {
    n=m;
    arg(&a[0][0],&b[0][0],&n,i,j);
    c[j][i]=pow(-1,(i+j))*det(&b[0][0],&n);
    }
    }
    n=m;
    d=det(&a[0][0],&n);
    printf("Determinant is :%d\n",d);
    if(d==0)
    {
    printf("INVERSE DOES NOT EXIST");
    getch();
    exit(d-'0');
    }
    printf("Inverting matrix 'B' gives 'B-1'=\n");
    for(i=0;i<m;i++)
    {
    printf("\n");
    for(j=0;j<m;j++)
    printf(" %f",c[i][j]/(float)d);
    }
    }	 getch();
    }
    
    void arg(int *a,int *b,int *n,int x,int y)
    {
    int k,l,i,j;
    for(i=0,k=0;i<*n;i++,k++)
    {
    for(j=0,l=0;j<*n;j++,l++)
    {
    if(i==x)
    i++;
    if(j==y)
    j++;
    *(b+10*k+l)=*(a+10*i+j);
    
    }
    }
    *n=*n-1;
    }
    
    int det(int *p,int *n)
    {
    int d[10][10],i,j,m,sum=0;
    m=*n;
    if(*n==2)
    return(*p**(p+11)-*(p+1)**(p+10));
    for(i=0,j=0;j<m;j++)
    {
    *n=m;
    arg(p,&d[0][0],n,i,j);
    sum=sum+*(p+10*i+j)*pow(-1,(i+j))*det(&d[0][0],n);
    }
    
    return(sum);
    }
    Please help
    i know there are some amazing coders out there

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    Major problem with arrays
    Check the last post.

    Does your code look that good?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You have literally opened like 4 threads on this program and you have not followed even the simplest instructions provided, such as INDENTING YOUR CODE. As it is right now, I doubt anyone sane will read it.

    Free tip: Posting the same thing over and over and over will only get people less inclined to help you.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Packet Container Class
    By ChaoticXSinZ in forum C++ Programming
    Replies: 2
    Last Post: 11-01-2010, 12:07 AM
  2. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 06:50 PM
  3. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 04:17 PM
  4. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-07-2008, 11:30 PM
  5. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21