Generate an iteration to determine the characteristic polynomial of several matrices
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Felipe Álvarez Acevedo
le 12 Mar 2021
Commenté : Walter Roberson
le 14 Mar 2021
Hello, I need a code that through the for will iteratively give me the characteristic polynomial of the 7 matrices that I have, the problem is that I want them to be called one at a time for each iteration, that is, in iteration 1, in the function poly between matrix A1, on iteration 2 in the poly function between matrix A2, and so on. For this reason, it occurred to me to put poly (Ai) because the number of each iteration is the same as the matrix that I need it to enter, but obviously matlab thinks that I am asking for the polynomial of the variable Ai. What can I do to solve my problem? Thanks in advance.
A1=[1 2; 2 1], A2=[1 -2; 2 1], A3=[2 1; 0 2]
A4=[2 2; 2 2], A5=[1 1 0; 0 -2 1; 0 0 2]
A6=[2 1 0; 1 2 0; 0 0 -1], A7=[2 0 0; 1 2 0; 0 0 -1]
for i=1:7
poly(Ai)
end
0 commentaires
Réponse acceptée
John D'Errico
le 12 Mar 2021
What can you do? Learn to use MATLAB properly.
Here, that means to learn to use matrices and arrays, especially cell arrays.
A={[1 2; 2 1], [1 -2; 2 1], [2 1; 0 2], [2 2; 2 2],...
[1 1 0; 0 -2 1; 0 0 2],[2 1 0; 1 2 0; 0 0 -1],[2 0 0; 1 2 0; 0 0 -1]};
A is a cell array. You index into A using curly braces. A has 7 elements.
for i=1:7
poly(A{i})
end
3 commentaires
John D'Errico
le 13 Mar 2021
I'm sorry. You want me to teach you to write some code that is far more poor, so that you can avoid having to learn MATLAB? In fact, no, you cannot simply create and index named arrays like that at all easily. And what you could do (code that I won't tell you how to write) would look far more nasty than simply creating a cell array.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!