# Banded matrix with ones in the lower triangular portion of the matrix

**URL:** <https://discourse.julialang.org/t/banded-matrix-with-ones-in-the-lower-triangular-portion-of-the-matrix/45591>\
**Category:** Numerics\
**Created:** [August 26, 2020, 7:49pm UTC](https://discourse.julialang.org/t/banded-matrix-with-ones-in-the-lower-triangular-portion-of-the-matrix/45591 "2020-08-26T19:49:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeynelson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joeynelson/32/16684_2.png) [@joeynelson](https://discourse.julialang.org/u/joeynelson)\
**Post date:** [August 26, 2020, 7:49pm UTC](https://discourse.julialang.org/t/banded-matrix-with-ones-in-the-lower-triangular-portion-of-the-matrix/45591/1 "2020-08-26T19:49:06Z")

</div>

I’m working on monotone spline fitting using an ispline basis. The matrix formed is similar to a banded matrix, but has all ones in the lower triangle portion below the banded portion. Additionally, I’m adding a constant column of all ones. Does anyone know of a package for more efficiently storing and working with this type of matrix, ideally one that will play nice with a non-negative-least-squares solver?

---

<div class="post-metadata">

**Author:** ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)\
**Post date:** [August 27, 2020, 8:02pm UTC](https://discourse.julialang.org/t/banded-matrix-with-ones-in-the-lower-triangular-portion-of-the-matrix/45591/2 "2020-08-27T20:02:55Z")

</div>

What do you need to do with the matrix? If all you need are matvecs and solves, then you could probably easily write a custom function for the multiplication that is efficient, and then use something like [IterativeSolvers.jl](https://juliamath.github.io/IterativeSolvers.jl/dev/getting_started/) to perform your solves with very little extra code. Something like this:

```julia
using IterativeSolvers 

struct MyMatrix
  B::(banded matrix object)
end

function lowertri_ones_apply(v)
  .... # easy to write in matrix-free form
end

function Base.:*(M::MyMatrix, v)
    M.B*v + lowertri_ones_apply(v)
end

function LinearAlgebra.mul!(M::MyMatrix, v)
  ... # should actually write THIS first, then make have * just make a copy and then call mul!.
end

eltype(M::MyMatrix) = ...

size(M::MyMatrix) = ...

function mysolve(M::MyMatrix, v; kwargs...)
  IterativeSolvers.gmres(M, v; kwargs...)
end

```

If you need more operations than that, maybe it isn’t so easy. But if those are the only operations you need, some custom approach like this would probably be pleasant and fast.
