We help IT Professionals succeed at work.

Source Code to find Inverse of N X N matrix in C or in C++

Shiju Sasidharan
on
Medium Priority
31,415 Views
Last Modified: 2012-06-22
Hi Experts

I would like to have source code to find Inverse of N X N matrix
either in C or in C++

Any algorithm can be used Crout's, Gaus' or finding co-factor

Regards
Shiju S N
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006
Commented:

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Shiju SasidharanSenior IT Developer

Author

Commented:
@ sunnycoder
Thank you for the code.

I am also hoping for a C++ stuff with operator overloaded.
CERTIFIED EXPERT
Top Expert 2006

Commented:
>I am also hoping for a C++ stuff with operator overloaded.

Homework ?
Shiju SasidharanSenior IT Developer

Author

Commented:
sorry, i am not asking for home work job.
If any one has got link or source code then pls provide
CERTIFIED EXPERT
Top Expert 2006

Commented:
Sounds very strange that you impose a restriction like C++ with operator overloading, unless the specific requirement of an assignment is to use operator overloading ... else, any code that does the job should suffice.
Shiju SasidharanSenior IT Developer

Author

Commented:
>>impose a restriction
Please appologise if my comment gave such an impression
>>>>  I am also hoping for a C++ stuff with operator overloaded

Suppose, you think of overloading unary operator~.

Take the sample sunnycoder gave you a link to.

Make the three functions

   
    double Determinant(double **a,int n)

    void CoFactor(double **a,int n,double **b)

    void Transpose(double **a,int n)


member functions of a class Matrix. 'a' and 'n' were data members of the class while 'b' needs to be passed as 'Matrx& b'. Determinant, CoFactor and Transpose have no arguments then. The rest of the implementation code should compile with minor changes (e. g. replace malloc/free by new/delete).

Then

    Matrix& Matrix::operator~()
    {
            Matrix b = *this;  // make a copy

            CoFactor();
            Transpose( );

            (*this) /= b.Determinant();
            return *this;
    }

Beside of the three functions you would a copy constructor/assignment operator and a operator/= where the prototype is

   Matrix& Matrix::operator/=(double d);

Regards, Alex

   

Shiju SasidharanSenior IT Developer

Author

Commented:
Thank you friends
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.