# How to change the tolerance of the QRPivoted method

**URL:** https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753
**Category:** Performance
**Tags:** package, optimization, qr
**Created:** [November 19, 2021, 12:39am UTC](https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753 "2021-11-19T00:39:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![valperez](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@valperez](https://discourse.julialang.org/u/valperez)
#### Post date: [November 19, 2021, 12:39am UTC](https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753/1 "2021-11-19T00:39:39Z")

</div>

Hi there 🙂

I’m using the LinearAlgebra package in Julia to use the QRPivoted method. The documentation is not very clear about the use of the tolerance. I want to use que qr pivoted function on a matrix A but I want to be able to change the tolerance.  
To use the qr pivoted function, the documentation says to do the following:

```julia
qr(A, Val(false)) which actually works once you do it in Julia for any matrix A

```

However, the only mention of tolerance in the documentation is  
qr(A::SparseMatrixCSC; tol=\_default\_tol(A), ordering=ORDERING\_DEFAULT)

I don’t know how to use it in Julia because I have tried  
qr(A, 10e-10, ordering = false) and  
qr(A, 10e-10)

and nothing works. Can anyone help with that?  
I would like to do something like  
qr(A, Val(false), 10e-10) to make a QRPivoted matrix with a tolerance of the method of 10e-10.

It should work on any matrix A so feel free to use any one you want.

Thanks in advanced

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [November 19, 2021, 10:29am UTC](https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753/2 "2021-11-19T10:29:42Z")

</div>

I would try `qr(A, tol=10e-10)`.

---

<div class="post-metadata">

### Author: ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)
#### Post date: [November 19, 2021, 12:41pm UTC](https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753/3 "2021-11-19T12:41:13Z")

</div>

`tol` is _keyword argument_ which is set by calling `qr(A, tol=1e-10)` as @goerch indicated. The clue for this in the documentation is the semicolon in

```julia
qr(A::SparseMatrixCSC; tol=_default_tol(A), ordering=ORDERING_DEFAULT)

```

For the function def `f(x, y, z; a=default1, b=default2)`, the arguments `x,y,z` before the semicolon are required and specified by order. The arguments `a` and `b` come with default values and can be set in any order or left to default values, but you need to name them when calling, as in `f(1,2,3, a="foo")` or `f(1,2,3, b="bar", a="foo").`

[Julia Doc: Keyword Arguments](https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments)

By the way, `10e-10` is a literal for 10 \times 10^{-10} = 10^{-9}. If what you want is 10^{-10}, enter it as `1e-10`. Just guessing here!

---

<div class="post-metadata">

### Author: ![valperez](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@valperez](https://discourse.julialang.org/u/valperez)
#### Post date: [November 19, 2021, 4:45pm UTC](https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753/4 "2021-11-19T16:45:19Z")

</div>

No, I have tried that and it doesn’t work.

---

<div class="post-metadata">

### Author: ![valperez](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@valperez](https://discourse.julialang.org/u/valperez)
#### Post date: [November 19, 2021, 4:47pm UTC](https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753/5 "2021-11-19T16:47:21Z")

</div>

I have tried both F = qr(A; tol = 10e-10) and F = qr(A, Val(true); tol = 10e-10) and none of them work.

---

<div class="post-metadata">

### Author: ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)
#### Post date: [November 19, 2021, 6:08pm UTC](https://discourse.julialang.org/t/how-to-change-the-tolerance-of-the-qrpivoted-method/71753/6 "2021-11-19T18:08:19Z")

</div>

Here’s a minimal working example that works (julia-1.6.0)

```julia
julia> using LinearAlgebra, SparseArrays

julia> i = [1,1,2,2,3,3,4,4]; 

julia> j = [1,2,2,3,3,4,4,2];

julia> v = [1.0,2.0,-5.0,3.0,-1.0,2.0,-2.0,4.0];

julia> A = sparse(i,j,v)
4×4 SparseMatrixCSC{Float64, Int64} with 8 stored entries:
 1.0 2.0 ⋅ ⋅ 
  ⋅ -5.0 3.0 ⋅ 
  ⋅ ⋅ -1.0 2.0
  ⋅ 4.0 ⋅ -2.0

julia> F = qr(A, tol=1-08)
SuiteSparse.SPQR.QRSparse{Float64, Int64}
Q factor:
4×4 SuiteSparse.SPQR.QRSparseQ{Float64, Int64}:
 1.0 0.0 0.0 0.0
 0.0 -0.780869 -0.551142 0.294086
 0.0 0.624695 -0.688927 0.367607
 0.0 0.0 0.470767 0.882258
R factor:
4×4 SparseMatrixCSC{Float64, Int64} with 8 stored entries:
 1.0 2.0 ⋅ ⋅ 
  ⋅ 6.40312 -2.34261 -1.24939
  ⋅ ⋅ -2.12419 2.31939
  ⋅ ⋅ ⋅ 1.0293
Row permutation:
4-element Vector{Int64}:
 1
 2
 4
 3
Column permutation:
4-element Vector{Int64}:
 1
 2
 3
 4
julia>

```
