
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - expm() Function
The matrix exponential of a square matrix is calculated in SciPy using the expm(A) method. In differential equations and control theory, for example, this technique is essential for modeling systems that change over time. It offers a method for determining a matrix's exponential utilizing effective numerical techniques.
Even for non-diagonalizable matrices, expm(A) is effective, yielding reliable and precise results for a variety of uses. One of the most important methods for modeling systems in physics, economics, and engineering, it is essential for resolving time-dependent issues.
It is integrated with like scipy.integrate.solve_ivp for solving equations and controls theory for modeling time evaluation and system dynamics.
Syntax
Following is the syntax of the SciPy expm() method
.expm(A)
Parameters
This method accepts the following parameters −
A − A sqaure matrix of shape(n,n).
This method in SciPy doesn't accept any additional parameters directly. It is designed for the computation of the matrix exponential of a sqaure matrix A.
Return Value
The expm(A) returns a NumPy array, where it represents the matrix exponential of the input square matrix A.
Example 1
This is the basic example of expm() method demonstrates the simple use case when we compute matrix exponential of a 2x2 matrix.
In this example, we define a 2x2 matrix and use the `scipy.linalg.expm` function to compute its matrix exponential. After that, the outcomethe matrix exponential of `A`is printed.
from scipy.linalg import expm import numpy as np # Define a 2x2 matrix A = np.array([[0, 1], [-1, 0]]) # Compute the matrix exponential result = expm(A) #print the result print("Matrix A:") print(A) print("\nExponential of A (e^A):") print(result)
When we run above program, it produces following result
Matrix A: [[ 0 1] [-1 0]] Exponential of A (e^A): [[ 0.54030231 0.84147098] [-0.84147098 0.54030231]]
Example 2: Matrix Exponential of a Larger Matrix
This example demonstrates the use of the matrix exponential to solve a larger matrix.
In this example, we define a 3x3 matrix B and calculate its matrix exponential using the function scipy.linalg.expm. We then print the result which is the matrix exponential of B.
import numpy as np from scipy.linalg import expm # Define the matrix B B = np.array([[1, 2, 3], [0, 1, 4], [5, 6, 0]]) # Calculate the matrix exponential of B exp_B = expm(B) print("Matrix exponential of B:\n", exp_B)
When we run above program, it produces following result
Matrix exponential of B: [[333.93090511 506.07389874 416.91659677] [311.08568303 473.91946248 389.97643141] [487.47053927 740.50748863 609.7396169 ]]
Example 3: Matrix Exponential of a Diagonal matrix
This example demonstrates the use of the matrix exponential to solve a diagonal matrix.
In this example, we build a diagonal matrix `D` with diagonal elements `[1, 2, 3]` and use the `scipy.linalg.expm` function to compute its matrix exponential. The matrix exponential of `D`: is the result.
import numpy as np from scipy.linalg import expm # Define a diagonal matrix D = np.diag([1, 2, 3]) # Calculate the matrix exponential of the diagonal matrix exp_D = expm(D) print("Matrix Exponential of D:\n", exp_D)
Following is an output of the above code
Matrix Exponential of D: [[ 2.71828183 0. 0. ] [ 0. 7.3890561 0. ] [ 0. 0. 20.08553692]]