* This function creates an n by n tridiagonal matrix with the values
* a on the subdiagonal,
* b on the diagonal, and
* c on the superdiagonal.
* Example for n=5:
* [ b c 0 0 0 ]
* [ a b c 0 0 ]
* A = [ 0 a b c 0 ]
* [ 0 0 a b c ]
* [ 0 0 0 a b ]
*/
MatrixXdA;
// TO DO: Fill the matrix A with zeros. Then fill the subdiagonal with the value a, the diagonal with b and the superdiagonal with c.
// Hint: You can get the diagonal of A by A.diagonal(). Moreover, you can get the super- and subdiagonals by passing +1 or -1 as arguments to A.diagonal().
> Eigen matrices have a range of methods to access their submatrices (blocks), instead of individual entries at a time.Suppose A is an Eigen::MatrixXd object, then a few useful methods are:
*`A.row(i)`: the i-th row of A,
*`A.col(j)`: the j-th column of A,
*`A.topRows(p)`: the first p rows of A,
*`A.leftCols(q)`: the first q columns of A,
*`A.bottomRightCorner(p,q)`: the p by q matrix formed by the intersection of the last p rows and last q columns of A, and more generally
*`A.block(i,j,p,q)`: the p by q submatrix of A, whose top-left corner is at the index (i,j).
> The purpose of this exercise is to learn to declare and initialize Eigen matrices, and to get familiar with some handy typedefs and methods.
> Open "MatrixBlocks.hpp" and fill in the missing code in between the delimiters `// START` and `// END` according to the instructions preceded by `// TO DO:`.
> Read each function of the program carefully. The code will not compile until after the first two tasks are finished, which is to include headers and set the namespace.
> There are three functions in MatrixBlocks.hpp and main.cpp has one test for each function.
***
> `zero_row_col( MatrixXd A, int p, int q )`: This function returns a copy of A with row p and column q set to zero.
The test prints `zero_row_col(Matrix3d::Constant(-1),0,1)`, and the correct result is:
```
0 0 0
-1 0 -1
-1 0 -1
```
***
> `swap_left_right_blocks( MatrixXd A, int p )`: This function swaps splits the matrix A into two blocks, the first p columns and the rest, and returns a matrix in which these blocks have been swapped.
The test prints `swap_left_right_blocks(MatrixXd::Identity(4,3),2)`, and the correct result is:
```
0 1 0
0 0 1
1 0 0
0 0 0
```
***
> `tridiagonal( int n, double a, double b, double c)`: This function creates an n by n tridiagonal matrix with constant diagonals with the values a, b, and c.
The test prints `tridiagonal(4,-1,2,-1)`, and the correct result is:
> Eigen matrices have a range of methods that reduce them to a single number. Suppose A is an Eigen::MatrixXd object, then a few useful methods are:
*`A.size()`: the number of entries in A,
*`A.sum()`: the sum of all entries in A,
*`A.prod()`: the product of all entries in A,
*`A.minCoeff()`: the minimum value amongst the entries of A,
*`A.maxCoeff()`: the maximum value amongst the entries of A, and
*`A.norm()`: The (Frobenius) norm of the matrix A.
> The [Eigen::Array class](https://eigen.tuxfamily.org/dox/group__TutorialArrayClass.html) is also featured in this exercise to perform coefficient-wise comparison.
> Open "MatrixReduce.hpp" and fill in the missing code in between the delimiters `// START` and `// END` according to the instructions preceded by `// TO DO:`.
> Read each function of the program carefully. The code will not compile until after the first two tasks are finished, which is to include headers, set the namespace, and write the average() function.
> There are four functions in MatrixReduction.hpp and main.cpp has one test for each function.
***
> `average( MatrixXd A )`: This function should calculate the average of the entries in A.
The test prints `average(Matrix3d::Identity())`, and the correct result is:
```
0.333333
```
***
> `percent_zero( MatrixXd A )`: This function calculates the percentage of entries in A that are exactly equal to zero.
The test prints `percent_zero(Matrix3d::Identity())`, and the correct result is:
```
66.6667
```
***
> `has_zero_column( MatrixXd A )`: This function checks if any one of the columns in A is equal to zero.
The test prints
`has_zero_column(B)` followed by `has_zero_column(B.transpose())` where `B=MatrixXd::Identity(4,5)`, and the correct result is:
```
1 0
```
***
> `columns_sum_to_zero( MatrixXd A )`: This functions returns a copy of A, except that the diagonal entries have been changed in a way such that the columns of the new matrix sum to zero.
The test prints `columns_sum_to_zero(C)` where `C=Matrix3d::Random()+Matrix3d::Constant(1)` (the random seed is fixed), and the correct result is: