Reducing a linear system of equations (Matrix Equations) with some known values to the system with only unknown values

481 Views Asked by At

So upon programming a Finite Element Method with Wolfram's Mathematica I came across the problem of having to solve a linear system of equations with some known values that resulted from boundary conditions.

The function for solving is LinearSolve[m,b] with m being the Matrix and b being the result of an equation: $$[m] \cdot u=b$$

So some $u_i$s are known, and if $u_i$ is known, the coresponding $b_i$ is unknown and vice versa. My goal in order to use the function LinearSolve was to get the corresponding system that only includes the equations for the unknown $u_i$s.

I did some thinking with a small system that I know the answer of:

$$ \begin{bmatrix}1&1&1&1\\2&3&6&7\\1&5&9&2\\2&2&4&4\end{bmatrix} \cdot \begin{bmatrix} 3 \\5 \\7 \\2 \end{bmatrix} =\begin{bmatrix} 17 \\77 \\95 \\52 \end{bmatrix} $$

If I pretend like only $u_2$ is known, that means $b_2$ is unknown we have the following scenario:

$$ \begin{bmatrix}1&1&1&1\\2&3&6&7\\1&5&9&2\\2&2&4&4\end{bmatrix} \cdot \begin{bmatrix} u_1 \\5 \\u_3 \\u_4 \end{bmatrix} =\begin{bmatrix} 17 \\b_2 \\95 \\52 \end{bmatrix} $$

my thought process then was that equation 2 (row 2) is irrelevant for the solution to $u_1, u_3, u_4$ so that row can be removed and we get:

$$ \begin{bmatrix}1&1&1&1\\1&5&9&2\\2&2&4&4\end{bmatrix} \cdot \begin{bmatrix} u_1 \\5 \\u_3 \\u_4 \end{bmatrix} =\begin{bmatrix} 17 \\95 \\52 \end{bmatrix} $$

After taking a look at the equations and how I would rearange that system by hand:

$$eq.1: 1u_1+1\cdot5+1u_3+1u_4=17 \rightarrow 1u_1+1u_3+1u_4=17-1\cdot5$$ $$eq.3: 1u_1+5\cdot5+9u_3+2u_4=95 \rightarrow 1u_1+9u_3+2u_4=95-5\cdot5$$ $$eq.4: 2u_1+2\cdot5+4u_3+4u_4=52 \rightarrow 2u_1+4u_3+4u_4=52-2\cdot5$$

I came up with:

$$ \begin{bmatrix}1&1&1\\1&9&2\\2&4&4\end{bmatrix} \cdot \begin{bmatrix} u_1 \\u_3 \\u_4 \end{bmatrix} =\begin{bmatrix} 17 \\95 \\52 \end{bmatrix} -\begin{bmatrix} 1 \\5 \\2 \end{bmatrix}\cdot u_2 $$

Doing this, I now have a system that is solveable by LinearSolve and delivers the correct results. It is also quite straightforward to code this:

  1. Remove the rows corresponding to the known $u_i$s in $m$ and $b$
  2. Remove the columns corresponding to the known $u_i$s and substract them times a vector of the known $u_i$s from the rhs of the equation

I know this works for a small system, but is what I'm doing here mathematically valid? are there much simpler ways to achieve this?

1

There are 1 best solutions below

0
On BEST ANSWER

What you are doing is totally valid mathematically:

First, you remove the equation on the known which had been superfluously generated, as you do not intend to use them.

Second, you replace the matrix-vector product by its definition.

Third, you replace a variable by its value.

However, to get a valid result you'll have to check that, with what looks like your boundary condition, the Banach Necas Babouska condition (or some easier ones) are met both for the discrete and continuous level.