473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Inverse of a matrix

I need a help in C++ for the following question:
write a p[rogram to read 4 by 4 matrix, store it and find the inverse of this matrix. then multiply the inverse with the original matrix , store it . lastly print the inverse of the matrix which is output of multiplication.

Could you help me please...somebody..????
Sep 15 '07 #1
3 6339
mattmao
121 100+
Hello aaram81:

Conceputally speaking, you can do this program in this way:

create a two-dimensional array, array[4][4], each of the "cell" -- array[x][y] would be used to store its corresponding value in the matrix.

Create another two-dimensional array inversed[4][4] for storing the inversed array.

Let the user key in the values and store them in the array[4][4]

Then use for loops to iterate through all the cells of the array to inverse it, say,
inversed[x][y] = array[y][x];

There you go, you got the inversed array, and you can do more from that basis.


My logic is fine, the only thing that lacks here is the implementation of coding, you can do that yourself:)


Sincerely yours,

Matt
Sep 15 '07 #2
mattmao i think you are confusing matrix inversion with matrix transposition.
see: http://en.wikipedia.org/wiki/Inverse_matrix

Inverting a matrix is a bit more complex. One solution would be to calculate its determinant and use:
B being the inversed matrix of A:
B = (1/determinant(A)) * Ck(A)

Please note that if determinant(A) = 0, then the matrix cannot be inversed, therefore you should stop the process at this point.

Ck(A) is the matrix of cofactors of A. To calculate the Ck(A) matrix you have to build a matrix of Minors of A then apply the right sign to each cell.
see: http://en.wikipedia.org/wiki/Cofactor_%28mathematics%29

Minor(A,i,j) would be the determinant of A when removing line i and column j.
So here you have to calculate a determinant for each cell, which makes 16 determinants. You then have the matrix of minors, lets call it M.

To obtain Ck(A) you simply change the sign of the cells of M in the following manner: Ck(A)[i][j] = (-1)^(i+j)*M[i][j]

You now have Ck(A) and can get B using the following formula:
B = (1/determinant(A)) * Ck(A)
Sep 15 '07 #3
JosAH
11,448 Expert 8TB
Never explicitly calculate the inverse of a matrix; it's numerically unstable. Use
a LUP decomposition instead: let L and U be lower and upper triangular matrixes
and let P be a row permutation matrix such that LU = PA. A permutation matrix
has exactly one 1 per row and column (all the other elements are zero).

Finding matrixes L and U is just a repeated Gauss row operation and P takes
care that the largest absolute pivot element is used.

For a linear system Ax= b:

PAx= Pb (permute the elements of vector b) -->
(Pb= b') LUx= b' -->
Ly = b' (find y by backward substitution) -->
Ux = y (find x by forward substitution).

Google is your friend: LUP decomposition.

kind regards,

Jos
Sep 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: vishnu mahendra | last post by:
hello to all, can any one please give me an algorithm to find inverse of a matrix of order n rows and m columns. thank you in advance, vishnu.
11
by: Budiman | last post by:
Hello friends, i need help for my assignment. For example i give input for a, b, c, d in matrix mode example like |a b| |c d| and i want to convert it to invers from that matrix, i hope you give...
14
by: Paul McGuire | last post by:
I've posted a simple Matrix class on my website as a small-footprint package for doing basic calculations on matrices up to about 10x10 in size (no theoretical limit, but performance on inverse is...
2
by: leelaramtenneti | last post by:
hello I need a program to find a Inverse of a square complex matrix in java... . The program should calculate the inverse of a matrix in which each element has both real and imaginary parts. Or...
0
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
1
by: dazzler | last post by:
Hi! I have problem with numpy, multiplying with an inversed matrix will crash python :( this works fine: from numpy import matrix A = matrix(,]) B = matrix(,]) print A.I #inverse matrix
8
by: SpeedMath | last post by:
http://i82.photobucket.com/albums/j247/Harry_goh/HelpPython.jpg
6
by: atemuoh1991 | last post by:
#include <stdio.h> #include <math.h> #include <malloc.h> #include <stdlib.h> #include <time.h> struct SMatrix { double** pValues;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.