# Backward substitution without memory allocation (Julia v0.6)

**URL:** <https://discourse.julialang.org/t/backward-substitution-without-memory-allocation-julia-v0-6/15060>\
**Category:** Performance\
**Created:** [September 17, 2018, 11:57am UTC](https://discourse.julialang.org/t/backward-substitution-without-memory-allocation-julia-v0-6/15060 "2018-09-17T11:57:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![migarstka](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/migarstka/32/3828_2.png) [@migarstka](https://discourse.julialang.org/u/migarstka)\
**Post date:** [September 17, 2018, 11:57am UTC](https://discourse.julialang.org/t/backward-substitution-without-memory-allocation-julia-v0-6/15060/1 "2018-09-17T11:57:39Z")

</div>

Let’s say I have a **sparse** positive semidefinite matrix that I want to factor using ldltfact and then solve a system of equations with changing right hand sides.

Is there any way to do this without allocating new memory for the solution at each iteration? I am looking for something like `A_ldiv_B!(sol,F,rhs)` where F can be a CHOLMOD factorization.

```julia

function solve(F,sol,rhs)
  sol[:] = F\rhs
end

function subsituteInLoop(F,n)
  sol = zeros(n)
  for iii = 1:5
    rhs = rand(n)
    @time solve(F,sol,rhs)
  end
end

# create random pos def matrix X
n = 100
X = sprand(n,n,0.3)
X = 0.5*(X'+X)
X = sparse(X + (-minimum(eigs(X)[1])+1)*eye(n))

# factor X

F = ldltfact(X)

subsituteInLoop(F,n)

```

Output:

```julia
  0.000041 seconds (9 allocations: 5.852 KiB)
  0.000024 seconds (9 allocations: 5.852 KiB)
  0.000017 seconds (9 allocations: 5.852 KiB)
  0.000017 seconds (9 allocations: 5.852 KiB)
  0.000015 seconds (9 allocations: 5.852 KiB)

```
