Matlab code for calculating characteristics equation

I have the code below to obtain the characteristic equation of a 6by6 matrix but it giving me an error of sym
% Define a symbolic 6x6 matrix with entries as a mixture of alphabet letters and zeros
syms a b c d e f g h i j k l m n p q r s t I v w x y z
A = [-a 0 b -c d e; f -g 0 0 h 0; 0 0 -i c 0 e; 0 0 j -k 0 0; 0 0 0 l -m 0; 0 0 0 n 0 -p];
% Calculate the characteristic polynomial of the matrix A
char_eqn = charpoly(A);
disp('The characteristic equation of the matrix A is:')
disp(char_eqn)

 Risposta accettata

Hi Sunday,
The error you're encountering is likely due to the fact that you haven't initialized the symbolic variables correctly or are using them incorrectly. In MATLAB, you need to ensure that all the variables used in the matrix are defined as symbolic. Here's how you can define a symbolic matrix and calculate its characteristic polynomial:
% Define symbolic variables
syms a b c d e f g h i j k l m n p
% Define the 6x6 matrix
A = [-a 0 b -c d e;
f -g 0 0 h 0;
0 0 -i c 0 e;
0 0 j -k 0 0;
0 0 0 l -m 0;
0 0 0 n 0 -p];
% Calculate the characteristic polynomial of the matrix A
char_eqn = charpoly(A);
% Display the characteristic equation
disp('The characteristic equation of the matrix A is:')
The characteristic equation of the matrix A is:
disp(char_eqn)
Key Points:
  • Ensure all variables used in the matrix are defined as symbolic using syms.
  • The charpoly function is used to compute the characteristic polynomial of the matrix.
  • The disp function is used to display the result.
This should resolve the error and correctly compute the characteristic equation of the matrix.

3 Commenti

Sunday
Sunday il 23 Ago 2024
Spostato: Walter Roberson il 23 Ago 2024

The characteristic equation of the matrix A is: [ 1, a + g + i + k + m + p, a*g - c*j + i*k + i*m + k*m + i*p + k*p + m*p + (a + g)*(i + k + m + p), (a + g)*(i*k - c*j + i*m + k*m + i*p + k*p + m*p) + a*g*(i + k + m + p) - c*j*m - c*j*p - e*j*n + i*k*m + i*k*p + i*m*p + k*m*p, (a + g)*(i*k*m - c*j*p - e*j*n - c*j*m + i*k*p + i*m*p + k*m*p) + a*g*(i*k - c*j + i*m + k*m + i*p + k*p + m*p) - c*j*m*p - e*j*m*n + i*k*m*p, a*g*(i*k*m - c*j*p - e*j*n - c*j*m + i*k*p + i*m*p + k*m*p) - (a + g)*(c*j*m*p + e*j*m*n - i*k*m*p), -a*g*(c*j*m*p + e*j*m*n - i*k*m*p)]

>> About is what I got after running the code. Too ambiguous to interpret

You failed to specify which variable you wanted the characteristic polynomial with respect to.
I think "charpoly" simply computes the coefficients of characteristic polynomial of the matrix A, doesn't it ?

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2007b

Richiesto:

il 22 Ago 2024

Commentato:

il 23 Ago 2024

Community Treasure Hunt

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

Start Hunting!

Translated by