|
1 |
| -# Solving Linear Systems in Julia |
| 1 | +# Getting Started with Solving Linear Systems in Julia |
2 | 2 |
|
3 |
| -A linear system $$Au=b$$ is specified by defining an `AbstractMatrix` `A`, or |
4 |
| -by providing a matrix-free operator for performing `A*x` operations via the |
5 |
| -function `A(u,p,t)` out-of-place and `A(du,u,p,t)` for in-place. For the sake |
6 |
| -of simplicity, this tutorial will only showcase concrete matrices. |
| 3 | +A linear system $$Au=b$$ is specified by defining an `AbstractMatrix`. For the sake |
| 4 | +of simplicity, this tutorial will start by only showcasing concrete matrices. |
7 | 5 |
|
8 | 6 | The following defines a matrix and a `LinearProblem` which is subsequently solved
|
9 | 7 | by the default linear solver.
|
|
34 | 32 |
|
35 | 33 | Thus, a package which uses LinearSolve.jl simply needs to allow the user to
|
36 | 34 | pass in an algorithm struct and all wrapped linear solvers are immediately
|
37 |
| -available as tweaks to the general algorithm. |
| 35 | +available as tweaks to the general algorithm. For more information on the |
| 36 | +available solvers, see [the solvers page](@ref linearsystemsolvers) |
| 37 | + |
| 38 | +## Sparse and Structured Matrices |
| 39 | + |
| 40 | +There is no difference in the interface for using LinearSolve.jl on sparse |
| 41 | +and structured matrices. For example, the following now uses Julia's |
| 42 | +built-in [SparseArrays.jl](https://docs.julialang.org/en/v1/stdlib/SparseArrays/) |
| 43 | +to define a sparse matrix (`SparseMatrixCSC`) and solve the system using LinearSolve.jl. |
| 44 | +Note that `sprand` is a shorthand for quickly creating a sparse random matrix |
| 45 | +(see SparseArrays.jl for more details on defining sparse matrices). |
| 46 | + |
| 47 | +```@example linsys1 |
| 48 | +using LinearSolve, SparseArrays |
| 49 | +
|
| 50 | +A = sprand(4, 4, 0.75) |
| 51 | +b = rand(4) |
| 52 | +prob = LinearProblem(A, b) |
| 53 | +sol = solve(prob) |
| 54 | +sol.u |
| 55 | +
|
| 56 | +sol = solve(prob, KrylovJL_GMRES()) # Choosing algorithms is done the same way |
| 57 | +sol.u |
| 58 | +``` |
| 59 | + |
| 60 | +## Using Matrix-Free Operators |
| 61 | + |
| 62 | +`A`, or |
| 63 | +by providing a matrix-free operator for performing `A*x` operations via the |
| 64 | +function `A(u,p,t)` out-of-place and `A(du,u,p,t)` for in-place. |
0 commit comments