Generate an iteration to determine the characteristic polynomial of several matrices
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
John D'Errico
2021년 3월 12일
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
John D'Errico
2021년 3월 13일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!