
- 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 - fiedler_companion() Function
The scipy.linalg.fiedler_companion() function builds a Fiedler companion matrix from an one-dimensional array or sequence. It creates a structured matrix which has off-diagonal members representing sums of vector entries and diagonal members representing the vector's negative sum. Such matrices are very useful in polynomial analysis and matrix factorization.
Errors can arise in cases where input is not a 1D array or sequence or is of length zero; the computation gets quite complicated. If the size of input vectors is big, potentially uses more memory and reduces speed.
Fiedler companion matrix is extensively applied with scipy.linalg.eig() for polynomial roots analysis and for analyzing stability in a system with scipy.linalg.lu() in order to speed up solutions for structured linear equations.
Syntax
The syntax for the SciPy fiedler_companion() method is as follows −
.fiedler_companion(a)
Parameters
This method accepts the following parameters −
a (array_like) − A 1D array or sequence that defines the Fiedler companion matrix.
Return Value
F (ndarray) − A square Fiedler companion matrix of shape (len(a)-1, len(a)-1), with structured diagonal and off-diagonal elements derived from the input vector.
Example 1
The Fiedler companion matrix yields a structured form where the non-zero entries are in a reduced form row by row.
This code demonstrates how one can create an Fiedler companion matrix using the input list a = [1, 2, 3] and passing it to the fiedler_companion() method. The matrix arranges its rows combining components in 'A', initiated with the input sequence and reducing the number of non-zero members in each successive row.
import scipy.linalg from scipy.linalg import fiedler_companion # Input array A = [1, 2, 3] # Generate the Fiedler companion matrix matrix = scipy.linalg.fiedler_companion(A) print("Fiedler Companion Matrix:") print(matrix)
When we run above program, it produces following result
Fiedler Companion Matrix: [[-2. -3.] [ 1. 0.]]
Example 2
This code demonstrates how to use the Fiedler companion matrix to calculate roots of a polynomial. The input a = [1, -6, 11, -6] consists of coefficients for the polynomial x^3 - 6x^2 + 11x - 6 = 0. Using the coefficients, the fiedler_companion() method builds a matrix, and, using scipy.linalg.eigvals(), the eigenvalues calculated are the roots of the polynomial.
The output provides the Fiedler companion matrix and its eigenvalues, which correspond to polynomial roots. In this case, the roots are [3,2,1] and may imply that the polynomial can be factored as (x3)(x2)(x1)=0. It is useful for numerical approaches and applications that require the analysis of the roots of the polynomial.
from scipy.linalg import fiedler_companion, eigvals # Polynomial coefficients a = [1, -6, 11, -6] matrix = fiedler_companion(a) # Compute eigenvalues to find roots roots = eigvals(matrix) print("Fiedler Companion Matrix:") print(matrix) print("\nRoots of the Polynomial:") print(roots)
Following is an output of the above code
Fiedler Companion Matrix: [[ 6. -11. 1.] [ 1. 0. 0.] [ 0. 6. 0.]] Roots of the Polynomial: [3.+0.j 2.+0.j 1.+0.j]
Example 3
A larger input array, such as a = [1, 2, 3, 4, 5], produces a larger Fiedler companion matrix. The matrix's structure expands proportionally, with each row containing fewer non-zero elements than the previous row.
from scipy.linalg import fiedler_companion # Large input array a = [1, 2, 3, 4, 5] # Generate the Fiedler companion matrix matrix = fiedler_companion(a) print("Fiedler Companion Matrix:") print(matrix)
Output of the above code is as follows
Fiedler Companion Matrix: [[-2. -3. 1. 0.] [ 1. 0. 0. 0.] [ 0. -4. 0. -5.] [ 0. 1. 0. 0.]]