Effacer les filtres
Effacer les filtres

How can we achieve the scalar ^ Matrix functionality in python.

1 vue (au cours des 30 derniers jours)
Arslan Saif
Arslan Saif le 7 Jan 2023
Like I have code in matlab
dt=0.005
A=[ 0 1; -394510 -62.831];
Kb=real(exp(1)^(A*dt));
I convert it in python as
kb=np.real(np.exp(1)**(A*dt))
But output is completely diff, np.exp(1) and (A*dt) gives the same output as in matlab exp(1) and (A*dt) gives. But when it comes to taking exponent ans will be different. I also tried the eigen value way which matlab uses when it calculate the scalar ^ matrix but still different outputs.
Eigen value way in python:
eigenvalues, eigenvectors = np.linalg.eig(A)
# Raise the eigenvalues to the power of the scalar
eigenvalues_raised = np.exp(1)**eigenvalues
# Multiply the resulting matrix by the inverse of the eigenvectors
result = eigenvectors.dot(np.diag(eigenvalues_raised)).dot(np.linalg.inv(eigenvectors))

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Jan 2023
Déplacé(e) : Walter Roberson le 7 Jan 2023

Plus de réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by