# LU Decomposition: MethodError: no method matching round(::Float64, ::Int64)

**URL:** <https://discourse.julialang.org/t/lu-decomposition-methoderror-no-method-matching-round-float64-int64/84710>\
**Category:** General Usage\
**Tags:** linearalgebra\
**Created:** [July 24, 2022, 12:46pm UTC](https://discourse.julialang.org/t/lu-decomposition-methoderror-no-method-matching-round-float64-int64/84710 "2022-07-24T12:46:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 24, 2022, 12:46pm UTC](https://discourse.julialang.org/t/lu-decomposition-methoderror-no-method-matching-round-float64-int64/84710/1 "2022-07-24T12:46:02Z")

</div>

Hi all,

I have read texts on Gauss-Elimination and LU Decomposition.  
[https://web.mit.edu/18.06/www/Spring17/Gaussian-elimination.pdf](https://web.mit.edu/18.06/www/Spring17/Gaussian-elimination.pdf)

The problem is when I try the function `visualize_gauss` it can’t work:

```julia
visualize_gauss(rand(-9:9,5,5))
visualize_gauss(Abad)

```

 ![Capture d’écran_2022-07-24_19-45-30](https://global.discourse-cdn.com/julialang/original/3X/6/f/6f93c82b59bd3b9cb145ef113f59e865790b21ad.png)

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [July 24, 2022, 3:26pm UTC](https://discourse.julialang.org/t/lu-decomposition-methoderror-no-method-matching-round-float64-int64/84710/2 "2022-07-24T15:26:48Z")

</div>

how about

```julia
rand(-9.0:9.0,5,5)

```

?

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [July 25, 2022, 5:26am UTC](https://discourse.julialang.org/t/lu-decomposition-methoderror-no-method-matching-round-float64-int64/84710/3 "2022-07-25T05:26:53Z")

</div>

> [@ctkelley](#):
>
> `rand(-9.0:9.0,5,5)`

Here are the codes (you need to create matrix A then)

```julia
"""
TwoMatrices is just a wrapper type around two matrices or vectors with the same
number of rows, so that they can be displayed side-by-side with a title and
and arrow pointing from left to right.
"""
type TwoMatrices
    left::AbstractVecOrMat
    right::AbstractVecOrMat
    title::AbstractString
    function TwoMatrices(left, right, title="")
        size(left,1) == size(right,1) || throw(DimensionMismatch("two matrices must have same # of columns and rows"))
        return new(left, right, title)
    end
end

function Base.show(io::IO, ::MIME"text/plain", x::TwoMatrices)
isempty(x.title) || println(io, x.title)
m = size(x.left, 1)
s = [Text(" "^10) for i in 1:m]
s[(m+1)÷2] = Text(" ---> ")
Base.showarray(io, [x.left s x.right], false; header=false)
end

```

```julia
"""
naive_gauss(A, [step])

Given a matrix ‘A‘, performs Gaussian elimination to convert
‘A‘ into an upper-triangular matrix ‘U‘.

This implementation is "naive" because it *never re-orders the rows*.
(It will obviously fail if a zero pivot is encountered.)

If the optional ‘step‘ argument is supplied, only performs ‘step‘
steps of Gaussian elimination.

Returns ‘(U, row, col, factor)‘, where ‘row‘ and ‘col‘ are the
row and column of the last step performed, while ‘factor‘
is the last factor multiplying the pivot row.
"""

function naive_gauss(A, step=typemax(Int))
        m = size(A,1) # number of rows
        factor = A[1,1]/A[1,1]
        step ≤ 0 && return (A, 1, 1, factor)
        U = copy!(similar(A, typeof(factor)), A)
        for j = 1:m # loop over m columns
            for i = j+1:m # loop over rows below the pivot row j
                # subtract a multiple of the pivot row (j)
                # from the current row (i) to cancel U[i,j] = U[U+1D62][U+2C7C]:
                factor = -U[i,j]/U[j,j]
                U[i,:] = U[i,:] + U[j,:] * factor
                step -= 1
                step ≤ 0 && return (U, i, j, factor)
        end
    end
    return U, m, m, factor
end

```

```julia
using Interact
# For display, I only want to show 3 decimal places of floating-point values,
# but I want to show integers and similar types exactly, so I define a little
# function to do this rounding

shorten(x::AbstractFloat) = round(x, 3)
shorten(x) = x # leave non floating-point values as-is

# create an interactive widget to visualize the Gaussian-elimination process for the matrix A.
function visualize_gauss(A)
    m = size(A, 1)
    @manipulate for step in slider(1:(m*(m-1))÷2, value=1, label="gauss step")
        Uprev, = naive_gauss(A, step-1)
        U, row, col, factor = naive_gauss(A, step)
        pivot = U[col,col]
        TwoMatrices(shorten.(Uprev), shorten.(U), "Gaussian elimination for column $col with pivot")
    end
end

```

```julia
visualize_gauss(rand(-9:9,5,5))

```

or

```julia
visualize_gauss(A)

```

anyone can see the illustration of Gaussian elimination / make it works?
