Thread: i think theres a couple errors?

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    25

    i think theres a couple errors?

    this is not the entire code but i dnt know if i put a certain part in the correction location
    its the red part
    insert
    Code:
    smatrix(A,x,n);
    n=4;
    double A_t, A_s, y;
    int i,j;
    for (i=0; i<rowLength; i++)
      for (j=0; j<colLength; j++)
        A_t[j][i] = A[i][j];
    A_t=(double **)calloc(4,sizeof(double *));
    for(i=0;i<4;i++)
    A_t[i]=(double *)calloc(4 ,sizeof(double));
    
    printf("Matrix A_s is:\n\n ");
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[0][q]);
    printf("\n");
    
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[1][q]);
    printf("\n");
    
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[2][q]);
    printf("\n");
    
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[3][q]);
    printf("\n\n");
    
    printf("Vector y is:");
    printf("\n\n");
    printf(" y[] =  ");
    for(q=0;q<4;q++)
    printf("%6.3f  ",b[j]);
    printf("\n\n");
    free(A);
    free(A_s);
    free(x);
    free(y);
    }
    
    
    void smatrix(double **A, double *x, double x[], double y[], double A_s, double norm_x);
    {
    int i, j, k;
       for(i=0; i<4; i++)
       {
    	    for(k=0; k<4; k++)
    	    {
    		  A_s[i][k] = (A[i][k]+A_t[i][k])/2;
    	    }
       }
    
    double dotp (double A_s[], double x[], double n) 
    {
      int output;
      output = 0;
      int i;
      for (i=0; i<n; i++)
        result += A_t[i]*x[i];
      return output;
    }
      
    double norm_x, storage, add;
    int k,
    for(k=0;k<n;k++)
     {
      add = x[k] * x[k];
      storage = storage + add;
     }
     norm_x=sqrt(sum);
     return norm_x;
    }

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    You need to malloc A_t before you put anything in it, and you need to declare is as double **A_t if you want it to be a 2D array.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    Code:
    smatrix(A,x,n);
    n=4;
    double **A_t, A_s, *y;
    int i,j;
    for (i=0; i<rowLength; i++)
      for (j=0; j<colLength; j++)
        A_t[j][i] = A[i][j];
    A_t=(double **)calloc(4,sizeof(double *));
    for(i=0;i<4;i++)
    A_t[i]=(double *)calloc(4 ,sizeof(double));
    y=(double *)malloc(4*sizeof(double));
    
    printf("Matrix A_s is:\n\n ");
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[0][q]);
    printf("\n");
    
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[1][q]);
    printf("\n");
    
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[2][q]);
    printf("\n");
    
    for(q=0;q<4;q++)
    printf("%6.3f ",A_s[3][q]);
    printf("\n\n");
    
    printf("Vector y is:");
    printf("\n\n");
    printf(" y[] =  ");
    for(q=0;q<4;q++)
    printf("%6.3f  ",b[j]);
    printf("\n\n");
    free(A);
    free(A_s);
    free(x);
    free(y);
    }
    
    
    void smatrix(double **A, double *x, double x[], double y[], double A_s, double norm_x);
    {
    int i, j, k;
       for(i=0; i<4; i++)
       {
    	    for(k=0; k<4; k++)
    	    {
    		  A_s[i][k] = (A[i][k]+A_t[i][k])/2;
    	    }
       }
    
    double dotp (double A_s[], double x[], double n) 
    {
      int output;
      output = 0;
      int i;
      for (i=0; i<n; i++)
        result += A_t[i]*x[i];
      return output;
    }
      
    double norm_x, storage, add;
    int k,
    for(k=0;k<n;k++)
     {
      add = x[k] * x[k];
      storage = storage + add;
     }
     norm_x=sqrt(sum);
     return norm_x;
    }
    okay i did i fix it correctly?

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    also are there ways to reduce my program

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    Code:
    double **A_t, A_s, *y;
    int i,j;
    for (i=0; i<rowLength; i++)
      for (j=0; j<colLength; j++)
        A_t[j][i] = A[i][j];
    A_t=(double **)calloc(4,sizeof(double *));
    for(i=0;i<4;i++)
    A_t[i]=(double *)calloc(4 ,sizeof(double));
    y=(double *)malloc(4*sizeof(double));
    You need to malloc:

    Code:
    A_t=(double **)calloc(4,sizeof(double *));
    for(i=0;i<4;i++)
    A_t[i]=(double *)calloc(4 ,sizeof(double));
    y=(double *)malloc(4*sizeof(double));
    before you write anything to that array:

    Code:
    for (i=0; i<rowLength; i++)
      for (j=0; j<colLength; j++)
        A_t[j][i] = A[i][j];

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    25
    ugh why isnt this clicking to me, ive been working on it for so long that its not

  7. #7
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    Just reverse the order of those code blocks lol.

    I am sure that it is not the only error by far, but it will fix at least one of them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  3. Help with a couple compiler errors
    By s_ny33 in forum C Programming
    Replies: 1
    Last Post: 09-15-2005, 08:46 PM
  4. Errors when including winsock2.h
    By skiingwiz in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2002, 07:32 PM
  5. Replies: 5
    Last Post: 11-13-2001, 04:38 PM