# Polar decomposition of a matrix

**URL:** <https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830>\
**Category:** General Usage\
**Tags:** linearalgebra\
**Created:** [October 22, 2020, 4:55pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830 "2020-10-22T16:55:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![danuzco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danuzco/32/18740_2.png) [@danuzco](https://discourse.julialang.org/u/danuzco)\
**Post date:** [October 22, 2020, 4:55pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/1 "2020-10-22T16:55:23Z")

</div>

I need to compute polar decomposition (PD) of matrices [https://en.wikipedia.org/wiki/Polar\_decomposition](https://en.wikipedia.org/wiki/Polar_decomposition). I tried to install this package [https://github.com/weijianzhang/PolarFact.jl](https://github.com/weijianzhang/PolarFact.jl), but I’m getting this error:

> ERROR: The following package names could not be resolved:
> 
> - PolarFact (not found in project, manifest or registry)

I tried with this approach [https://stackoverflow.com/questions/53198762/adding-a-package-in-julia-error-the-following-package-names-could-not-be-resolv](https://stackoverflow.com/questions/53198762/adding-a-package-in-julia-error-the-following-package-names-could-not-be-resolv), but it’s not working.

Is there another package available to compute PD or any way to install PolarFact?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [October 23, 2020, 6:23am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/3 "2020-10-23T06:23:28Z")

</div>

That package was written for Julia 0.4. It would need to be updated to be compatible with Julia 1.x.

Do you need all of the algorithms from that package? If you’re happy with just the SVD approach, you could implement the formula from the Wikipedia article in about two lines of Julia.

---

<div class="post-metadata">

**Author:** ![danuzco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danuzco/32/18740_2.png) [@danuzco](https://discourse.julialang.org/u/danuzco)\
**Post date:** [October 23, 2020, 2:21pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/4 "2020-10-23T14:21:47Z")

</div>

Thanks for your answer. Yes, I’ve been using the SVD, but it makes the entire program too slow. So, I was expecting PolarFact to compute it much faster. Shouldn’t I expect to find a faster way of computing the PD?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 23, 2020, 2:28pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/5 "2020-10-23T14:28:12Z")

</div>

The package appears to use a qr factorization which is about 2x faster than svd. Would that be enough to make it fast enough?

---

<div class="post-metadata">

**Author:** ![danuzco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danuzco/32/18740_2.png) [@danuzco](https://discourse.julialang.org/u/danuzco)\
**Post date:** [October 23, 2020, 2:31pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/6 "2020-10-23T14:31:50Z")

</div>

Thanks for you comment.

“The package appears to use a qr factorization”

You mean PolarFact?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 23, 2020, 2:32pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/7 "2020-10-23T14:32:06Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![danuzco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danuzco/32/18740_2.png) [@danuzco](https://discourse.julialang.org/u/danuzco)\
**Post date:** [October 23, 2020, 2:33pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/8 "2020-10-23T14:33:57Z")

</div>

Maybe that would help, I’d have to implement the code and see.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [October 24, 2020, 2:58am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/9 "2020-10-24T02:58:59Z")

</div>

I submitted a PR to update PolarFact to Julia 1.x. You can clone the PR branch to try the other algorithms if you like.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 24, 2020, 3:11am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/10 "2020-10-24T03:11:44Z")

</div>

Nice PR! Hopefully the maintainer is around to merge it.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 24, 2020, 3:13am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/11 "2020-10-24T03:13:46Z")

</div>

> [@Ralph\_Smith](#):
>
> PolarFact

[weijianzhang (Weijian Zhang) · GitHub](https://github.com/weijianzhang) looks like a no to me

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 24, 2020, 3:55am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/12 "2020-10-24T03:55:50Z")

</div>

Maybe time to fork the repo then?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 24, 2020, 4:01am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/13 "2020-10-24T04:01:08Z")

</div>

And rename it to `PolarFactorization.jl`

EDIT: Or `PolarDecomposition.jl`

Or add it to one of the existing linear algebra packages, like `GenericLinearAlgebra.jl`

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 24, 2020, 4:03am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/14 "2020-10-24T04:03:02Z")

</div>

Also might be a good idea to do some benchmarking to find the best algorithm, and delete the rest.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [October 24, 2020, 7:34am UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/15 "2020-10-24T07:34:12Z")

</div>

You could add it to MatrixFactorizations.jl

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [October 24, 2020, 1:41pm UTC](https://discourse.julialang.org/t/polar-decomposition-of-a-matrix/48830/16 "2020-10-24T13:41:49Z")

</div>

It’s not as simple as one algorithm being “the best”. It will depend on matrix size, sparsity structure, and how close it is to being unitary.
