Matrix Multiplication 2 - Error Message

This is a discussion on Matrix Multiplication 2 - Error Message within the C++ Programming forums, part of the General Programming Boards category; Can anyone please explain what this error message means? error 139 - Argument no 2 of 'scaling_multiplication' must be of ...

  1. #1
    dlf
    dlf is offline
    Registered User
    Join Date
    Nov 2005
    Posts
    17

    Matrix Multiplication 2 - Error Message

    Can anyone please explain what this error message means?

    error 139 - Argument no 2 of 'scaling_multiplication' must be of type '<ptr>(double[3])', not 'int[3][3]'

    My code is below:

    Code:
    void scaling (double line[][3])
    {
       
       double s;
       double new_line2[2][3];
       
       printf("\nHow much would you like to scale the line by?\nEnter a value between 0 and 1:");
       scanf("%lf", &s);
    
       int scaling_matrix[3][3] = { {s, 0, 0}, {0, s, 0}, {0, 0, s} };
       
     scaling_multiplication(line, scaling_matrix, new_line2);
       
       printf("\nThe new start coordinates are: (%lf,%lf,%lf)", new_line2[0][0], new_line2[0][1], new_line2[0][2]);
       printf("\nThe new end coordinates are: (%lf,%lf,%lf)", new_line2[1][0], new_line2[1][1], new_line2[1][2]);
    }  
    
    
    void scaling_multiplication (double a[][3], double b[][3], double F[][3])
    {
    
       for(i=0; i<3; i++)
       {
    	 for(j=0; j<3; j++)
    	 {
    	    for(k=0; k<3; k++)
    	    {
    		  F[i][j] = a[i][k] + b[k][j];
    	    }
    	 }
       }
    }

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    You're passing scaling_multiplication() an integer array, and it expects a double one. (Not really an error, but still.)

    Code:
    int scaling_matrix[3][3] = { {s, 0, 0}, {0, s, 0}, {0, 0, s} };
    s is a double.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    scaling_matrix is a 2-d int array but the function is expecting a 2-d double array. There is no automatic conversion, it is an error.

  4. #4
    dlf
    dlf is offline
    Registered User
    Join Date
    Nov 2005
    Posts
    17
    Thanks for the help. I have made the change.

    The program now runs, where as it didn't before but it comes up with an error when I try to use the scaling function.

    Any suggestions?

    Code:
    void scaling (double line[][3])
    {
       
       double s;
       double new_line2[2][3];
       
       printf("\nHow much would you like to scale the line by?\nEnter a value between 0 and 1:");
       scanf("%lf", &s);
    
       double scaling_matrix[3][3] = { {s, 0, 0}, {0, s, 0}, {0, 0, s} };
       
    
    
       scaling_multiplication(line, scaling_matrix, new_line2);
       
       printf("\nThe new start coordinates are: (%lf,%lf,%lf)", new_line2[0][0], new_line2[0][1], new_line2[0][2]);
       printf("\nThe new end coordinates are: (%lf,%lf,%lf)", new_line2[1][0], new_line2[1][1], new_line2[1][2]);
    }  
    
    
    void scaling_multiplication (double a[][3], double b[][3], double F[][3])
    {
    
    int i, j, k;
       for(i=0; i<3; i++)
       {
    	 for(j=0; j<3; j++)
    	 {
    	    for(k=0; k<3; k++)
    	    {
    		  F[i][j] = a[i][k] + b[k][j];
    	    }
    	 }
       }
    }

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    new_line2 is a 2x3 matrix, you pass it as the third argument to the function (which is F[][3]). Then you use the index i (which goes from 0 to 2) on the first dimension. But the first dimension of new_line2 only allows 0 or 1. When you use index 2, it fails. Maybe you meant to make new_line2 3x3.

  6. #6
    dlf
    dlf is offline
    Registered User
    Join Date
    Nov 2005
    Posts
    17
    My code now works with no errors. THANK YOU.

    But when I run the program and use the scaling function, I get incorrect values. Ar emy equations correct?

    Code:
    void scaling (double line[][3])
    {
       //double a=0;
       double s;
       double new_line2[2][3];
       
       printf("\nHow much would you like to scale the line by?\nEnter a value between 0 and 1:");
       scanf("%lf", &s);
    
       double scaling_matrix[3][3] = { {s, 0, 0}, {0, s, 0}, {0, 0, s} };
       
    
       //scaling_matrix[0][0]=s;
       //scaling_matrix[1][0]=0;
       //scaling_matrix[2][0]=0;
       //scaling_matrix[0][1]=0;
       //scaling_matrix[1][1]=s;
       //scaling_matrix[2][1]=0;
       //scaling_matrix[0][2]=0;
       //scaling_matrix[1][2]=0;
       //scaling_matrix[2][2]=s;
       
       scaling_multiplication(line, scaling_matrix, new_line2);
       
       printf("\nThe new start coordinates are: (%lf,%lf,%lf)", new_line2[0][0], new_line2[0][1], new_line2[0][2]);
       printf("\nThe new end coordinates are: (%lf,%lf,%lf)", new_line2[1][0], new_line2[1][1], new_line2[1][2]);
    }  
    
    
    void scaling_multiplication (double a[][3], double b[][3], double F[][3])
    {
       //F[0][0]=D[0][0]*E[0][0];
       //F[0][1]=D[1][0]*E[0][1];
       //F[0][2]=D[2][0]*E[0][2];
       //F[1][0]=D[0][1]*E[1][0];
       //F[1][1]=D[1][1]*E[1][1];
       //F[1][2]=D[2][3]*E[1][2];
    int i, j, k;
       for(i=0; i<2; i++)
       {
    	 for(j=0; j<3; j++)
    	 {
    	    for(k=0; k<2; k++)
    	    {
    		  F[i][j] = a[i][k] + b[k][j];
    	    }
    	 }
       }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. *operator overloading: scalar matrix multiplication
    By gemini_shooter in forum C++ Programming
    Replies: 4
    Last Post: 06-08-2009, 01:14 PM
  3. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 04:57 PM
  4. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-13-2004, 11:19 PM

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