user3476225
user3476225

Reputation: 240

Avoid inverse of matrix

I want to avoid computing the inverse of a matrix. I am writing code in C, so I cannot use MATLAB commands for this. I want to perfrom the following calculation:

v = bk/G;

bk is a 2 × 1 matrix and G is a 2 × 2 matrix, v is a float variable.

I am currently doing this:

V = G^-1 * bk;

This way, I have to use the division operator for finding G^-1. I want to avoid using divisions.

Upvotes: 0

Views: 416

Answers (1)

Mad Physicist
Mad Physicist

Reputation: 114330

It seems that you are trying not so much avoid inverting a matrix as to find a different way to do it. Since G is a 2x2 matrix, you lucked out as it is trivial to compute the inverse of a 2x2 matrix.

G = [a b; c d]
G^-1 = (1/det(G)) * [d -b; -c a]

or in C:

double a, b, c, d;
double *G = {a, c, b, d}; // I used matlab internal (column-wise) order for the matrix here
double det = a * d - b * c;
if(det == 0.0) { /* Throw up your hands and lament */ }
double Ginv = {d / det, -c / det, -b / det, a / det};

where det(G) is the determinant: ad - bc. You can use the determinant to test if the matrix is invertible in the first place. If det(G) == 0, one over the determinant is undefined and the matrix is non-invertible.

Upvotes: 4

Related Questions