Skip to content

Instantly share code, notes, and snippets.

@Eddy-Morgan
Last active March 3, 2024 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eddy-Morgan/51bdb566592a3bc0e386db1f8c50104b to your computer and use it in GitHub Desktop.
Save Eddy-Morgan/51bdb566592a3bc0e386db1f8c50104b to your computer and use it in GitHub Desktop.
symbolic expression for eigenvalues and eigenvectors of a system implemented in casadi
def qr_eigen(A, iterations=100):
pQ = SX.eye(A.size1())
X = copy.deepcopy(A)
for _ in range(iterations):
Q, R = qr(X) # QR decomposition in CasADi
pQ = pQ @ Q # Update eigenvector matrix for next iteration
X = R @ Q # Update eigenvalue matrix for next iteration
return diag(X), pQ
# example usage for a symbolic SX square matrix in casadi
w_sym , v_sym = qr_eigen(M, 100) # This get the symbolic eigenvalues and eigenvector expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment