Getting the eigen spectrum of a large matrix (representing a microgrid)

Hello, I am really newb in Julia.
I am looking to see a solution for finding the eigenvalues (eigen spectrum) of a microgrid. The grid matriz is not that big (47x47).
I will be using some symbolic variables related to the control signals of the grid.
I was not able to get it work in Matlab (very painful).
At the end I want to plot the real and imaginary parts of the eigen values as one of the control signals changes.
Can it be done in Julia?

Welcome to the discourse :slight_smile:
Generally eigen decompositions with symbolic variables are very difficult for matrices larger than 4x4 since closed form expressions might not exist.
Maybe you have some favorable structure in your matrix that makes it possible but you’ll have to exploit that yourself. What I am saying is: What you ask might just be mathematically impossible no matter the language. Maybe we can provide better insights if you can share how your matrix is constructed.

Usually what you do is just construct a lot of matrices and diagonalize them :slight_smile: Since they are so small this not a problem at all. Diagonalization of a 50x50 matrix takes less than 1ms on my laptop.

1 Like

Thank ou for your kind reply!
I can share with you of course the work, it is based on the paper:
“Modeling, Analysis and Testing of Autonomous Operation of an Inverter-Based Microgrid” .
I have constructed the matrices in Matlab. Mabe a work around is to put the matrix construction code in a loop and vary the input control signals then plot the results.

As @abraemer already said, you don’t really want to compute eigenvalues of a matrix containing symbolic variables. Instead

So ideally you should build the matrix once without the changing control signal (e.g. by exporting a big excel table to CSV and loading that once, or by writing a julia function). Then you need some function

function adjust_control(mat0, control)
res = copy(mat0)
#here you plug in the control signal, whereever it belongs
res[17, 3] = control
res[23, 5] = im + pi * control
res

And then you can compute your stuff. For example, you could plot

c -> LinearAlgebra.eigvals(adjust_control(mat0, c))

…However: you will notice in the plotted output a certain non-smoothness. This is due to the sorting of eigenvalues, as per

help?> LinearAlgebra.eigen
...
By default, the eigenvalues and vectors are sorted lexicographically by (real(λ),imag(λ)).
...

Take a quick look at e.g. matrix - Tracking Eigenvalues Through a Crossing - Mathematica Stack Exchange to see plots with the issue.

You probably really want to track “the same” eigenvalue, even if it is leading (largest real part) for some control values, and non-leading for others.

This more bifurcation theory – maybe the BifurcationKit.jl people can help you. (don’t follow the stackoverflow article and homebrew, there exists lots of theory and algorithms designed for this problem, but I can’t remember that right now)

2 Likes

Thank you very much!
I will look into it