Wednesday, July 23, 2014

The Linear Regression Model y = a + bx

Sponsored Links

This is part of Mike's Regression and Model Fitting Tutorial

Linear Regression of the form \( y = a + b x \) is the typical "go to" regression method that people generally use. It is often taught in many basic statistics and non-statistical mathematics courses. There are a large number of problems where linear regression of the form \( y = a + bx \) provides a correct answer and a large number of problems where it provides an acceptable answer. In future posts, we'll look at other models that may fit other data better.

By definition, the line \( y = a + b x \) is a straight line with the following characteristics:

  • The y axis intercept (the model evaluated at \( x = 0 \), in mathematical notation \( y = a +bx |_{x=0}  \) is equal to  \(a\).
  • The x axis intercept (the model evaluated at \( y = 0 \) and solved for x, in mathematical notation \( y = a + bx|_{y=0} \) is equal to \( \frac{-a}{b} \).
  • The slope of the line is equal to \( b \). This can be shown with either the typical "rise over run" or using the first derivative (there's really not a lot of distinction here, but I recognize that some readers may not have a calculus background).
    • Let's look at the "rise over run" part first. To make the math easy, let's assume that we want to compare the change in y (call the change in y \( \sigma \) when we make some arbitrary change in x ( let's say we add \(\delta\) )$$ y = a + b x $$ $$ y + \sigma = a + b(x + \delta) $$ Now let's look at the change: $$ y + \sigma - y = a + b (x + \delta) - (a + bx  ) $$ Simplifying, we get to $$ \sigma = b \delta $$ . The "rise over run" is equal to $$ \frac{\sigma}{\delta} = b$$. To take this a step further, assume \(\delta = 1\), the change is exactly \(b\)
    • Going back to basic first semester calculus, this can be shown using the first derivative (for non-calculus readers, the derivative is a measure of how quickly the slope of a particular curve changes) $$ \frac{d}{dx} a + bx = b $$

How do I calculate \( a \) and \( b \) for the line \( y =  a + b x \)?
 

Let's get into the calculation of the \( a \) and \( b \) values for the \( y= a  + b x \) model. Firstly, we need to set up a matrix \( A \)  with the relevant transformations of our input data. We'll get to that in a minute below. First, let's answer the question "How do I find a line between 2 points in the \( (x,y) \) plane?"

For a second, let's consider two of our points in our data: \( (x_1, y_1 )\) and \( (x_2, y_2 )\).  If we used just the two points, we can calculate \( a \) and \( b \) directly. First, let's define a couple of equations:

$$ y_1 = a + b x_1 $$
$$ y_2 = a + b x_2 $$

Doing a little bit of reorganization, let's solve for b first:

$$ y_2 - y_1  = a + b x_2 - (a + b x_1) $$

\( a \) cancels out and the right side simplifies to  \( b x_2 - b x_1 = b ( x_2 - x_1 ) \). Solving for \( b \):

$$ b = \frac{y_2 - y_1}{x_2 - x_1} $$

Either equation can be used to solve for \( a \). Using the first, \( a = y_1 - b x_1 \), using the second equation, \( a = y_2 - b x_2 \). Now, let's consider a matrix solution to the same problem. We'll set up matrices to solve the equation
 $$ A z = B $$

Here, lets define \( z \) and \( B \). \( z \) contains our unknowns... namely \( a \) and \( b \). \( B \) contains our Y values, namely \( y_1 \)  and \( y_2 \)

$$ z = \begin{pmatrix} a \\ b \end {pmatrix} \quad \quad B = \begin{pmatrix} y_1 \\ y_2 \end{pmatrix} $$

Let's take a little bit of extra time to talk about \( A \). Each column in \( A \) has to be a function of the data \( x_i \). Let's go back to our original equations and rewrite them slightly...

$$ y_1 = a + b x_1 \iff a \mathbf{x_1^0} + b x_1^{\mathbf{1}} $$
$$ y_2 = a + b x_2 \iff a \mathbf{x_2^0} + b x_2^{\mathbf{1}} $$

We know generally that almost anything raised to the "zero" power is equal to 1. Anything raised to the first power is equal to itself. Let's put our rewritten equations into their equivalent matrix format:

$$ A = \begin{pmatrix} x_1^0 & x_1^1 \\ x_2^0 & x_2^1 \end{pmatrix} \iff \begin{pmatrix} 1 & x_1 \\ 1 & x_2 \end{pmatrix} $$

Our resulting matrix \( A \) contains all of the data. The first column contains the data raised to the 0 power and the second column contains the data raised to the first power. Let's write our system of equations out in matrix form:

$$ A z = B $$
$$ \begin{pmatrix} 1 & x_1 \\ 1 & x_2 \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} y_1 \\ y_2 \end{pmatrix} $$

This is a 2x2 system, so we can look up the inverse of a 2x2 matrix on my post here: http://mikemstech.blogspot.com/2014/07/inverse-of-2x2-matrix.html. We'll use the fact that

$$(A^{-1}) A z = (A^{-1}) B $$
$$ z = (A^{-1}) B $$

Calculating \( A^{-1} B \) yields

$$ \begin{pmatrix} \frac{y_1 x_2 - y_2 x_1}{ x_2 - x_1 } \\  \frac{y_2 - y_1}{x_2-x_1} \end{pmatrix} $$

Namely, \( a = \frac{y_1 x_2 - y_2 x_1}{ x_2 - x_1 } \) and \( b = \frac{y_2 - y_1}{x_2-x_1} \) for our two point example. A fair amount of algebra can be used to show the equivalence of the answers above and the answers to the matrix equations for \( a \) ( \( b \) is the same with either approach).

How to find \( a \) and \( b \) with more than two points.

We used the two point example as a conceptual introduction to how we set up the matrices, and now we want to consider the case with more than 2 points. We set up our system of equations using the least squares approach (minimizing the total sum of squared error for the model generated).

$$ A^T A z = A^T B $$

In this case,
$$  A = \begin{pmatrix} 1 & x_1 \\ \vdots & \vdots \\ 1 & x_n \end{pmatrix} \quad z = \begin{pmatrix} a \\ b \end{pmatrix} \quad B = \begin{pmatrix} y_1 \\ \vdots \\ y_n \end{pmatrix} $$








Now for the calculation of \( A^T A \) and \( A^T B \)

$$ A^T A = \begin{pmatrix} \sum \limits _{i = 1}^n 1 & \sum \limits _{i=1}^n x_i \\ \sum \limits _{i=1}^n x_i & \sum \limits _{i=1}^n x_i^2 \end{pmatrix} = \begin{pmatrix} n & \sum \limits _{i=1}^n x_i \\ \sum \limits _{i=1}^n x_i & \sum \limits _{i=1}^n x_i^2 \end{pmatrix} \quad \quad A^T B = \begin{pmatrix} \sum \limits _{i=1}^n y_i \\ \sum \limits _{i=1}^n x_i \cdot y_i \end{pmatrix} $$


This is a 2x2 system, so we can look up the inverse of a 2x2 matrix on my post here: http://mikemstech.blogspot.com/2014/07/inverse-of-2x2-matrix.html. Again, we'll use the following:

$$ (A^TA)^{-1} A^TA z = (A^TA)^{-1} B $$
$$ z = (A^TA)^{-1} B $$

Finding the inverse of \( A^T A \) yields

$$ (A^T A)^{-1} = \frac { 1 } { n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 } \begin{bmatrix} \sum \limits_{i=1}^n x_i^2 & -1 \cdot \sum \limits _{i=1}^n x_i \\ -1 \cdot \sum \limits _{i=1}^n x_i & n \end{bmatrix}$$

Calculating \( (A^T A)^{-1} B \) yields

$$ \begin{pmatrix} (A^T A)^{-1} B = \frac{\sum \limits_{i=1}^n x_i^2 \sum \limits_{i=1}^n y_i -  \sum \limits_{i=1}^n x_i \sum \limits_{i=1}^n x_i y_i}{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 }  \\ \frac{n \sum \limits_{i=1}^n x_i y_i  -  \sum \limits_{i=1}^n y_i \sum \limits_{i=1}^n x_i }{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 } \end{pmatrix} $$

So, for the regression model \( y = a + bx \)
$$ a = \frac{\sum \limits_{i=1}^n x_i^2 \sum \limits_{i=1}^n y_i -  \sum \limits_{i=1}^n x_i \sum \limits_{i=1}^n x_i y_i}{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 } \quad \quad  b = \frac{n \sum \limits_{i=1}^n x_i y_i  -  \sum \limits_{i=1}^n y_i \sum \limits_{i=1}^n x_i }{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 }   $$

Example: Calculate A Regression Line for 3 Collinear Points

Problem statement: Calculate a line in the form \( y = a + b x \) that goes through the points \( (1,5),(2,7),(3,9) \).

 

We derived the formula above, so now we need to focus on calculation.

$$ a = \frac{\sum \limits_{i=1}^n x_i^2 \sum \limits_{i=1}^n y_i -  \sum \limits_{i=1}^n x_i \sum \limits_{i=1}^n x_i y_i}{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 } \quad \quad  b = \frac{n \sum \limits_{i=1}^n x_i y_i  -  \sum \limits_{i=1}^n y_i \sum \limits_{i=1}^n x_i }{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 } $$

If calculating by hand, the easiest way is to organize the calculationsin a table.

Point \( x_i \) \( y_i \) \( x_i^2 \) \( x_i y_i \)
\((1,5)\) 1 5 1 5
\((2,7)\) 2 7 4 14
\((3,9)\) 3 9 9 27

\( \sum \limits_{i=1}^3 x_i = 1 + 2 + 3 = 6 \) \( \sum \limits_{i=1}^3 y_i = 5 + 7 + 9 = 21 \) \( \sum \limits_{i=1}^3 x_i^2 = 1 + 4 + 9 = 14 \) \( \sum \limits_{i=1}^3 x_i y_i = 5 + 14 + 27 = 46 \)
Now, for the calculation of \( a \)
$$ a = \frac{\sum \limits_{i=1}^n x_i^2 \sum \limits_{i=1}^n y_i -  \sum \limits_{i=1}^n x_i \sum \limits_{i=1}^n x_i y_i}{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 } = \frac{ 14 \cdot 21 - 6 \cdot 46 }{ 3 \cdot 14 - 6^2 } = \frac{18}{6} = 3 $$

Now, for the calculation of \( b \)

$$ b = \frac{n \sum \limits_{i=1}^n x_i y_i  -  \sum \limits_{i=1}^n y_i \sum \limits_{i=1}^n x_i }{n \sum \limits _{i=1}^n x_i^2 - \left ( \sum \limits_{i=1}^n x_i \right )^2 } = \frac{3 \cdot 46 - 21 \cdot 6}{3 \cdot 14 - 6^2 } = \frac{12}{6} = 2 $$

The ending solution for \( y= a + b x \) that fits these three points is \( y = 3 + 2 x \)

Sunday, July 20, 2014

Mike's Regression and Model Fitting Tutorial

Sponsored Links

So, I noticed on a brief look around the Internet that there are not a lot of good, multi-platform tutorials for regression and model fitting... particularly examples in the tools that most people have access to in the workplace. In this tutorial series I will present explanations and derivations of the models and procedures for fitting models of various levels of complexity in various applications and programming languages. The applications will include the following: Microsoft Excel, OpenOffice.org, Office 365, and Google Spreadsheets. The programming languages will include C#.Net, VB.Net, Java, SQL, and R. Over time I may expand to other applications and programming languages.

As a special note, the focus of this tutorial series is on presenting methods to implement linear regression in an application. In some cases, there may be a built in way to calculate a model in the application, but the focus of the posts is using an application to implement the model directly (since in some cases you may need to tweak the model for your specific data set, and in my experience the built-in features of an application don't usually support model customization).

Below are a list of models that I've developed tutorials for:
  • Linear Models
    • \( y = a \) (sometimes called the "null" model)
      • Understanding the model for \( y = a \)
      • How to calculate \( y=a \) models in Microsoft Excel
      • How to calculate \( y=a \) models in OpenOffice.org
      • How to calculate \( y=a \) models in Google Spreadsheets
      • How to calculate \( y=a \) models in Office 365
      • How to calculate \( y=a \) models in C#.Net
      • How to calculate \( y=a \) models in VB.Net
      • How to calculate \( y=a \) models in Java
      • How to calculate \( y=a \) models in SQL
      • How to calculate \( y=a \) models in R
    • \( y = a + bx \)
      • Understanding the model for \( y = a + bx \)
      • How to perform linear regression in Microsoft Excel
      • How to perform linear regression in OpenOffice.org
      • How to perform linear regression in Google Spreadsheets
      • How to perform linear regression in Office 365
      • How to perform linear regression in C#.Net
      • How to perform linear regression in VB.Net
      • How to perform linear regression in Java
      • How to perform linear regression in SQL
      • How to perform linear regression in R
    • \( y = a + b x + c x^2 \)
      • Understanding the model for \( y = a + b x + c x^2  \)
      • How to perform quadratic regression in Microsoft Excel
      • How to perform quadratic regression in OpenOffice.org
      • How to perform quadratic regression in Google Spreadsheets
      • How to perform quadratic regression in Office 365
      • How to perform quadratic regression in C#.Net
      • How to perform quadratic regression in VB.Net
      • How to perform quadratic regression in Java
      • How to perform quadratic regression in SQL
      • How to perform quadratic regression in R


The Linear Model y = a

Sponsored Links

This is part of Mike's Regression and Model Fitting Tutorial.

The simplest linear model that I am going to discuss in this series is the model \(y = a\). By the end of this post, I hope you'll walk away with the knowledge of what the model represents and how it is often used. By the end of this post, I hope you'll be able to answer the following questions:
  • What is the "null" model?
  • How is the "null" model used?
  • Why is the solution to the linear model \( y = a \) equal to the mean?
For a minute, let's consider a scenario where we have a set of interval or ratio data that we want to learn more about. In this scenario we are attempting to describe the relationship in the data that we have collected. We may or may not be interested in predicting other values. We are essentially asking the question "Why are things the way that they are?" and may be asking the question "How might things be if we collect more data?" As we work through our model, we will be attempting to describe the relationship between dependent and independent variables.

If your new to statistics, the words in the previous paragraph might not have a lot of meaning. Let's look at them in detail...

Interval/Ratio Data - The words "Interval" and "Ratio" refer to the measurement scale of the data in question. Most of the models in the tutorial will require an interval/ratio dependent variable. Some clues that help us end up at a description of this measurement level include:

  • "Zero on the scale" - the measurement scale typically has a 0 at some point. For ratio data, there is an absolute "zero" to the scale (i.e. it would be impossible for a collected data point to fall below "zero").
  • Sub-interval equality - The distance between subsequent points on the scale are equal. For example, we would generally consider the difference between 1 degree F and 2 degrees F to be equivalent to the difference between 3 degrees and 4 degrees F.
  • "Lots" of possible values on the scale. For example, in a bank account, we could have virtually any amount above or below zero, probably down to a resolution of $0.01 (for accounts denominated in the U.S. Dollar)

Some examples of interval/ratio data include:

  • Temperature: degrees of temperature are typically considered interval or ratio. Scales such as Celsius and Fahrenheit are typically considered interval (because they have a "zero" on the scale). Scales such as Kelvin and Rankin have an "absolute" zero on the scale, meaning there can't reasonably be values less than 0 on these scales.
  • Measurements of mass/weight/volume: Measurements of mass, weight, and volume typically have interval/ratio properties.
  • Measurements of economic value: Typical measurements of economic value are quoted in a currency or an amount of a good.
Some examples of things that aren't interval/ratio:

  • Demographic variables such as religion, sexual preference, and gender: These can't be given non-arbitrary numeric values. Additionally, there is no meaning between the numeric "differences" applied to these categories. For example, say Republican is coded as a 1, Democrat is coded as a 2, and Independent is coded as a 3. There is no meaningful difference by describing the difference between 1 and 2, much less comparing that to the difference between 3 and 4. these are sometimes referred to as "nominal" or "categorical" data.
  • Ratings and rankings: These typically arise from surveys/questionnaires. These might take the form of the common "agree/disagree" and "satisfied/dissatisfied" scales. In this case, we can say that certain values are different (and potentially less than or greater than) other values, but we don't have homogeneity in the scale. For example, someone responding "agree" to a question might not be the same as someone else responding "agree," but after repeated measurements of the same person we could probably conclude that "strongly agree" is larger in magnitude than "somewhat agree" or just "agree." These are sometimes referred to as "ordinal" data.
Relationships in Data/Prediction:

We don't generally set off on a course of research without some sort of purpose. This purpose is typically to understand or optimize something. We might be asking questions of the form "Is there a relationship between X an Y?" or "Are A and B correlated?" or "Can I use C or D (or some combination) to predict E?" The purpose of each of these questions is to help us understand relationships in the real world based on data collected from our observations.

We should be careful to remember that correlation does not imply causation. When we develop predictive models, we will be careful not to say things like "A is causing B" because we probably don't have sufficient basis to conclude such a thing... To be able to describe causation, we would likely need to step away from regression/classification and enter the realms of experimental design.

Dependent/Independent Variables

For our purposes, the dependent variable is the variable we are interested in describing. The independent variables are the variables that we could potentially use to describe the dependent variable.
Examples:

  • If we are predicting asset prices (ex. stocks, bonds, commodities), our dependent variable might be "price in the future", and we might be using independent variables such as "price in the past," economic variables, financial data, etc.
  • If we are predicting a students "GPA in a course" (dependent variable), we might use the following as independent variables: "hours spent per week," "percentage of lectures attended," scores on standardized tests such as the SAT, ACT, GED, GRE, MCAT, etc.
So now, let's dig into the "null model."

At a basic level, the null model is a model that minimizes the error when describing the dependent variable with a single number. Effectively, the overall error is minimized as measured from the horizontal (or vertical) line to each of the points. Below is a graphical depiction of the null model (generated in R):


The null model represents the best guess that we could use to describe the data if we didn't have or didn't use any of the possible dependent variables to describe the independent variable (y in the chart above).

Intuitively, we might conclude that this is the mean (or average) of the dependent variable. We can prove this below.

Without sinking too much into the proofs involved in linear algebra, let's first state the (provable) assumption that we can develop a "minimum error" solution to our system of equations by solving the linear system:

$$ A^T A x = A^T B $$

Here, \( A \) is a matrix that contains a transformation of the independent variables and \( B \) is a matrix containing all of the dependent variable values.

$$ A = \begin{pmatrix} 1 \\ \vdots \\ 1 \end{pmatrix} \quad B = \begin{pmatrix}y_1 \\ \vdots \\ y_n \end {pmatrix} $$

In this case, we don't have (or aren't using) any of the independent variable data to describe the dependent variable. Now let's calculate two of the items needed in the first equation:

$$ A^T A = \sum_{i=1}^n 1 = n \quad \quad A^T B = \sum_{i =1}^n 1 \cdot y_i $$

So... \( A^T A \) is simply the sample size and \( A^T B \) is the sum of the dependent variable observations. If we take the inverse of \( A^T A \) and multiply it both sides, we end up with our answer for \( a \). In this case, \( A^T A \) is a 1x1 matrix. I show how to find the inverse here: http://mikemstech.blogspot.com/2014/07/inverse-of-1x1-matrix.html

$$ (A^T A) ^{-1} (A^T A) x = (A^T A)^{-1} (A^T B) $$
$$ x = (A^T A)^{-1} (A^T B) $$

By the matrix inversion formula for the 1x1 matrix (linked above), we see that

$$  (A^T A)^{-1} (A^T B) = \frac{ \sum_{i=1}^n y_i}{n} = \bar{x} $$
Here we see that the answer to the null model is just the average of the dependent variable values.

Let's do a small example. Say that we have the following data:
$$ B = \begin{pmatrix} y_1 = 0 \\ y_2  = 5 \\ y_3 = 10 \end{pmatrix} $$

Let's determine the null model for this data.

$$ A = \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} $$

$$ A^T A = \sum_{i=1}^{3} 1 = 3  \quad \quad  A^T B = (1 \cdot 0 + 1 \cdot 5 + 1 \cdot 10 = 15) $$

$$ (A^T A)^{-1} = \frac { 1} {3}$$

$$ (A^T A)^{-1} B = \frac { 15} {3} = 5 $$

Here the null model (average) for the data is y = 5.

The null model, besides being an interesting conceptual introduction, is also important for other practical reasons. When we evaluate other models, we will typically determine their goodness of fit based on a comparison with the null model for the same data. We are conceptually asking the question "Does our 'complicated' model describe the dependent variable better than the average?" There are tools that we can use to answer this question that will be discussed with the other models. Here it is also useful to initially define the total sum of squares.

The total sum of squares (TSS) for the model is the sum of the squared deviations from the average.

$$ TSS = \sum_{i=1}^n (y_i - \bar{y})^2 $$

This is also equal to

$$ TSS = \sum_{i=1}^n (\bar{y} - y_i)^2 $$
As an example, let's consider our data from above and calculate the TSS.

$$ TSS = \sum_{i=1}^n (y_i - \bar{y})^2  = (0 - 5)^2 + (5-5)^2 + (10-5)^2 = 50 $$

The ending value of 50 doesn't tell us a lot until we compare it with another model (normally to see if the other model "explains" more of the variability in the dependent variable).

Inverse of a 1x1 Matrix

Sponsored Links

In my previous post (http://mikemstech.blogspot.com/2014/07/c-matrix-inversion-with-latex-output.html) I demonstrated an application that can generate the steps to show the inversion of a matrix by Gauss Jordan elimination.

In a few posts, I plan to answer the following questions:
What is the inverse of a 1x1 Matrix?
What is the inverse of a 2x2 Matrix?
What is the inverse of a 3x3 Matrix?
What is the inverse of a 4x4 Matrix?

The inverse of a 1x1 matrix is defined as follows. For a 1x1 matrix:

$$ A = \begin{pmatrix}a_{1,1}\end{pmatrix} $$

$$ A^{-1} = \begin{pmatrix}\frac{1}{a_{1,1}} \end {pmatrix} $$

Obviously, if $$a_{1,1} = 0$$ the matrix has no inverse.

The latex code generated for a 1x1 inverse is the following:

 
\documentclass{article}

% This is the output from LatexMatrixInverse 1.0 for a matrix with rank 1 
% For more information on this application, see
% http://mikemstech.blogspot.com

\usepackage{geometry}

% Note: you should probably use pdflatex to compiile this file. 
% Other processors are known to have some issues with using
% 'geometry' to set paper size

% Adjust the page size here if output is wrapping in a bad way.
% Default is 8.5 x 11 in (Letter)
\geometry{papersize={8.5in,11in}}

%Import AMS Latex packages
\usepackage{amsmath, amssymb}
\setcounter{MaxMatrixCols}{3}


%Variable definition

\begin{document}
% Definition of initial A
% A row 1
\newcommand{\ARbCb}{a_{1,1}}

% Definition of initial B
\newcommand{\BRb}{b_{1}}



LatexMatrixInverse 1.0 Output for rank 1, ShowIntermediateSteps is True.

For more information on this application, please see http://mikemstech.blogspot.com

Given the following initial matrices:
\begin{equation*}
A = \begin{pmatrix}\ARbCb
\end{pmatrix}B = \begin{pmatrix}\BRb\end{pmatrix}\end{equation*}
 We want to find $A^{-1}$ and $A^{-1} B$...
\begin{equation*}
\left ( \begin{array}{c|c|c}\ARbCb
&1
&\BRb\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARbCb} R_{1}}
\left ( \begin{array}{c|c|c}1
&\frac{1}{\ARbCb}
&\frac{\BRb}{\ARbCb}\end{array} \right )
\end{equation*}
\begin{equation*}
A^{-1} = \begin{pmatrix}\frac{1}{\ARbCb}
\end{pmatrix}A^{-1}B = \begin{pmatrix}\frac{\BRb}{\ARbCb}\end{pmatrix}\end{equation*}
\end{document}


Here is a screenshot of the generated file that shows all of the steps for a 1x1 matrix inverse:





Inverse of a 2x2 Matrix

Sponsored Links

In my previous post (http://mikemstech.blogspot.com/2014/07/c-matrix-inversion-with-latex-output.html) I demonstrated an application that can generate the steps to show the inversion of a matrix by Gauss Jordan elimination.

In a few posts, I plan to answer the following questions:
What is the inverse of a 1x1 Matrix?
What is the inverse of a 2x2 Matrix?
What is the inverse of a 3x3 Matrix?
What is the inverse of a 4x4 Matrix?

The inverse of a 2x2 matrix is defined as follows. For a 2x2 matrix:

$$ A = \begin{pmatrix}a & b \\ c & d\end{pmatrix} $$

Unsimplified, the inverse is equal to:

$$ A^{-1} = \begin{pmatrix}\frac{1}{a} - \left (\frac{b}{a} \right )  \left ( \frac{0 - \left (c \right ) \left ( \frac{1}{a}\right )}{d - \left (c \right ) \left ( \frac{b}{a}\right )}\right )
&
0 - \left (\frac{b}{a} \right )  \left ( \frac{1}{d - \left (c \right ) \left ( \frac{b}{a}\right )}\right )
\\\frac{0 - \left (c \right ) \left ( \frac{1}{a}\right )}{d - \left (c \right ) \left ( \frac{b}{a}\right )}
&
\frac{1}{d - \left (c \right ) \left ( \frac{b}{a}\right )}
\end{pmatrix} $$

After simplifying, this is the inverse of a 2x2 matrix.

$$ A^{-1} = \frac{1}{ad-bc} \begin{pmatrix}  d & -b \\ -c & a  \end {pmatrix} $$

The latex code generated for a 2x2 inverse is the following (note that I changed the default variables to a, b, c, and d to match how most people learn the 2x2 matrix):

\documentclass{article}

% This is the output from LatexMatrixInverse 1.0 for a matrix with rank 2 
% For more information on this application, see
% http://mikemstech.blogspot.com

\usepackage{geometry}

% Note: you should probably use pdflatex to compiile this file. 
% Other processors are known to have some issues with using
% 'geometry' to set paper size

% Adjust the page size here if output is wrapping in a bad way.
% Default is 8.5 x 11 in (Letter)
\geometry{papersize={16in,11in}}

%Import AMS Latex packages
\usepackage{amsmath, amssymb}
\setcounter{MaxMatrixCols}{5}


%Variable definition

\begin{document}
% Definition of initial A
% A row 1
\newcommand{\ARbCb}{a}
\newcommand{\ARbCc}{b}

% A row 2
\newcommand{\ARcCb}{c}
\newcommand{\ARcCc}{d}

% Definition of initial B
\newcommand{\BRb}{e}
\newcommand{\BRc}{f}



LatexMatrixInverse 1.0 Output for rank 2, ShowIntermediateSteps is True.

For more information on this application, please see http://mikemstech.blogspot.com

Given the following initial matrices:
\begin{equation*}
A = \begin{pmatrix}\ARbCb
&\ARbCc
\\\ARcCb
&\ARcCc
\end{pmatrix}B = \begin{pmatrix}\BRb\\ \BRc\end{pmatrix}\end{equation*}
 We want to find $A^{-1}$ and $A^{-1} B$...
\begin{equation*}
\left ( \begin{array}{cc|cc|c}\ARbCb
&\ARbCc
&1
&0
&\BRb\\
\ARcCb
&\ARcCc
&0
&1
&\BRc\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARbCb} R_{1}}
\left ( \begin{array}{cc|cc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&\frac{\BRb}{\ARbCb}\\
\ARcCb
&\ARcCc
&0
&1
&\BRc\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{2} - \left ( \ARcCb\right ) R_{1}}
\left ( \begin{array}{cc|cc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&\frac{\BRb}{\ARbCb}\\
0
&\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )
&0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )
&1
&\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} R_{2}}
\left ( \begin{array}{cc|cc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&\frac{\BRb}{\ARbCb}\\
0
&1
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{1} - \left ( \frac{\ARbCc}{\ARbCb}\right ) R_{2}}
\left ( \begin{array}{cc|cc|c}1
&0
&\frac{1}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARcCb \right ) 
\left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&0 - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&\frac{\BRb}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{\BRc - \left (\ARcCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )\\
0
&1
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\end{array} \right )
\end{equation*}
\begin{equation*}
A^{-1} = \begin{pmatrix}\frac{1}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARcCb \right ) 
\left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&
0 - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
\\\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&
\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\end{pmatrix}A^{-1}B = \begin{pmatrix}\frac{\BRb}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{\BRc - \left (\ARcCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )\\ \frac{\BRc - \left (\ARcCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\end{pmatrix}\end{equation*}
\end{document}


Here is a screenshot of the work for calculating a 2x2 inverse (based on the compiled code above):

Inverse of a 3x3 Matrix

Sponsored Links

In my previous post
(http://mikemstech.blogspot.com/2014/07/c-matrix-inversion-with-latex-output.html)
I demonstrated an application that can generate the steps to show the
inversion of a matrix by Gauss Jordan elimination.

In a few posts, I plan to answer the following questions:
What is the inverse of a 1x1 Matrix?
What is the inverse of a 2x2 Matrix?
What is the inverse of a 3x3 Matrix?
What is the inverse of a 4x4 Matrix?


The inverse of a 3x3 matrix is defined as follows. For a 3x3 matrix:

$$ A = \begin{pmatrix}a & b & c \\ d & e & f \\ g & h & i\end{pmatrix} $$

$$ A^{-1} = \begin{pmatrix}
\frac{f h-e i}{c e g-b f g-c d h+a f h+b d i-a e i}
& \frac{c h - b i}{- c e g + b f g + c d h - a f h - b d i + a e i}
& \frac{c e - b f}{c e g - b f g - c d h + a f g + b d i - a e i } \\
\frac{f g - d i}{- c e g + b f g + c d h - a f h - b d i + a e i}
& \frac{c g - a i}{c e g - b f g - c d h+ a f h + b d i - a e i}
& \frac{c d - a f}{- c e g + b f g + c d h - a f h - b d i + a e i} \\
\frac{e g - d h}{c e g - b f g - c d h + a f h + b d i - a e i}
& \frac{b g - a h}{- c e g + b f g + c d h - a f h - b d i + a e i}
& \frac{b d - a e}{c e g - b f g - c d h + a f h + b d i - a e i}
\end {pmatrix} $$

The latex code generated for a 3x3 inverse is the following:

\documentclass{article}

% This is the output from LatexMatrixInverse 1.0 for a matrix with rank 3 
% For more information on this application, see
% http://mikemstech.blogspot.com

\usepackage{geometry}

% Note: you should probably use pdflatex to compiile this file. 
% Other processors are known to have some issues with using
% 'geometry' to set paper size

% Adjust the page size here if output is wrapping in a bad way.
% Default is 8.5 x 11 in (Letter)
\geometry{papersize={40in,14in}}

%Import AMS Latex packages
\usepackage{amsmath, amssymb}
\setcounter{MaxMatrixCols}{7}


%Variable definition

\begin{document}
% Definition of initial A
% A row 1
\newcommand{\ARbCb}{a}
\newcommand{\ARbCc}{b}
\newcommand{\ARbCd}{c}

% A row 2
\newcommand{\ARcCb}{d}
\newcommand{\ARcCc}{e}
\newcommand{\ARcCd}{f}

% A row 3
\newcommand{\ARdCb}{g}
\newcommand{\ARdCc}{h}
\newcommand{\ARdCd}{i}

% Definition of initial B
\newcommand{\BRb}{j}
\newcommand{\BRc}{k}
\newcommand{\BRd}{l}



LatexMatrixInverse 1.0 Output for rank 3, ShowIntermediateSteps is True.

For more information on this application, please see http://mikemstech.blogspot.com

Given the following initial matrices:
\begin{equation*}
A = \begin{pmatrix}\ARbCb
&\ARbCc
&\ARbCd
\\\ARcCb
&\ARcCc
&\ARcCd
\\\ARdCb
&\ARdCc
&\ARdCd
\end{pmatrix}B = \begin{pmatrix}\BRb\\ \BRc\\ \BRd\end{pmatrix}\end{equation*}
 We want to find $A^{-1}$ and $A^{-1} B$...
\begin{equation*}
\left ( \begin{array}{ccc|ccc|c}\ARbCb
&\ARbCc
&\ARbCd
&1
&0
&0
&\BRb\\
\ARcCb
&\ARcCc
&\ARcCd
&0
&1
&0
&\BRc\\
\ARdCb
&\ARdCc
&\ARdCd
&0
&0
&1
&\BRd\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARbCb} R_{1}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{\ARbCd}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&0
&\frac{\BRb}{\ARbCb}\\
\ARcCb
&\ARcCc
&\ARcCd
&0
&1
&0
&\BRc\\
\ARdCb
&\ARdCc
&\ARdCd
&0
&0
&1
&\BRd\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{2} - \left ( \ARcCb\right ) R_{1}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{\ARbCd}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&0
&\frac{\BRb}{\ARbCb}\\
0
&\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )
&\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )
&0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )
&1
&0
&\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )\\
\ARdCb
&\ARdCc
&\ARdCd
&0
&0
&1
&\BRd\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{3} - \left ( \ARdCb\right ) R_{1}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{\ARbCd}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&0
&\frac{\BRb}{\ARbCb}\\
0
&\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )
&\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )
&0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )
&1
&0
&\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )\\
0
&\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )
&\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )
&0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right )
&0
&1
&\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} R_{2}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{\ARbCd}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&0
&\frac{\BRb}{\ARbCb}\\
0
&1
&\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&0
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\\
0
&\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )
&\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )
&0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right )
&0
&1
&\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{3} - \left ( \ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )\right ) R_{2}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{\ARbCd}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&0
&\frac{\BRb}{\ARbCb}\\
0
&1
&\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&0
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\\
0
&0
&\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb 
\right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left 
( \frac{\ARbCc}{\ARbCb}\right )}\right )
&0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) 
\left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&1
&\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\right )\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc 
- \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb 
\right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )} R_{3}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{\ARbCd}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&0
&\frac{\BRb}{\ARbCb}\\
0
&1
&\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&0
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}\\
0
&0
&1
&\frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc 
- \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc -
 \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}
{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd 
- \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}
{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc 
- \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) 
\left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{2} - \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right ) R_{3}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{\ARbCd}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&0
&\frac{\BRb}{\ARbCb}\\
0
&1
&0
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} 
- \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} 
\right ) \linebreak \left ( \frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - 
\left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd 
- \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}\right )
&0 - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )} \right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc 
- \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} 
- \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )} \right ) \linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - 
\left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - 
\left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\\
0
&0
&1
&\frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) 
\left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd 
- \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{1} - \left ( \frac{\ARbCd}{\ARbCb}\right ) R_{3}}
\left ( \begin{array}{ccc|ccc|c}1
&\frac{\ARbCc}{\ARbCb}
&0
&\frac{1}{\ARbCb} - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - 
\left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&0 - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd 
- \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&0 - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&\frac{\BRb}{\ARbCb} - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) 
\left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd 
- \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\\
0
&1
&0
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - 
\left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )} \right ) \linebreak \left ( \frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right )
 \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - 
\left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - 
\left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&0 - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )
 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) 
\left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - 
\left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - 
\left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\\
0
&0
&1
&\frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - 
\left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc 
- \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc 
- \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - 
\left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{1} - \left ( \frac{\ARbCc}{\ARbCb}\right ) R_{2}}
\left ( \begin{array}{ccc|ccc|c}1
&0
&0
&\frac{1}{\ARbCb} - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( 
\frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) 
\left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 
- \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - 
\left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\right )
&0 - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb 
\right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) 
\left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd 
- \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\right )
&0 - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb} 
\right ) \linebreak \left ( 0 - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\right )
&\frac{\BRb}{\ARbCb} - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) 
\left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb} 
\right ) \linebreak \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} 
- \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) 
\linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\right )}\right )\right )\\
0
&1
&0
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd 
- \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( 
\frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - 
\left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - 
\left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&0 - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} 
\right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) 
\linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\\
0
&0
&1
&\frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - 
\left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&\frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}
&\frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) 
\left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd 
- \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\end{array} 
\right )
\end{equation*}
\begin{equation*}
A^{-1} = \begin{pmatrix}\frac{1}{\ARbCb} - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc
 - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc -
 \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc -
 \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARcCb \right )
 \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 - \left (\ARdCb \right ) 
\left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{0 - \left (\ARcCb \right )
 \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( 
\frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) 
\left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\right )
&
0 - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) -
 \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( 
\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - 
\left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) 
\left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\right )}\right )\right )
&
0 - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc 
- \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}
{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( 0 - 
\left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} 
\right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\right )
\\\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) 
\linebreak \left ( \frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd 
- \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd 
- \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )
&
\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{0 - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - 
\left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) 
\left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\right )}\right )
&
0 - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} 
\right ) \linebreak \left ( \frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right ) \right
 ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\right )}\right )
\\\frac{0 - \left (\ARdCb \right ) \left ( \frac{1}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) 
\left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd 
- \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( 
\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&
\frac{0 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb 
\right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}
&
\frac{1}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) 
\right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}
\right )}\right )}
\end{pmatrix}A^{-1}B = \begin{pmatrix}\frac{\BRb}{\ARbCb} - \left (\frac{\ARbCd}{\ARbCb} \right ) \linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb 
\right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) 
\left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb 
\right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right ) - \left (\frac{\ARbCc}{\ARbCb}
 \right ) \linebreak \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( 
\frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) 
\left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) - \left (\ARdCc
 - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc
 - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right ) - \left (\ARdCc
 - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc
 - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\right )\\ \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{
\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} - \left (\frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )}{\ARcCc
 - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} \right ) \linebreak \left ( \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}\right ) 
- \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}\right )
 - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\right )\\ \frac{\BRd - \left (\ARdCb \right ) \left ( \frac{\BRb}{\ARbCb}
\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{
\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}{\ARdCd - \left (\ARdCb \right ) \left ( \frac{\ARbCd}{\ARbCb}
\right ) - \left (\ARdCc - \left (\ARdCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right ) \right ) \left ( \frac{\ARcCd - \left (\ARcCb \right ) \left ( \frac{\ARbCd}{
\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )}\end{pmatrix}\end{equation*}
\end{document}




Here is a link to the pdf showing all of the work for the inverse of a
3x3 matrix:

https://drive.google.com/file/d/0B0MeMQmnEH6ackxsa1VSMmlIVDA/edit?usp=sharing

Inverse of a 4x4 Matrix

Sponsored Links

In my previous post
(http://mikemstech.blogspot.com/2014/07/c-matrix-inversion-with-latex-output.html)
I demonstrated an application that can generate the steps to show the
inversion of a matrix by Gauss Jordan elimination.

In a few posts, I plan to answer the following questions:
What is the inverse of a 1x1 Matrix?
What is the inverse of a 2x2 Matrix?
What is the inverse of a 3x3 Matrix?
What is the inverse of a 4x4 Matrix?


The inverse of a 4x4 matrix is defined as follows. For a 4x4 matrix:

$$ \begin{pmatrix}a

&b

&c

&d

\\e

&f

&g

&h

\\i

&j

&k

&l

\\m

&n

&o

&p

\end{pmatrix}

$$

The inverse of the matrix simplifies to:

Row 1, Column 1:

$$\frac{f k p-f l o-g j p+g l n+h j o-h k n}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)}$$

Row 1, Column 2:

$$ \frac{-b k p+b l o+c j p-c l n-d j o+d k n}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 1, Column 3

$$\frac{b g p-b h o-c f p+c h n+d f o-d g n}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)}$$

Row 1, Column 4

$$ \frac{d g j - c h j - d f k + b h k + c f l - b g l}{b h k m - b g l m -
a h k n + a g l n - b h i o + a h j o + b e l o - a f l o +
d (g j m - f k m - g i n + e k n + f i o - e j o) + (b g i -
a g j - b e k + a f k) p +
c (-h j m + f l m + h i n - e l n - f i p + e j p)} $$

Row 2, Column 1

$$ \frac{-e k p+e l o+g i p-g l m-h i o+h k m}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 2, Column 2

$$ \frac{-d k m + c l m + d i o - a l o - c i p + a k p}{b h k m - b g l m -
a h k n + a g l n - b h i o + a h j o + b e l o - a f l o +
d (g j m - f k m - g i n + e k n + f i o - e j o) + (b g i -
a g j - b e k + a f k) p +
c (-h j m + f l m + h i n - e l n - f i p + e j p)} $$

Row 2, Column 3

$$ \frac{-a g p+a h o+c e p-c h m-d e o+d g m}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 2, Column 4

$$ \frac{a g l-a h k-c e l+c h i+d e k-d g i}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 3, Column 1

$$ \frac{e j p-e l n-f i p+f l m+h i n-h j m}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 3, Column 2

$$ \frac{-a j p+a l n+b i p-b l m-d i n+d j m}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 3, Column 3

$$ \frac{a f p-a h n-b e p+b h m+d e n-d f m}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 3, Column 4

$$ \frac{-a f l+a h j+b e l-b h i-d e j+d f i}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 4, Column 1

$$ \frac{-e j o+e k n+f i o-f k m-g i n+g j m}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 4, Column 2

$$ \frac{a j o-a k n-b i o+b k m+c i n-c j m}{p (a f k-a g j-b e k+b g
i)-a f l o+a g l n+a h j o-a h k n+b e l o-b g l m-b h i o+b h k m+c (e
j p-e l n-f i p+f l m+h i n-h j m)+d (-e j o+e k n+f i o-f k m-g i n+g j
m)} $$

Row 4, Column 3

$$ \frac{c f m - b g m - c e n + a g n + b e o - a f o}{b h k m - b g l m -
a h k n + a g l n - b h i o + a h j o + b e l o - a f l o +
d (g j m - f k m - g i n + e k n + f i o - e j o) + (b g i -
a g j - b e k + a f k) p +
c (-h j m + f l m + h i n - e l n - f i p + e j p)} $$

Row 4, Column 4

$$ \frac{-c f i + b g i + c e j - a g j - b e k + a f k}{b h k m - b g l m -
a h k n + a g l n - b h i o + a h j o + b e l o - a f l o +
d (g j m - f k m - g i n + e k n + f i o - e j o) + (b g i -
a g j - b e k + a f k) p +
c (-h j m + f l m + h i n - e l n - f i p + e j p)} $$

Saturday, July 19, 2014

C# Matrix Inversion With Latex Output

Sponsored Links

Matrix inversion is important in the domains of solving a large number of problems. Many types of problems can be expressed and then solved using matrices. In my areas of work, I most frequently encounter matrix inversion problems when working with regression problems and math problems involving affine transformations (ex. those used in cryptography applications).

Anyway, from my first college level linear algebra class, I typed up most of my math homework using Latex, and I worked out a reasonable way to show Matrix inversion step by step using row multiplications and row additions. Even though it's been a number of years since I've taken a course in linear algebra, I've wanted to build an application that outlines all of the single row multiplication and multiple row additions that are required to find the inverse for a matrix of arbitrary rank (rank is the number of diagonal elements in a square matrix).

Researchers might use this application to help them find a solution to a specific problem. Students might use the application to check their homework or to learn more about Gauss Jordan elimination.
Using this application, in a few posts I plan to answer the following questions:
What is the inverse of a 1x1 Matrix?
What is the inverse of a 2x2 Matrix?
What is the inverse of a 3x3 Matrix?
What is the inverse of a 4x4 Matrix?
Depending on the input matrix, initial row substitutions might be necessary to ensure that all diagonal elements are non-zero during the elimination process, since the application has no knowledge of the input matrix (this is directly entered into the generated latex code). Additionally, some steps may need to be removed from the output as they might be unnecessary (ex. initial zero elements off of the diagonal of the input matrix).

This application can, with sufficient memory, disk space, and compiled as 64 bit, invert large matrices, but Latex has an inherent limitation of paper sizes around 200 in wide. Testing would suggest that any matrix over rank 4 will probably overrun this limitation. Additionally, the disk size for all of the intermediate steps becomes really large (my machine tops out computing an 8x8, with an output file size > 10 GB). Latex also has some difficulty compiling these large files (numerous changes to texmf.cnf). These settings are about the highest that I can apply to my system:

main_memory    = 10000000
extra_mem_top  = 10000000
max_strings    = 2000000
hash_extra     = 10000000
pool_size      = 25000000

If you need to compile the .tex files linked to my blog or generated from my tex generating applications, you should probably use Tex Live: http://tug.org/texlive/

Here is an example of the tex output of the application for a 2x2 matrix (note that you can change the variables that appear in the final output):

\documentclass{article}

% This is the output from LatexMatrixInverse 1.0 for a matrix with rank 2 
% For more information on this application, see
% http://mikemstech.blogspot.com

\usepackage{geometry}

% Note: you should probably use pdflatex to compiile this file. 
% Other processors are known to have some issues with using
% 'geometry' to set paper size

% Adjust the page size here if output is wrapping in a bad way.
% Default is 8.5 x 11 in (Letter)
\geometry{papersize={16in,11in}}

%Import AMS Latex packages
\usepackage{amsmath, amssymb}
\setcounter{MaxMatrixCols}{5}


%Variable definition

\begin{document}
% Definition of initial A
% A row 1
\newcommand{\ARbCb}{a_{1,1}}
\newcommand{\ARbCc}{a_{1,2}}

% A row 2
\newcommand{\ARcCb}{a_{2,1}}
\newcommand{\ARcCc}{a_{2,2}}

% Definition of initial B
\newcommand{\BRb}{b_{1}}
\newcommand{\BRc}{b_{2}}



LatexMatrixInverse 1.0 Output for rank 2, ShowIntermediateSteps is True.

For more information on this application, please see http://mikemstech.blogspot.com

Given the following initial matrices:
\begin{equation*}
A = \begin{pmatrix}\ARbCb
&\ARbCc
\\\ARcCb
&\ARcCc
\end{pmatrix}B = \begin{pmatrix}\BRb\\ \BRc\end{pmatrix}\end{equation*}
 We want to find $A^{-1}$ and $A^{-1} B$...
\begin{equation*}
\left ( \begin{array}{cc|cc|c}\ARbCb
&\ARbCc
&1
&0
&\BRb\\
\ARcCb
&\ARcCc
&0
&1
&\BRc\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARbCb} R_{1}}
\left ( \begin{array}{cc|cc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&\frac{\BRb}{\ARbCb}\\
\ARcCb
&\ARcCc
&0
&1
&\BRc\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{2} - \left ( \ARcCb\right ) R_{1}}
\left ( \begin{array}{cc|cc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&\frac{\BRb}{\ARbCb}\\
0
&\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )
&0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )
&1
&\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )} R_{2}}
\left ( \begin{array}{cc|cc|c}1
&\frac{\ARbCc}{\ARbCb}
&\frac{1}{\ARbCb}
&0
&\frac{\BRb}{\ARbCb}\\
0
&1
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\end{array} \right )
\end{equation*}
\begin{equation*}
\xrightarrow{R_{1} - \left ( \frac{\ARbCc}{\ARbCb}\right ) R_{2}}
\left ( \begin{array}{cc|cc|c}1
&0
&\frac{1}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARcCb \right ) 
\left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&0 - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&\frac{\BRb}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc 
- \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )\\
0
&1
&\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&\frac{\BRc - \left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\end{array} \right )
\end{equation*}
\begin{equation*}
A^{-1} = \begin{pmatrix}\frac{1}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc 
- \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
&
0 - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )
\\\frac{0 - \left (\ARcCb \right ) \left ( \frac{1}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
&
\frac{1}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}
\end{pmatrix}A^{-1}B = \begin{pmatrix}\frac{\BRb}{\ARbCb} - \left (\frac{\ARbCc}{\ARbCb} \right ) \linebreak \left ( \frac{\BRc - \left (\ARcCb \right ) 
\left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\right )\\ \frac{\BRc - 
\left (\ARcCb \right ) \left ( \frac{\BRb}{\ARbCb}\right )}{\ARcCc - \left (\ARcCb \right ) \left ( \frac{\ARbCc}{\ARbCb}\right )}\end{pmatrix}
\end{equation*}
\end{document}

Below is a screenshot of the PDF output from the 2x2 file:



Obviously, the end user would need to perform any simplification at the end.

Below is the application in C#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LatexMatrixInverse
{
    public class Program
    {
        public int rank = 0;

        public string[,] A,
                          A_inverse;
        public string[] B;

        public string ArrayFormat = null;

        public bool ShowIntermediateSteps = true;

        public bool FinalOutputAsMatrix = true;

        static void Main(string[] args)
        {
            Program p = new Program();

            if (args.Length == 1)
            {
                p.rank = 0;

                //arg 0 is rank
                try { p.rank = int.Parse(args[0]); }
                catch (Exception) { PrintUsage(); return; }

                if (p.rank < 1)
                {
                    PrintUsage(); return;
                }

                p.ProcessA();
            }
            else
            {
                PrintUsage();
            }

        }

        public void ProcessA()
        {

            // Print out the preamble stuff
            Console.WriteLine(
"\\documentclass{article}" + @"

% This is the output from LatexMatrixInverse 1.0 for a matrix with rank " + rank + @"
% For more information on this application, see

\usepackage{geometry}

% Note: you should probably use pdflatex to compiile this file.
% Other processors are known to have some issues with using
% 'geometry' to set paper size

% Adjust the page size here if output is wrapping in a bad way.
% Default is 8.5 x 11 in (Letter)
\geometry{papersize={8.5in,11in}}

%Import AMS Latex packages
\usepackage{amsmath, amssymb}
\setcounter{MaxMatrixCols}{" + (2 * rank + 1) + @"}


%Variable definition
");

            // Define variables
            //
            // We have A = {a_i_j}, B = {b_j}
            // Want to find solution to Ax=B by Gauss-Jordan elimination
            //
            // Variables format: X= row, Y = column
            // \newcommand{ArXcY}{a_{X,Y}}
            // \newcommand{BrX}{b_X}
            // Have to do odd things with the numbers in the command names
            // because latex doesn't support numbers in \newcommand

            A = new string[rank, rank];
            A_inverse = new string[rank, rank];
            B = new string[rank];

            StringBuilder A_definition = new StringBuilder("% Definition of initial A");
            StringBuilder B_definition = new StringBuilder("% Definition of initial B\r\n");

            for (int i = 0; i < rank; i++)
            {
                A_definition.AppendLine(@"
% A row " + (i + 1));


                for (int j = 0; j < rank; j++)
                {
                    A[i, j] = "\\AR" + NtoC(i + 1) + "C" + NtoC(j + 1);

                    A_definition.AppendLine("\\newcommand{\\AR" + NtoC(i + 1) + "C" + NtoC(j + 1)
                        + "}{a_{" + (i + 1) + "," + (j + 1) + "}}");

                    A_inverse[i, j] = (i == j ? "1" : "0");


                }

                B[i] = "\\BR" + NtoC(i + 1);

                B_definition.AppendLine("\\newcommand{\\BR" + NtoC(i + 1) + "}{b_{" + (i + 1) + "}}");
            }

            Console.WriteLine("\\begin{document}");

            Console.WriteLine(A_definition);
            Console.WriteLine(B_definition);
            Console.WriteLine();
            Console.WriteLine();


            Console.WriteLine("LatexMatrixInverse 1.0 Output for rank " + rank + ", ShowIntermediateSteps is "
                + ShowIntermediateSteps.ToString() + ".");
            Console.WriteLine();
            Console.WriteLine("For more information on this application, please see http://mikemstech.blogspot.com");
            Console.WriteLine();


            Console.WriteLine("Given the following initial matrices:");


            Console.WriteLine("\\begin{equation*}");
            // Print out A
            Console.Write("A = \\begin{pmatrix}");
            for (int i = 0; i < rank; i++)
            {
                if (i > 0) Console.Write("\\\\");

                for (int j = 0; j < rank; j++)
                {
                    if (j > 0) Console.Write("&");

                    Console.WriteLine(A[i, j]);
                }

            }
            Console.Write("\\end{pmatrix}");


            // Print out B
            Console.Write("B = \\begin{pmatrix}");
            Console.Write(B[0]);
            for (int i = 1; i < rank; i++)
            {
                Console.Write("\\\\ " + B[i]);
            }
            Console.Write("\\end{pmatrix}");
            Console.WriteLine("\\end{equation*}");

            Console.WriteLine(" We want to find $A^{-1}$ and $A^{-1} B$...");

            StringBuilder array_fmt = new StringBuilder();

            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < rank; i++)
                {
                    array_fmt.Append("c");
                }

                array_fmt.Append("|");
            }
            ArrayFormat = array_fmt.Append("c").ToString();

            if (ShowIntermediateSteps)
            {

                Console.WriteLine("\\begin{equation*}");
                Console.WriteLine(GetCombinedArrays());
                Console.WriteLine("\\end{equation*}");

            }

            string multiplier = null;

            //
            // Build the upper triangle matrix in A
            //
            for (int i = 0; i < rank; i++)
            {
                multiplier = A[i, i];

                B[i] = "\\frac{" + B[i] + "}{" + multiplier + "}";

                if (A_inverse[i, i] != "0")
                {
                    A_inverse[i, i] = "\\frac{" + A_inverse[i, i] + "}{" + multiplier + "}";
                }

                A[i, i] = "1";

                //work with under the diagonal elements on the inverse

                for (int j = 0; j < i; j++)
                {
                    if (A_inverse[i, j] != "0")
                    {
                        A_inverse[i, j] = "\\frac{" + A_inverse[i, j] + "}{" + multiplier + "}";
                    }
                }

                //work with over the diagonal elements in the row for A

                for (int j = i + 1; j < rank; j++)
                {
                    A[i, j] = "\\frac{" + A[i, j] + "}{" + multiplier + "}";
                }

                if (ShowIntermediateSteps)
                {
                    Console.WriteLine("\\begin{equation*}");
                    Console.WriteLine("\\xrightarrow{\\frac{1}{" + multiplier + "} R_{" + (i + 1) + "}}");
                    Console.WriteLine(GetCombinedArrays());
                    Console.WriteLine("\\end{equation*}");
                }

                //Row additions
                for (int j = i + 1; j < rank; j++)
                {
                    multiplier = A[j, i];

                    // Work with B
                    B[j] = B[j] + " - \\left (" + multiplier + " \\right ) \\left ( " + B[i] + "\\right )";

                    // Row addition in A
                    A[j, i] = "0";

                    for (int k = i + 1; k < rank; k++)
                    {
                        A[j, k] = A[j, k] + " - \\left (" + multiplier + " \\right ) \\left ( " + A[i, k] + "\\right )";
                    }

                    //Work with inverse matrix

                    for (int k = 0; k <= i; k++)
                    {
                        if (A_inverse[i, k] != "0")
                        {
                            A_inverse[j, k] = A_inverse[j, k] + " - \\left (" + multiplier + " \\right ) \\left ( " + A_inverse[i, k] + "\\right )";
                        }
                    }

                    if (ShowIntermediateSteps)
                    {
                        Console.WriteLine("\\begin{equation*}");
                        Console.WriteLine("\\xrightarrow{R_{" + (j + 1) + "} - \\left ( " + multiplier + "\\right ) R_{" + (i + 1) + "}}");
                        Console.WriteLine(GetCombinedArrays());
                        Console.WriteLine("\\end{equation*}");
                    }

                }


            }

            //Now finish the elimination from the diagonal in A to the upper triangle of A
            for (int i = rank - 1; i >= 0; i--)
            {
                for (int j = i - 1; j >= 0; j--)
                {
                    //What's the multiplier?
                    multiplier = A[j, i];
                    A[j, i] = "0";

                    //Handle the B[j]
                    B[j] = B[j] + " - \\left (" + multiplier + " \\right ) \\linebreak \\left ( " + B[i] + "\\right )";

                    //Nothing to do with A in this case

                    //A inverse is going to be a full row operation
                    for (int k = 0; k < rank; k++)
                    {
                        A_inverse[j, k] = A_inverse[j, k] + " - \\left (" + multiplier + " \\right ) \\linebreak \\left ( " + A_inverse[i, k] + "\\right )";
                    }

                    if (ShowIntermediateSteps)
                    {

                        Console.WriteLine("\\begin{equation*}");
                        Console.WriteLine("\\xrightarrow{R_{" + (j + 1) + "} - \\left ( " + multiplier + "\\right ) R_{" + (i + 1) + "}}");
                        Console.WriteLine(GetCombinedArrays());
                        Console.WriteLine("\\end{equation*}");
                    }
                }
            }


            if (FinalOutputAsMatrix)
            {

                Console.WriteLine("\\begin{equation*}");
                // Print out A
                Console.Write("A^{-1} = \\begin{pmatrix}");
                for (int i = 0; i < rank; i++)
                {
                    if (i > 0) Console.Write("\\\\");

                    for (int j = 0; j < rank; j++)
                    {
                        if (j > 0) Console.WriteLine("&");

                        Console.WriteLine(A_inverse[i, j]);
                    }

                }
                Console.Write("\\end{pmatrix}");


                // Print out B
                Console.Write("A^{-1}B = \\begin{pmatrix}");
                Console.Write(B[0]);
                for (int i = 1; i < rank; i++)
                {
                    Console.Write("\\\\ " + B[i]);
                }
                Console.Write("\\end{pmatrix}");
                Console.WriteLine("\\end{equation*}");

            }
            else
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("The solution for $A^{-1}$ follows...");



                Console.WriteLine();

                for (int i = 0; i < rank; i++)
                {
                    for (int j = 0; j < rank; j++)
                    {
                        Console.WriteLine("Row " + i + ", Column " + j + " of $A^{-1}$ is");
                        Console.WriteLine("\\begin{equation*}");
                        Console.WriteLine(A_inverse[i, j]);
                        Console.WriteLine("\\end{equation*}");


                    }
                }


                for (int i = 0; i < rank; i++)
                {
                    Console.WriteLine("Row " + i + " of $A^{-1} B$ is");
                    Console.WriteLine("\\begin{equation*}");
                    Console.WriteLine(B[i]);
                    Console.WriteLine("\\end{equation*}");


                }

            }

            //End of file
            Console.WriteLine("\\end{document}");


        }

        public string GetCombinedArrays()
        {
            StringBuilder output = new StringBuilder();

            output.Append("\\left ( \\begin{array}{" + ArrayFormat + "}");

            for (int i = 0; i < rank; i++)
            {
                if (i > 0) { output.AppendLine("\\\\"); }

                for (int j = 0; j < rank; j++)
                {
                    if (j > 0) output.Append("&");
                    output.AppendLine(A[i, j]);
                }

                for (int j = 0; j < rank; j++)
                {
                    output.Append("&");
                    output.AppendLine(A_inverse[i, j]);
                }

                output.Append("&");
                output.Append(B[i]);

            }

            output.Append("\\end{array} \\right )");
            return output.ToString();
        }

        public string NtoC(int input)
        {
            return NtoC(input.ToString());
        }

        public string NtoC(string input)
        {
            return input.Replace("0", "a")
                        .Replace("1", "b")
                        .Replace("2", "c")
                        .Replace("3", "d")
                        .Replace("4", "e")
                        .Replace("5", "f")
                        .Replace("6", "g")
                        .Replace("7", "h")
                        .Replace("8", "i")
                        .Replace("9", "j");

        }

        public static void PrintUsage()
        {
            Console.WriteLine(@"
LatexMatrixInverse C#.Net Edition 1.0
Developed by Mike Burr
This application is provided without any warranties, express or implied.

Usage: LatexMatrixInverse <rank>

<rank>: The rank of the matrix. Also the number of the diagonal elements in a square matrix.
ex. A 2x2 matrix has rank 2, a 3x3 matrix has rank 3, etc...

The latex code for the matrix inverse and corresponding solution vector
of a matrix with given rank will be written to standard out along with supporting work
code (ex. row transformations and additions). The end user should then adjust the matrix
values in the resulting latex code to get the desired result for their specific problem.

The matrix inversion is performed using Gauss-Jordan elimination.

Note that singular matrices still won't be invertible, but matrices with inverses
should be invertible using the latex code generated with the occasional initial
row substitution. Simplification of the resulting formulas are the end user's
responsibility.

A recommended use of the application would be to redirect the output to a file.
ex. The inverse for a 3x3 matrix written to m3x3.tex:

LatexMatrixInverse 3 > m3x3.tex
");
        }
    }
}


-->