473,749 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inverse of a matrix

1 New Member
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...somebo dy..????
Sep 15 '07 #1
3 6382
mattmao
121 New Member
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
cellerit
1 New Member
mattmao i think you are confusing matrix inversion with matrix transposition.
see: http://en.wikipedia.or g/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.or g/wiki/Cofactor_%28mat hematics%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 Recognized Expert MVP
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
25204
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
14662
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 the answer(if possible with the explanation). Thx so much for your help
14
6217
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 exponential). Includes: - trace - transpose - conjugate - determinant - inverse - eigenvectors/values (for symmetric matrices)
2
13327
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 atleast help me in finding inverse of a ordinary n*n square matrix in java
0
2810
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 Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY...
1
15249
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
2222
by: SpeedMath | last post by:
http://i82.photobucket.com/albums/j247/Harry_goh/HelpPython.jpg
6
4875
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
8997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.