# Matrix-Free/Function-Only Linear Solves

**URL:** <https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411>\
**Category:** Numerics\
**Tags:** linearalgebra, linearsolve, matrix\
**Created:** [March 1, 2023, 10:07pm UTC](https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411 "2023-03-01T22:07:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [March 1, 2023, 10:07pm UTC](https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411/1 "2023-03-01T22:07:39Z")

</div>

Suppose I want to solve a system of equations `A*x = b`, and I have a function `A_func` such that `A_func(x) = A*x`. How could I go about solving the system of equations without constructing the matrix `A`?

I could construct the matrix `A` if I really wanted to, but I have written enough in terms of `A_func` that I would like to avoid it if possible.

I saw some similar topics, but they seemed to be focused on the nuances of specific package implementations.

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [March 1, 2023, 10:31pm UTC](https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411/2 "2023-03-01T22:31:30Z")

</div>

One option is to use an iterative method such as those from [Krylov.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl). Have a look at the docs to choose a method based on the properties of A (if any).

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 1, 2023, 10:37pm UTC](https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411/3 "2023-03-01T22:37:32Z")

</div>

[https://docs.sciml.ai/SciMLOperators/stable/](https://docs.sciml.ai/SciMLOperators/stable/)

SciMLOperators.jl isn’t perfect yet, but it’s pretty close. It has the most integration with the Julia package system by far too, and it’s only growing. So I’d recommend it.

[https://docs.sciml.ai/LinearSolve/stable/](https://docs.sciml.ai/LinearSolve/stable/)

LinearSolve.jl takes AbstractSciMLOperators and will use that with the various Krylov methods. This also means any SciML solver (ODEs, nonlinear solvers, etc.) will also take AbstractSciMLOperators for Jacobian/Hessian definitions.

---

<div class="post-metadata">

**Author:** ![amontoison](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amontoison/32/218741_2.png) [@amontoison](https://discourse.julialang.org/u/amontoison)\
**Post date:** [March 8, 2023, 5:04am UTC](https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411/4 "2023-03-08T05:04:50Z")

</div>

@leespen1 The relevant documentation page for Matrix-free operators is [here](https://juliasmoothoptimizers.github.io/Krylov.jl/dev/factorization-free/) if want you to use it in Krylov.jl.

We did two examples with `LinearOperators.jl` but you can use `SciMLOperators.jl`, `LinearMaps.jl` or your own operator if you prefer.

For information, `LinearSolve.jl` mainly uses `Krylov.jl` for Krylov methods under the hood.

---

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [March 14, 2023, 7:25pm UTC](https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411/5 "2023-03-14T19:25:46Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [March 14, 2023, 7:26pm UTC](https://discourse.julialang.org/t/matrix-free-function-only-linear-solves/95411/6 "2023-03-14T19:26:08Z")

</div>

Thanks! LinearMaps.jl works very well for me!
