# \[ANN\] PeriodicMatrices.jl - Handling of periodic time-varying matrices

**URL:** https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425
**Category:** Package Announcements
**Tags:** package, announcement, diffeq, symbolics, approxfun
**Created:** [January 4, 2025, 3:32pm UTC](https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425 "2025-01-04T15:32:51Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![andreasvarga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasvarga/32/11634_2.png) [@andreasvarga](https://discourse.julialang.org/u/andreasvarga)
#### Post date: [January 4, 2025, 3:32pm UTC](https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425/1 "2025-01-04T15:32:52Z")

</div>

[`PeriodicMatrices.jl`](https://github.com/andreasvarga/PeriodicMatrices.jl) provides the basic tools to handle periodic time-varying matrices. This package is the basis for developing the [`PeriodicMatrixEquations.jl`](https://github.com/andreasvarga/PeriodicMatrixEquations.jl) and [`PeriodicSystems.jl`](https://github.com/andreasvarga/PeriodicSystems.jl) packages.

For a real periodic matrix `A(t)` with period `T`, the dependence of the time variable `t` can be either continuous or discrete.

A continuous-time periodic matrix can be specified in one of the following forms:

- _periodic matrix function_, with `A(t)` a matrix function of the real variable `t ∈ [0, T)`;

- _periodic symbolic matrix_, with `A(t)` a symbolic matrix as defined in the [`Symbolics.jl`](https://github.com/JuliaSymbolics/Symbolics.jl) package depending on the (symbolic) real variable `t ∈ [0, T)`;

- _harmonic matrix series_, with `A(t)` defined as

- _periodic matrix time series with constant dimensions on a uniform time grid_;

- _periodic matrix time series with constant dimensions on a non-uniform time grid_;

- _Fourier matrix series approximation_, with `A(t)` a Fourier series representation (similar to the harmonic matrix series representation) as defined in the [`ApproxFun.jl`](https://github.com/JuliaApproximation/ApproxFun.jl) package.

A discrete-time periodic matrix can be specified in the following forms:

- _periodic matrix time series with time-varying dimensions on a uniform time grid_;

- _periodic matrix time series with time-varying dimensions on a non-uniform time grid_;

- _periodic matrix time series with constant dimensions on a uniform time grid_;

- _periodic matrix time series with constant dimensions on a non-uniform time grid_.

All possible conversions between the above representations are supported.  
The usage of the [`FFTW`](https://github.com/JuliaMath/FFTW.jl), [`Symbolics.jl`](https://github.com/JuliaSymbolics/Symbolics.jl), [`ApproxFun.jl`](https://github.com/JuliaApproximation/ApproxFun.jl) and [`Interpolations`](https://github.com/JuliaMath/Interpolations.jl) packages to implement some conversions is highly acknowledged.

Several operations on periodic matrices are implemented, such as, inversion, transposing, norms, derivative/time-shifting, trace. All operations with two periodic matrices such as addition/substraction, multiplication, horizontal/vertical concatenation, block-diagonal appending, allow different, but commensurate, periods.

Several advanced computational functions are provided to compute the characteristic multipliers and characteristic exponents of periodic matrices, using methods based on the periodic Schur decomposition of matrix products (provided in the [`SLICOT`](https://github.com/SLICOT/SLICOT-Reference/) library or in the [`PeriodicSchurDecompositions.jl`](https://github.com/RalphAS/PeriodicSchurDecompositions.jl) package) or structure exploitung fast algorithms requiring no external supporting packages. These functions are instrumental to apply [Floquet theory](https://en.wikipedia.org/wiki/Floquet_theory) to study the properties of solutions of various classes of differential equations (e.g., Mathieu, Hill, Meissner) and the stability of linear periodic systems (see [`PeriodicSystems.jl`](https://github.com/andreasvarga/PeriodicSystems.jl) package). The implementations of several functions rely on the high performance ODE solvers available in the [`OrdinaryDiffEq`](https://github.com/SciML/OrdinaryDiffEq.jl) and [`IRKGaussLegendre`](https://github.com/SciML/IRKGaussLegendre.jl) packages.

In developing this package I benefitted from the generous support of the Julia developers community, with special mention of @kellertuer, Ralph A. Smith, @ChrisRackauckas, [mikelehu](https://github.com/mikelehu), @mkitti, @dlfivefifty.

I am open to constructive critics and suggestions. I am aware of many possible improvements for this package, addressing issues such as, the reduction of the number of allocations, improvements of the definitions of periodic matrix objects, extension with new periodic matrix representations, better support of large periodic matrices, to mention a few of them.

---

<div class="post-metadata">

### Author: ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)
#### Post date: [January 6, 2025, 5:04pm UTC](https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425/2 "2025-01-06T17:04:32Z")

</div>

Congrats for making your work available to the community! Much appreciated.

Please apologize for being only poorly literate on periodic matrices.

I do, however, wonder how PeriodicMatrices.jl implements operations on truncated harmonic series. This curiosity stems from the fact that we wish to implement the same functionality for the project described at [GitHub - ziolai/sediment-transport-rivers](https://github.com/ziolai/sediment-transport-rivers) .

In particular, I imagine that the multiplication of periodic matrices results in higher order harmonics. A trial example is sin^2 (x) = 0.5 - 0.5 cos(2x). How does PeriodicMatrices.jl handle this case? Does the package truncate the new series or does it instead allow to store the higher harmonic as well?

Many thanks in advance for sharing your thoughts on this matter.

---

<div class="post-metadata">

### Author: ![andreasvarga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasvarga/32/11634_2.png) [@andreasvarga](https://discourse.julialang.org/u/andreasvarga)
#### Post date: [January 6, 2025, 9:17pm UTC](https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425/3 "2025-01-06T21:17:12Z")

</div>

Periodic matrices can be represented simply as function matrices or symbolic function matrices, in which cases there is no information stored about the used number of harmonics. However, the `HarmonicArray` representation stores all harmonic terms (packed in a complex 3-dimensional array) and yes, operations such as a product of two such matrices may change the number of harmonics.  
For your example, the result for squaring `sin^2(t)` is converted to a symbolic representation for better visualization:

```julia
using PeriodicMatrices
using Symbolics
A = PeriodicFunctionMatrix(t-> sin(t)^2,2pi) 
Ah = convert(HarmonicArray,A);
convert(PeriodicSymbolicMatrix,Ah*Ah)

```

and the result is:

`PeriodicSymbolicMatrix{:c, Num, Matrix{Num}}(Num[0.375 - 0.5cos(2.0t) + 0.125cos(4.0t);;], 6.283185307179586, 1)`

which is `0.375 - 0.5cos(2t) + 0.125cos(4t)`, as expected.  
So, no truncation is performed. Truncation can be however explicitly performed using the function `hrtrunc`.

---

<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: [January 6, 2025, 10:23pm UTC](https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425/4 "2025-01-06T22:23:30Z")

</div>

> [@Domenico\_Lahaye](#):
>
> I do, however, wonder how [PeriodicMatrices.jl](https://juliaregistries.github.io/General/packages/redirect_to_repo/PeriodicMatrices) implements operations on truncated harmonic series. This curiosity stems from the fact that we wish to implement the same functionality for the project described at [GitHub - ziolai/sediment-transport-rivers](https://github.com/ziolai/sediment-transport-rivers) .

Note that ApproxFun.jl also implements operations on [truncated Fourier series](https://juliaapproximation.github.io/ApproxFun.jl/stable/usage/spaces/#Fourier-and-Laurent-spaces) representations of periodic functions (along with several other spectral representations).

---

<div class="post-metadata">

### Author: ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)
#### Post date: [January 7, 2025, 7:24am UTC](https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425/5 "2025-01-07T07:24:03Z")

</div>

Sincere thx to both. Much appreciated.

---

<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: [January 9, 2025, 2:05pm UTC](https://discourse.julialang.org/t/ann-periodicmatrices-jl-handling-of-periodic-time-varying-matrices/124425/6 "2025-01-09T14:05:14Z")

</div>

A post was split to a new topic: [Truncated power series in ApproxFun.jl](https://discourse.julialang.org/t/truncated-power-series-in-approxfun-jl/124593)
