2 x 2 matrix division

A 2 x 2 matrix A multiplied by a 2 x 2 matrix B is a 2 x 2 matrix AB. This tool helps to find the inverse of matrix B so that we can find out what matrix A is.

Multiplication of a matrix:

(1)
\begin{align} \left(\ \begin{matrix} a & b \\ c & d \end{matrix}\right) \left(\ \begin{matrix} e & f \\ g & h \end{matrix}\right) = \left(\ \begin{matrix} ae+bg & af+bh \\ ce+dg & cf+dh \end{matrix}\right) = \left(\ \begin{matrix} i & j \\ k & l \end{matrix}\right) \end{align}

So when you divide one matrix by another, you have to solve some equations.

// Warning! This code may be inaccurate in syntax or may not work properly.
// Please refrain from using it.
function divide2x2matrix(e,f,g,h,i,j,k,l)
/**
 *We assume that the matrix is in the form [[i,j],[k,l]] and [[e,f],[g,h]].
 *The first bracket  is the upper row, second bracket lower row.
 *Matrix returned: [[a,b],[c,d]]
 */
/**
 *The first step is to solve the simultaneous equations.
 *The simultaneous equations are:
 *ae+bg=i }
 *af+bh=j }focus on these first
 *ce+dg=k }
 *cf+dh=l }then focus on these
 *aeh+bgh=hi
 *afg+bgh=gj
 *=>aeh-afg=hi-gj
 *=>a=(hi-gj)/(eh-fg)
 *=>aef+bfg=fi
 *=>aef+beh=ej
 *=>bfg-beh=fi-ej
 *=>b=(fi-ej)/(fg-eh)
 *Using the same method:
 *ce+dg=k
 *cf+dh=l
 *c=(kh-lg)/(eh-fg)
 *d=(fk-el)/(fg-eh)
 */
var discrim=(e*h-g*f)
if (discrim!=0) {
a=(h*i-g*j);
a/=discrim;
b=(e*j-f*i);
b/=discrim;
c=(k*h-l*g);
c/=discrim;
d=(e*l-f*k);
d/=discrim;
return a,b,c,d;
}
else {
alert("The answer is undefined");
return "undefined product";
}
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License