インデックスが配列要​素数を超えています。​インデックスは 0 を超えてはなりません。

조회 수: 60 (최근 30일)
Masaaki Yanagihara
Masaaki Yanagihara 2024년 3월 28일
댓글: Dyuman Joshi 2024년 3월 28일
syms s
for kq = -10:1:10
eqnqroop = 1 + (kq*(-((4483*s^3)/5000 + (1915281*s^2)/5000000 - (551896897*s)/5000000000)/(s^4 + (52*s^3)/125 ...
+ (764541*s^2)/1000000 + (4137177603*s)/500000000 - 427810011/250000000))) == 0;
q1 = solve(eqnqroop,s); %%求解
kq
plot(real(q1(1)),imag(q1(1)),'-s','MarkerSize',5,'MarkerEdgeColor','red', 'MarkerFaceColor',[1 .6 .6])
hold on
end
kq = -10
kq = -9
kq = -8
kq = -7
kq = -6
kq = -5
kq = -4
kq = -3
kq = -2
kq = -1
kq = 0
Index exceeds the number of array elements. Index must not exceed 0.

Error in indexing (line 962)
R_tilde = builtin('subsref',L_tilde,Idx);
kqを-10~10まで1刻みで変えながら,eqnqroopという方程式の解を複素平面にプロットする,ということをしたいのですが,「インデックスが配列要素数を超えています。インデックスは 0 を超えてはなりません。」とでてきてしまい,-10~0までで計算がストップしてしまいます.
解決方法をご教授いただけると幸いです.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 3월 28일
편집: Dyuman Joshi 2024년 3월 28일
When kq is 0, the equation becomes 1==0, which is obviously not true, thus there is no solution for it. For that iteration, q1 is empty and you can't use indexing for it.
You can skip that value or plot a value manually for it. I have implemented the 1st option in my code below.
Note that the solve() returns the real solutions first if there are any. As the equation is a cubic polynomial in s, there will atleast be one real solution, so use the 2nd index for plotting.
syms s
figure
hold on
%Modify the loop indices to skip the value 0
for kq = setdiff(-10:10, 0)
eqnqroop = 1 + (kq*(-((4483*s^3)/5000 + (1915281*s^2)/5000000 - (551896897*s)/5000000000)/(s^4 + (52*s^3)/125 ...
+ (764541*s^2)/1000000 + (4137177603*s)/500000000 - 427810011/250000000))) == 0;
q1 = solve(eqnqroop,s);
%updated indexing
plot(real(q1(2)),imag(q1(2)),'-s','MarkerSize',5,'MarkerEdgeColor','red', 'MarkerFaceColor',[1 .6 .6])
end
  댓글 수: 2
Masaaki Yanagihara
Masaaki Yanagihara 2024년 3월 28일
ご回答ありがとうございます.
大変よくわかりました.
"Note"も有用で助かりました.
Dyuman Joshi
Dyuman Joshi 2024년 3월 28일
You're welcome!
If my answer solved your problem, please consider accepting the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 ビッグ データの処理에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!