Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inverse matrix and integer result in Octave?

I would like to get an invertible matrix in Octave but as integers matrix, so:

x = [9,15;19,2];
inv(x)

Here I get:

[-0.0074906, 0.0561798; 0.0711610, -0.0337079]

but I would like to get [22,17;25,21] anyone knows how to invert a matrix?

like image 625
J.R. Avatar asked Jan 17 '10 00:01

J.R.


People also ask

How do you reverse a matrix in octave?

To flip a matrix about the horizontal axis (up to down), call the flipud function. To flip a matrix about the vertical axis (left to right), call the fliplr function. These functions are from Matlab and so work in it too.

How do you take the inverse of a matrix in Matlab?

Y = inv( X ) computes the inverse of square matrix X . X^(-1) is equivalent to inv(X) .

Can you invert the identity matrix?

FAQs on Inverse of Identity Matrix Since the product of the identity matrix with itself is equal to the identity matrix, therefore the inverse of identity matrix is the identity matrix itself.

How do you invert a matrix?

To find the inverse of a 2x2 matrix: swap the positions of a and d, put negatives in front of b and c, and divide everything by the determinant (ad-bc).


2 Answers

The inverse of each element is:

x .^ -1

Which results

0.1111    0.0667
0.0526    0.5000

Why you want to get [22,17;25,21]? What mathematical operation would yield such result?

like image 138
Jader Dias Avatar answered Sep 28 '22 02:09

Jader Dias


Invert a matrix in octave:

You are confused about what an inverse of a matrix is, don't nobody here knows what you want with your output, so here are some clues.

If you Invert an identity matrix, you get the identity matrix:

octave:3> a = [1,0;0,1]
a =

   1   0
   0   1

octave:4> inv(a)
ans =

   1   0
   0   1

Non-square matrices (m-by-n matrices for which m != n) do not have an inverse

x = [9,15;19,2;5,5]; 
inv(x) 
%error: inverse: argument must be a square matrix

Inverting a matrix with a zero on the diagonal causes an infinity:

octave:5> a = [1,0;0,0]
a =

   1   0
   0   0

octave:6> inv(a)
warning: inverse: matrix singular to machine precision, rcond = 0
ans =

   Inf   Inf
   Inf   Inf

Inverting a matrix with full values like this:

octave:1> a = [1,2;3,4]
a =
   1   2
   3   4

octave:2> inv(a)
ans =    
  -2.00000   1.00000
   1.50000  -0.50000

For a description of what is happening under the hood of the inverse function:

https://www.khanacademy.org/math/precalculus/precalc-matrices/inverting_matrices/v/inverse-of-a-2x2-matrix

like image 41
Eric Leschinski Avatar answered Sep 28 '22 01:09

Eric Leschinski