# Idempotent matrices in Julia

**URL:** https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467
**Category:** Teaching & Outreach
**Tags:** tutorials, matrices
**Created:** [June 9, 2022, 1:18am UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467 "2022-06-09T01:18:17Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![VinodV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinodv/32/32733_2.png) [@VinodV](https://discourse.julialang.org/u/VinodV)
#### Post date: [June 9, 2022, 1:18am UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/1 "2022-06-09T01:18:17Z")

</div>

Hi all,  
I have created a small blog post related to Idempotent matrices with Julia.  
[Idempotent matrices in Julia](https://pythonjulia.blogspot.com/2022/06/idempotent-matrices-in-julia.html)  
Please provide your feedback.

---

<div class="post-metadata">

### Author: ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)
#### Post date: [June 9, 2022, 6:17am UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/2 "2022-06-09T06:17:46Z")

</div>

You could show that rank(A)=tr(A)=4.

---

<div class="post-metadata">

### Author: ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)
#### Post date: [June 9, 2022, 7:06am UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/3 "2022-06-09T07:06:07Z")

</div>

Here is another direction: What if you wanted to have a rank 3 idempotent matrix? How would you find a vector `v` such that `u'*v = 0` so that we can make a `B` with rank(B) = 3 and `B^100 ≈ B`?

---

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [June 9, 2022, 7:17am UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/4 "2022-06-09T07:17:06Z")

</div>

Very nice. I like your 100 Julia Excercises too!

I feel the sentence

> Idempotent matrices behave like identity matrices when raised to a power n

is a bit misleading. They do only after being applied once.

I think your example demonstrates Julia’s natural math syntax nicely and if that’s all you want, then I say well done.

If you want to go a step further and showcase what Julia can do, you could define a `IdempotentMatrix<:AbstractMatrix` type and specialize all kinds of linear algebra on it. Most importantly of course matrix powers, but also eigenvalues, trace, determinant…  
I admit that I’ve thought about this for approximately five minutes, so maybe there is good reason not to 😃

---

<div class="post-metadata">

### Author: ![VinodV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinodv/32/32733_2.png) [@VinodV](https://discourse.julialang.org/u/VinodV)
#### Post date: [June 9, 2022, 2:39pm UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/5 "2022-06-09T14:39:57Z")

</div>

> [@skleinbo](#):
>
> Idempotent matrices behave like identity matrices when raised to a power n

What would be a correct sentence which will clearly show the behaviour of idempotent matrices when raised to a power?

---

<div class="post-metadata">

### Author: ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)
#### Post date: [June 9, 2022, 2:47pm UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/6 "2022-06-09T14:47:13Z")

</div>

I think `P^2 = P` explains it tbh.

---

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [June 9, 2022, 3:32pm UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/7 "2022-06-09T15:32:25Z")

</div>

I’m with @jacobusmmsmit in this. The definition is perfectly understandable. IMHO the sentence could be left out entirely.

---

<div class="post-metadata">

### Author: ![VinodV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinodv/32/32733_2.png) [@VinodV](https://discourse.julialang.org/u/VinodV)
#### Post date: [June 17, 2022, 4:06pm UTC](https://discourse.julialang.org/t/idempotent-matrices-in-julia/82467/8 "2022-06-17T16:06:31Z")

</div>

Cross posted to [Idempotent matrices in Julia - Julia Community 🟣](https://forem.julialang.org/vinodv/idempotent-matrices-in-julia-470o)
