# Cholesky type and multiplication

**URL:** <https://discourse.julialang.org/t/cholesky-type-and-multiplication/15388>\
**Category:** New to Julia\
**Tags:** linearalgebra\
**Created:** [September 23, 2018, 4:49pm UTC](https://discourse.julialang.org/t/cholesky-type-and-multiplication/15388 "2018-09-23T16:49:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zymbuzz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zymbuzz/32/5482_2.png) [@zymbuzz](https://discourse.julialang.org/u/zymbuzz)\
**Post date:** [September 23, 2018, 4:49pm UTC](https://discourse.julialang.org/t/cholesky-type-and-multiplication/15388/1 "2018-09-23T16:49:39Z")

</div>

Hi,

I am lost why this operation does not work…  
u=[4. 0.; 0. 4.]  
cholesky(u)\*[1.;0.]

it seems it has to do that with the special matrix type of Cholesky. Should I transform this type back to normal matrix?

thanks a lot for your help.

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [September 23, 2018, 4:58pm UTC](https://discourse.julialang.org/t/cholesky-type-and-multiplication/15388/2 "2018-09-23T16:58:49Z")

</div>

```julia
u=[4. 0.; 0. 4.]
cholesky(u).U * [1.;0.] # Upper Triangular or F.L for lower triangular

```

---

<div class="post-metadata">

**Author:** ![zymbuzz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zymbuzz/32/5482_2.png) [@zymbuzz](https://discourse.julialang.org/u/zymbuzz)\
**Post date:** [September 23, 2018, 5:13pm UTC](https://discourse.julialang.org/t/cholesky-type-and-multiplication/15388/3 "2018-09-23T17:13:14Z")

</div>

thanks a lot! I assumed that cholesky(u) by default gives upper triangular

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 23, 2018, 7:31pm UTC](https://discourse.julialang.org/t/cholesky-type-and-multiplication/15388/4 "2018-09-23T19:31:18Z")

</div>

> [@zymbuzz](#):
>
> I assumed that `cholesky(u)` by default gives upper triangular

If it just gave an ordinary matrix, this would lose the information that it was a Cholesky factorization. By returning a special `Cholesky` type, it can be used in place of the original matrix for things like solving systems of equations `\`:

```julia
julia> A = rand(3,3); A = A'A # random SPD matrix
3×3 Array{Float64,2}:
 0.227769 0.306165 0.155967
 0.306165 1.00758 0.484895
 0.155967 0.484895 0.967645

julia> C = cholesky(A)
Cholesky{Float64,Array{Float64,2}}
U factor:
3×3 UpperTriangular{Float64,Array{Float64,2}}:
 0.477252 0.641517 0.326802
  ⋅ 0.772035 0.35652 
  ⋅ ⋅ 0.856586

julia> C \ [3,4,5] # solve Ax = [3,4,5]
3-element Array{Float64,1}:
 12.98633638730901  
 -1.9180590129375255
  4.035174666757661 

julia> A * ans
3-element Array{Float64,1}:
 2.9999999999999996
 4.0               
 5.000000000000001 

```
