# Jordan form of a matrix

**URL:** <https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123>\
**Category:** Specific Domains\
**Tags:** linearalgebra\
**Created:** [November 17, 2017, 12:43pm UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123 "2017-11-17T12:43:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)\
**Post date:** [November 17, 2017, 12:43pm UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/1 "2017-11-17T12:43:02Z")

</div>

Is there an equivalent of Matlab’s [jordan](https://fr.mathworks.com/help/symbolic/jordan.html) function, to compute the Jordan canonical form of a matrix? I didn’t find it by tab-completion and in the julia observer didn’t find anything relevant. A version over exact rings would be fine.

---

<div class="post-metadata">

**Author:** ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)\
**Post date:** [November 17, 2017, 2:34pm UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/2 "2017-11-17T14:34:30Z")

</div>

`jordan_form` is available through [SymPy.jl](https://github.com/JuliaPy/SymPy.jl), eg. [in this example](https://github.com/JuliaPy/SymPy.jl/blob/e73bad67bc67e740b26f166808470b84554c03fb/test/test-matrix.jl#L111):

```julia
    M = Sym[ 6 5 -2 -3;
            -3 -1 3 3;
             2 1 -2 -3;
            -1 1 5 5]
    P, J = jordan_form(M)
    @test J == [2 1 0 0;
                0 2 0 0;
                0 0 2 1;
                0 0 0 2]
@test J == inv(P) * M * P

```

---

<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:** [November 17, 2017, 3:32pm UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/3 "2017-11-17T15:32:31Z")

</div>

As noted in the Matlab manual, a floating-point `jordan` function is nearly useless, because the tiniest roundoff errors will generally break up Jordan blocks (by breaking eigenvalue degeneracies). The built-in linear algebra functions in Julia are mostly focused on floating-point computations. Computing the Jordan form over finite fields is quite a different problem, and something like SymPy may be more appropriate for that.

(In numerical computation, it is rare to want the Jordan form precisely because it is so unstable. Sometimes you can use the Schur factorization instead. In some applications, you have a matrix that is _close_ to a defective matrix with a known Jordan form, e.g. close to a matrix with a 2x2 Jordan block, and in this case there are [efficient algorithms](https://arxiv.org/abs/1704.05837) to find the generalized eigenvectors of the “nearby” defective matrix.)

---

<div class="post-metadata">

**Author:** ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)\
**Post date:** [November 17, 2017, 4:24pm UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/4 "2017-11-17T16:24:13Z")

</div>

Thanks for the insights and the reference! I’ll have a look.

While reading your answer I remembered a passage on [Moler and Van Loan’s Nineteen dubious ways to compute the matrix exponential](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.92.5653&rep=rep1&type=pdf). In fact the kind of problem that i’m interested in is very much the one depicted in the “Method 18. Block Diagonal” (page 25): the aim is to do some sort of “interpolation” between the Jordan form and the Schur form. We thought – naively – computing with Julia both the Jordan form and a Schur form, then taking a linear combination of these, which minimizes some objective norm. Anyways, in that section some strategies are outlined, but i haven’t thought too much (yet) if this is something that can be readily done with existing functions in Julia, or it would require a lot of new development.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [November 18, 2017, 1:23am UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/5 "2017-11-18T01:23:40Z")

</div>

You could try using the [NORMFORM](http://www.reduce-algebra.com/manual/manualse132.html) package with [Reduce.jl](https://github.com/chakravala/Reduce.jl), which is a julia pkg I made to interface the Reduce computer algebra system within Julia, the NORMFORM package can be called from it.

```nohighlight
using Reduce
load_package(:normform)

```

If I have some time available, I might also create a built-in feature to interface the Jordan form into a julia function directly, there are still many opportunities for extended that pacakge.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [November 18, 2017, 1:49am UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/6 "2017-11-18T01:49:18Z")

</div>

Okay, so this feature does not quite work out of the box in Julia yet, since I have not implemented parsing of matrices through the Reduce pipe. However, I will consider this as my next task for moving forward.

```nohighlight
julia> using Reduce
Reduce (Free CSL version, revision 4015), 05-May-17 ...

julia> load_package(:normform)

reduce> A:=mat((1,y),(y^2,3));

     [1 y]
     []
a := [2]
     [y 3]

reduce> first jordansymbolic(A);

```

As of now, the matrix output is not properly detected and parsed yet, but this is a feature I will add in next.

Then you will be able to do Jordan form using this package as well (which is compatible with 0.7 unlike SymPy).

---

<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:** [November 19, 2017, 2:26am UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/7 "2017-11-19T02:26:48Z")

</div>

If you want to study the Jordan structure of dense matrices numerically, you might find a generalized nullspace analysis helpful. To that end, I packaged up an implementation [here](https://github.com/RalphAS/GeneralizedNullspaces.jl).

Note that I said “study the Jordan structure” (i.e. characterize the invariant subspaces of nearby matrices) and not “perform a Jordan decomposition”, since (as @stevengj indicated above), the latter is usually ill-advised in numerics.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [November 19, 2017, 5:36am UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/8 "2017-11-19T05:36:29Z")

</div>

Alright, so the symbolic matrix parsing is now implemented on the master branch,

```nohighlight
julia> :([1 y; y^2 1]) |> RExpr

[1 y]
[]
[2]
[y 1]

julia> ans |> parse
:([1 y; y ^ 2 1])

```

So the parser now handles matrices in both directions (from Reduce into Julia and from Julia into Reduce)

Now it is only a matter of making the NORMFORM package play nicely with the `Pipe`

---

<div class="post-metadata">

**Author:** ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)\
**Post date:** [November 19, 2017, 8:55am UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/9 "2017-11-19T08:55:34Z")

</div>

Thanks for the updates and your efforts to use Reduce’s functionality in Julia 🙂  
What is the `Pipe`?

---

<div class="post-metadata">

**Author:** ![mforets](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mforets/32/298_2.png) [@mforets](https://discourse.julialang.org/u/mforets)\
**Post date:** [November 19, 2017, 9:05am UTC](https://discourse.julialang.org/t/jordan-form-of-a-matrix/7123/10 "2017-11-19T09:05:02Z")

</div>

“Generalized Null Space Decomposition” – Okay, looking at your description in the README I’m excited about trying this out in our research problem; basically we have some control systems (LTI) and perform a set-based analysis in the state-space through _block decompositions_.

If you need more tests, I can send you some matrices or write test scripts (PS: we’ve been working with the [SLICOT benchmarks](http://slicot.org/20-site/126-benchmark-examples-for-model-reduction) models).
