mtl4.html 19.1 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
<!DOCTYPE html>
<html>
  <head>
    <title>AMDiS - Adaptive Multi-Dimensional Simulations</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <style type="text/css">
      @import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
      @import url(https://fonts.googleapis.com/css?family=Raleway);
      @import url(https://fonts.googleapis.com/css?family=Ubuntu);
      @import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
      @import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);

      table tr:nth-child(even) {
          background-color: #eee;
      }
      table tr:nth-child(odd) {
          background-color: #fff;
      }
      table tr td {
        padding: 10px;
        border-left: 1px solid #aaa;
      }
    </style>
    <!--<link rel="stylesheet" type="text/css" href="style_display.css" />-->
    <link rel="stylesheet" type="text/css" href="style_print.css" />
  </head>
  <body>
    <textarea id="source">

class: center, middle

# Session 8
## MTL4 - the matrix template library

---

# Agenda

### Wednesday
- Boundary conditions and Composite FEM
- **MTL4 - a linear algebra library**
- Linear solvers and preconditioners
- Talk by Sebastian Aland

(Examples are taken from [MTL4 website](www.mtl4.org).)

---


# Features

### Open-Source Edition
- Easy, native application interface (API)
- Intuitive mathematical notation
- Expression Templates
- Rich Expression Templates
- Meta-Tuning
- Newest Krylov-subspace methods
- Fast and memory efficient matrix assembly
- Transparent BLAS-Support (partially, complete support in separated edition)
- Transparent UMFPACK Support
- Generic Implementation
- Support GNU-Multiprecision library, Boost.Interval, Boost.Quaternion
- Nested Container (e.g. matrices of vectors) operationally differentiated
- Advanced Morton order matrix formats

### Supercomputing Edition
- Distributed data structures
- Parallel operations of distributed data structure
- Uniform Interface for parallel and sequential computation
- In addition to the functionality of Open Source Edition

---

# Motivating example

Multiply two matrices: `\(A = B \cdot C\)`.

### Call Lapack/BLAS routine directly
```
int m= num_rows(A), n= num_cols(B), k= num_cols(A),
    lda= A.get_ldim(), ldb= B.get_ldim(), ldc= C.get_ldim();
double alpha= 1.0, beta= 1.0;
char a_trans= 'N', b_trans= 'N';

// Call Lapack function dgemm
dgemm(&a_trans, &b_trans, &m, &n, &k, &alpha, &A[0][0], &lda,
      &B[0][0], &ldb, &beta, &C[0][0], &ldc);
```

### In MTL4
```
A = B * C
```
use Lapack/BLAS internally if available.

---

# Matrix/Vector types

```
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int, char**)
{
  using namespace mtl;

  // Define dense vector of doubles with 10 elements all set to 0.0.
  dense_vector<double>   v(10, 0.0);

  // Set element 7 to 3.0.
  v[7]= 3.0;

  std::cout << "v is " << v << "\n";
}
```
- Column vector
- Constructor takes two arguments: size, initial value
- Indices start with zero

---

# Matrix/Vector types

```
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int, char**)
{
  using namespace mtl;

  // Define dense vector of complex with 7 elements.
  dense_vector<std::complex<float>, mtl::vec::parameters<tag::row_major> >  v(7);

  // Set all elements to 3+2i
  v= std::complex<float>(3.0, 2.0);
  std::cout << "v is " << v << "\n";

  // Set all elements to 5+0i
  v= 5.0;
  std::cout << "v is " << v << "\n";

  v= 6;
  std::cout << "v is " << v << "\n";
}
```
- Row vector, with 7 elements without (explicit) initialization
- value_type is `std::complex`

---

# Matrix/Vector types

`C++11` Variant of creating vectors
```
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

template <typename Vector>
void fill_and_print(Vector& v, const char* name)
{
  // Set values in traditional way and print them
  v= 1.2, 3.4, 5.6;
  std::cout << name << " is " << v << "\n";
}

int main(int, char**)
{
  using namespace mtl;

  vector<double>             v1(3); // Regular vector
  fill_and_print(v1, "v1");

  vector<double, row_major>  v2(3); // Row vector
  fill_and_print(v2, "v2");

  vector<double, dim<3> >    v3;    // Fixed-size vector
  fill_and_print(v3, "v3");
}
```

---

# Matrix/Vector types
Available matrix types:
- `dense2D` (dense matrix)
- `morton_dense` (dense Morton-order matrix)
- `compressed2D` (CRS/CCS matrix)
- `coordinate2D` (Sparse matrix structure in coordinate format)
- `multi_vector` (Matrix constituting of set of column vectors)
- `block_diagonal2D`
- `sparse_banded`
- `element_structure`
- `ell_matrix` (Ell-Pack format)
- some *matrix-free* linear operators, like `identity2D`, `poisson2D_dirichlet`

---

# Matrix/Vector types

```
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int, char**)
{
  using namespace mtl;

  // A is a row-major matrix
  dense2D<double>  A(10, 10);

  A= 0.0;       // Matrices are not initialized by default
  A(2, 3)= 7.0; // Assign a value to a matrix element
  A[2][4]= 3.0; // You can also use a more C-like notation

  std::cout << "A is \n" << A << "\n";

  // B is a column-major matrix
  dense2D<float, mat::parameters<tag::col_major> > B(10, 10);

  // Assign the identity matrix times 3 to B
  B= 3;
  std::cout << "B is \n" << B << "\n";
}
```
- matrix is row-major by default
- Assignment of scalar to matrix creates scaled identity matrix!

---

# Matrix/Vector types
Recursive memory layout: morton-dense matrices
```
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int, char**)
{
  using namespace mtl;

  // Z-order matrix
  morton_dense<double, recursion::morton_z_mask>  A(10, 10);

  A= 0;
  A(2, 3)= 7.0;
  A[2][4]= 3.0;
  std::cout << "A is \n" << A << "\n";

  // B is an N-order matrix with column-major 4x4 blocks, see paper
  morton_dense<float, recursion::doppled_4_col_mask> B(10, 10);

  // Assign the identity matrix times 3 to B
  B= 3;
  std::cout << "B is \n" << B << "\n";
}
```

---

# Matrix/Vector types
Recursive memory layout: morton-dense matrices. Four level Z-ordering:
.center[
<img src="images/Four-level_Z.png" width="60%" alt="4-level z-ordering" />
]
(Source: Wikipedia)

---

# Matrix/Vector types
Recursive memory layout: morton-dense matrices. Four level Z-ordering:
.center[
<img src="images/Four-level_Z.png" width="30%" alt="4-level z-ordering" />
]
- recursive structure
- block locality
- optimal for some recursive algorithms (e.g. Strassen matrix-matrix multiplication)
- Local block structure / Pattern can be described by bitmask.

---

# Matrix/Vector types
## Compressed sparse matrices

```
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int, char**)
{
  using namespace mtl;

  compressed2D<double> A(12, 12);  // CRS matrix

  // Laplace operator discretized on a 3x4 grid
  mat::laplacian_setup(A, 3, 4);
  std::cout << "A is \n" << A;

  // Element access is allowed for reading
  std::cout << "A[3][2] is " << A[3][2] << "\n\n";

  compressed2D<float, mat::parameters<tag::col_major> > B(10, 10); // CCS matrix

  // Assign the identity matrix times 3 to B
  B= 3;
  std::cout << "B is \n" << B << "\n";
}
```
- default: compressed row storage

---

# Matrix/Vector types

```
template <typename Matrix>
void fill(Matrix& A) {
  A= 1.2, 3.4,
     5.6, 7.8;
}

int main(int, char**) {
  using namespace mtl;
  matrix<double>  A(2, 2); // Create a 2 by 2 dense matrix
  fill(A);
```
---
# Matrix/Vector types

```
template <typename Matrix>
void fill(Matrix& A) {
  A= 1.2, 3.4,
     5.6, 7.8;
}

int main(int, char**) {
  using namespace mtl;
  matrix<double>  A(2, 2); // Create a 2 by 2 dense matrix
  fill(A);

  matrix<double, sparse> B(2, 2); // Now a sparse matrix
  fill(B);
```
---
# Matrix/Vector types

```
template <typename Matrix>
void fill(Matrix& A) {
  A= 1.2, 3.4,
     5.6, 7.8;
}

int main(int, char**) {
  using namespace mtl;
  matrix<double>  A(2, 2); // Create a 2 by 2 dense matrix
  fill(A);

  matrix<double, sparse> B(2, 2); // Now a sparse matrix
  fill(B);

  // A column-major sparse matrix (CCS by default)
  matrix<double, sparse, column_major> C(2, 2);
  fill(C);
```
---
# Matrix/Vector types

```
template <typename Matrix>
void fill(Matrix& A) {
  A= 1.2, 3.4,
     5.6, 7.8;
}

int main(int, char**) {
  using namespace mtl;
  matrix<double>  A(2, 2); // Create a 2 by 2 dense matrix
  fill(A);

  matrix<double, sparse> B(2, 2); // Now a sparse matrix
  fill(B);

  // A column-major sparse matrix (CCS by default)
  matrix<double, sparse, column_major> C(2, 2);
  fill(C);

  matrix<double, col_major> D(2, 2); // A Fortran-like matrix
  fill(D);
```
---
# Matrix/Vector types

```
template <typename Matrix>
void fill(Matrix& A) {
  A= 1.2, 3.4,
     5.6, 7.8;
}

int main(int, char**) {
  using namespace mtl;
  matrix<double>  A(2, 2); // Create a 2 by 2 dense matrix
  fill(A);

  matrix<double, sparse> B(2, 2); // Now a sparse matrix
  fill(B);

  // A column-major sparse matrix (CCS by default)
  matrix<double, sparse, column_major> C(2, 2);
  fill(C);

  matrix<double, col_major> D(2, 2); // A Fortran-like matrix
  fill(D);

  // A sparse matrix with a shorter size type
  matrix<float, sparse, as_size_type<int> > E(2, 2);
  fill(E);
```
---
# Matrix/Vector types

```
template <typename Matrix>
void fill(Matrix& A) {
  A= 1.2, 3.4,
     5.6, 7.8;
}

int main(int, char**) {
  using namespace mtl;
  matrix<double>  A(2, 2); // Create a 2 by 2 dense matrix
  fill(A);

  matrix<double, sparse> B(2, 2); // Now a sparse matrix
  fill(B);

  // A column-major sparse matrix (CCS by default)
  matrix<double, sparse, column_major> C(2, 2);
  fill(C);

  matrix<double, col_major> D(2, 2); // A Fortran-like matrix
  fill(D);

  // A sparse matrix with a shorter size type
  matrix<float, sparse, as_size_type<int> > E(2, 2);
  fill(E);

  // A (dense) matrix with compile-time size
  matrix<double, dim<2, 2> > F;
  fill(F);
}
```

---

# Matrix insertion

For sparse matrices the direct element access/insertion is slow!
- Use an inserter structure for this task

```
template <typename Matrix>
void fill(Matrix& m)
{
  // Matrices are not initialized by default
  m= 0.0;

  // Create inserter for matrix m
  mat::inserter<Matrix> ins(m);

  // Insert value in m[0][0]
  ins[0][0] << 2.0;
  ins[1][2] << 0.5;
  ins[2][1] << 3.0;

  // Destructor of ins sets final state of m
}
```

---

# Matrix insertion

For sparse matrices the direct element access/insertion is slow!
- Use in inserter structure for this task

```
template <typename Matrix>
void modify(Matrix& m)
{
  // Type of m's elements
  typedef typename Collection<Matrix>::value_type value_type;

  // Create inserter for matrix m
  // Existing values are not overwritten but inserted
  mat::inserter<Matrix, update_plus<value_type> > ins(m, 3);

  // Increment value in m[0][0]
  ins[0][0] << 1.0;

  // Elements that don't exist (in sparse matrices) are inserted
  ins[1][1] << 2.5;
  ins[2][1] << 1.0;
  ins[2][2] << 4.0;

  // Destructor of ins sets final state of m
}
```

---

# Expressions with Vectors and Matrices

- MTL uses Expression templates, i.e. instead of storing the result of a binary operation, just
  store the operation as functor and perform calculation later, at assignment.

The expression
```
Vector a, b, c, d;
a = b + c + d
```
translates into
```
for (size_t i = 0; i < size(a); ++i)
  a[i] = b[i] + c[i] + d[i];
```
So, no temporaries are necessary, no multiple-loops are implemented.

- Also known as lazy-evaluation: Result of operation calculated only when needed.

---

# Expressions with Vectors and Matrices

Examples of vector expressions:
```
typedef std::complex<double>  cdouble;
dense_vector<cdouble>         u(10), v(10);
dense_vector<double>          w(10), x(10, 4.0);

for (size_t i = 0; i < size(v); ++i)
    v[i] = cdouble(i+1, 10-i), w[i]= 2 * i + 2;

u= v + w + x;

u-= 3 * w;

u*= 6 ;

u/= 2;

u+= dot(v, w) * w + 4.0 * v + 2 * w;

std::cout << "i * w is " << cdouble(0,1) * w << "\n";
```

---

# Expressions with Vectors and Matrices

*Rich* vector expression

```
// Increment w by x
// and assign the sum of--the incremented--w and v to u
u= v + (w+= x);
std::cout << "u is " << u << "\n";

// w= w * 3; x= 2; v= v + w + x; u= u + v;
u+= v+= (w*= 3) + (x= 2);
std::cout << "u is " << u << "w is " << w << "\n";
```
All these operations are performed in one loop and each vector element is accessed exactly once.

---

# Expressions with Vectors and Matrices

Expressions involving matrices

```
const unsigned n= 10;
compressed2D<double>                         A(n, n);
dense2D<int, mat::parameters<col_major> >    B(n, n);
morton_dense<double, 0x555555f0>             C(n, n), D(n, n);

mat::laplacian_setup(A, 2, 5);
mat::hessian_setup(B, 1); mat::hessian_setup(C, 2.0); mat::hessian_setup(D, 3.0);

D+= A - 2 * B + C;

// Corresponds to A= B * B;
mult(B, B, A);

A= B * B;   // use BLAS
A= B * C;   // use recursion + tiling from MTL4

A+= B * C;  // Increment A by the product of B and C
A-= B * C;  // Likewise with decrement

A+= B * B + C * B - B * B * C * D;
```

---

# Expressions with Vectors and Matrices

Expressions involving matrices and vectors
```
const unsigned                xd= 2, yd= 5, n= xd * yd;
dense2D<double>               A(n, n);
compressed2D<double>          B(n, n);
hessian_setup(A, 3.0); laplacian_setup(B, xd, yd);

typedef std::complex<double>  cdouble;
dense_vector<cdouble>         v(n), w(n);
for (size_t i= 0; i < size(v); i++)
  v[i]= cdouble(i+1, n-i), w[i]= cdouble(i+n);

v+= A * w;
w= B * v;

// Scale A with 4 and multiply the scaled view with w
v= 4 * A * w;

// Scale w with 4 and multiply the scaled view with A
v= A * (4 * w);

// Scale both with 2 before multiplying
v= 2 * A * (2 * w);

// Scale v after the MVP
v= A * w;
v*= 4;
```

---

class: center, middle
# Linear solvers in MTL4

---

# Triangular solvers

To solve a linear system `\(Ax = b\)`, where the matrix is an upper/ lower triangular matrix (forward/backward substitution)
```
x = upper_trisolve(A, b);
// or
invert_diagonal(A);
x = inverse_upper_trisolve(A, b);
```
If `\(A\)` additionally has a unit diagonal, i.e.
\\[
A = \begin{pmatrix} 1 & a\_{0,1} & \cdots & a\_{0,n} \\\\
                    0 & 1        & a\_{1,2} & \vdots \\\\
                    \vdots & \ddots & & \vdots \\\\
                    0 & \cdots & 0 & 1 \end{pmatrix}
\\]
use
```
x = unit_upper_trisolve(A, b);
```

---

# Krylov subspace solvers

MTL provides a long list of availbale iterative solvers.
### Concept: separate solver, preconditioner, and observer

```
int main(int, char**)
{
  const int size = 40, N = size * size;
  typedef compressed2D<double>  matrix_type;

  // Set up a matrix 1,600 x 1,600 with 5-point-stencil
  matrix_type                   A(N, N);
  mat::laplacian_setup(A, size, size);

  // Create an ILU(0) preconditioner
  pc::ilu_0<matrix_type>        P(A);

  // Set b such that x == 1 is solution; start with x == 0
  dense_vector<double>          x(N, 1.0), b(N);
  b= A * x; x= 0;

  // Termination criterion: r < 1e-6 * b or N iterations
  noisy_iteration<double>       iter(b, 500, 1.e-6);

  // Solve Ax == b with left preconditioner P
  bicgstab(A, x, b, P, iter);
}
```

---

# Krylov subspace solvers

### Available solvers:
- Conjugate Gradient: `itl::cg(A, x, b, L, iter);`
- Conjugate Gradient Squared: `itl::cgs(A, x, b, L, iter);`
- Bi-Conjugate Gradient: `itl::bicg(A, x, b, L, iter);`
- BiCG Stabilized: `itl::bicgstab(A, x, b, L, iter);`
- BiCG Stabilized(ell): `itl::bicgstab_ell(A, x, b, L, R, iter, ell);`
- Generalized Minimal Residual: `itl::gmres(A, x, b, L, R, iter, restart);`
- Induced Dimension Reduction on s dimensions (IDR(s)):
  `itl::idr_s(A, x, b, L, R, iter, s);`
- Quasi-minimal residual: `itl::qmr(A, x, b, L, R, iter);`
- Transposed-free Quasi-minimal residual: `itl::tfqmr(A, x, b, L, R, iter)`.

--

### Preconditioners:
- Identity: that is no preconditioning: `itl::pc::identity<Matrix, Value>;`
- Diagonal inversion: `itl::pc::diagonal<Matrix, Value>;`
- ILU(0): Incomplete LU without fill-in: `itl::pc::ilu_0<Matrix, Value>;`
- IC(0): Incomplete Cholesky without fill-in: `itl::pc::ic_0<Matrix, Value>;`
- IMF(s): Incomplete Multifrontal LU Decomposition with s levels of fill-in: `itl::pc::imf_preconditioner<Value>`

---

# Krylov subspace solvers

### Iteration (Observers)
- Basic iteration does not generate output: `basic_iteration(r0, m, r, a= 0);`
- Cyclic iteration prints residual information every c iteration: `cyclic_iteration(r0, m, r, a= 0, c= 100, out= std::cout);`
- Noisy iteration prints residual in each iteration: `noisy_iteration(r0, m, r, a= 0, out= std::cout)`.

The iterative methods are terminated when either:

- The maximum number of iterations is reached (failure);
- The relative residuum reduction was achieved; or
- The absolute residuum is below a if specified.

---

class: center, middle
# Iteration and Recursion

---

# Iteration and Recursion

```
template <typename Matrix>
void f(Matrix& A) {
  A= 7.0;  // Set values in diagonal

  // Define the property maps
  auto row=   row_map(A);
  auto col=   col_map(A);
  auto value= const_value_map(A);

  // Now iterate over the matrix
  for (auto c : major_of(A))      // rows or columns,
    for (auto i : nz_of(c))     // non-zeros within
      std::cout << "A[" << row(i) << "," << col(i) << "]=" << value(i) << '\n';
}
int main(int, char**) {
  // Define a row-major sparse and a column-major dense matrix
  compressed2D<double>                             A(3, 3);
  dense2D<double, mat::parameters<col_major> >  B(3, 3);

  f(A);
  f(B);
}
```
- Substracture of traversal: `[rows_of|cols_of|major_of|minor_of|nz_of|all_of]`
- Property maps: `[row_map|col_map|value_map|const_value_map|offset_map]`

---

class: center, middle
# Exercise
## symmetric Dirichlet boundary conditions

---

# Exercise: symmetric Dirichlet BC

In order to set a dirichlet condition `\(u_i=f\)` for an DOF i, the matrix is modified, s.t.
\\[
  \begin{pmatrix}
    & a\_{0,0} & a\_{0,i}   & a\_{0,n} \\\\
(i) & 0&  1  &0 \\\\
    & a\_{n,0} & a\_{n,i}  & a\_{n,n}
  \end{pmatrix}\begin{pmatrix}
  u\_0 \\\\ u\_i \\\\ u\_n
  \end{pmatrix} = \begin{pmatrix}
  b\_0 \\\\ f \\\\ b\_n
  \end{pmatrix}
\\]

By subtracting column i from the right-hand side, the matrix can be symmetrized again:
\\[
  \begin{pmatrix}
    & a\_{0,0} &  0  & a\_{0,n} \\\\
(i) & 0&  1  &0 \\\\
    & a\_{n,0} & 0  & a\_{n,n}
  \end{pmatrix}\begin{pmatrix}
  u\_0 \\\\ u\_i \\\\ u\_n
  \end{pmatrix} = \begin{pmatrix}
  b\_0-f\cdot a\_{0,i} \\\\ f \\\\ b\_n-f\cdot a\_{n,i}
  \end{pmatrix}
\\]

1. Implement this matrix-modification, using MTL4
2. See `ExtendedProblemStat" for an example of a non-symmetric implementation.


    </textarea>
    <script src="lib/remark.js" type="text/javascript"></script>
818
    <script type="text/javascript" src="MathJax/MathJax.js?config=TeX-AMS_HTML"></script>
Praetorius, Simon's avatar
Praetorius, Simon committed
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841

    <script type="text/javascript">
      var slideshow = remark.create({
        ratio: "4:3",
        highlightLanguage: "cpp"
      });

      // Setup MathJax
      MathJax.Hub.Config({
          tex2jax: {
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
          }
      });
      MathJax.Hub.Queue(function() {
          $(MathJax.Hub.getAllJax()).map(function(index, elem) {
              return(elem.SourceElement());
          }).parent().addClass('has-jax');
      });

      MathJax.Hub.Configured();
    </script>
  </body>
</html>