np.reshape(X, order='f')
, where the string 'f'
stands for the Fortran ordering.
In [ ]:
Consider a 2D Poisson equation in $\Omega = [0,1]^2$ $$ \Delta u \equiv \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} = f(x,y), \quad (x,y)\in \Omega $$ with zero Dirichlet boundary conditions $$ u_{\partial \Omega} = 0, $$ with known function $f(x,y)$ and unknown $u(x,y)$.
To find solution of the Poisson equation we will use the finite difference method. Standard second order finite difference discretization on a uniform grid $(x_i, y_j) = (ih, jh)$, $i,j = 0,\dots, N$, $h = \frac{1}{N}$ leads to the following system of equations: $$ \begin{split} &\frac{u_{i+1,j} - 2u_{i,j} + u_{i-1,j}}{h^2} + \frac{u_{i,j+1} - 2u_{i,j} + u_{i,j-1}}{h^2} = f(ih, jh) \\ &u_{0,j} = u_{i,0} = u_{N,j} = u_{i,N} = 0, \quad i,j = 0,\dots,N \end{split} $$
scipy.sparse.linalg.spsolve
which is direct sparse solver. Use pandas
library and print table that contains $N$, time, relative error between the analytic solution and the obtained one for $N=128,256,512$. Matrices $B, C$ and $A_h$ should be assembled in the CSR
format using functions from the scipy.sparse
package (functions scipy.sparse.kron
and scipy.sparse.spdiags
will be helpful). Do not use full matrices! Use only sparse arithmetics. cg
, minres
, GMRES
, BicgStab
? Explain why. scipy.sparse.linalg.eigs
(Implicitly Restarted Arnoldi Method) or if $B$ and $C$ are Hermitian using scipy.sparse.linalg.eigsh
(Implicitly Restarted Lanczos Method). Print them.scipy.sparse.linalg.eigsh
and compare them with what you have found using eigenvalues of $B$ and $C$.
In [ ]:
scipy.sparse.linalg.LinearOperator
to create an object that has attribute .dot()
(this object will be further used in the iterative process). Note that .dot()
input and output must be 1D vectors, so do not forget to use reshape.
In [ ]: