フィルターのクリア

Matlab code not computing

3 ビュー (過去 30 日間)
lateef
lateef 2023 年 7 月 18 日
コメント済み: Image Analyst 2023 年 7 月 21 日
is anyone able to review my code and tell me why its not outputing correcrtly when i run it im not sure what errors i have
clear
p=-1;
z=-5;
K = 0.05:0.001:100;
a=K;
b=2*K.^2-p*K;
c=-z*K.^2;
root1 = (-b + sqrt(b.^2 - 4.*a.*c))./(2.*a);
root2 = (-b - sqrt(b.^2 - 4.*a.*c))./(2.*a);
root = root1;
K_corresponding = K;
decay_rate = real;
fprintf('The maximal imaginary part is: %f\n', max_imag_part);
fprintf('The corresponding value of K is: %f\n', K_corresponding);
fprintf('The decay rate is: %f\n', decay_rate);
figure
plot(real(root), imag(root));
scatter[real(root(max_index)], imag[root(max_index)], 'red'; 'filled');
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
xlabel('Real Part');
ylabel('Imaginary Part');
title('Root Locus Plot');
  2 件のコメント
Stephen23
Stephen23 2023 年 7 月 18 日
編集済み: Stephen23 2023 年 7 月 18 日
scatter[real(root(max_index)], imag[root(max_index)], 'red'; 'filled');
% ^ ^ should be parentheses
% ^ what is this for?
% ^ should be parenthesis, not square bracket
lateef
lateef 2023 年 7 月 18 日
even afiter put in paranthesis my code still computes an error
scatter((real(root(max_index)), imag(root(max_index)), 'red'; 'filled';
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
xlabel('Real Part');

サインインしてコメントする。

採用された回答

Alan Stevens
Alan Stevens 2023 年 7 月 18 日
The use of square brackets in the scatter function is not the only problem! Are you looking for something like this?
p=-1;
z=-5;
K = 0.05:0.001:100;
a=K;
b=2*K.^2-p*K;
c=-z*K.^2;
root1 = (-b + sqrt(b.^2 - 4.*a.*c))./(2.*a);
root2 = (-b - sqrt(b.^2 - 4.*a.*c))./(2.*a);
root = root1;
iroot = imag(root);
maximag = max(iroot);
max_index = find(iroot == maximag);
K_corresponding = K(max_index);
decay_rate = real(root(max_index));
fprintf('The maximal imaginary part is: %f\n',maximag);
The maximal imaginary part is: 1.936492
fprintf('The corresponding value of K is: %f\n', K_corresponding);
The corresponding value of K is: 2.000000
fprintf('The decay rate is: %f\n', decay_rate);
The decay rate is: -2.500000
figure
plot(real(root), imag(root));
hold on
scatter(real(root(max_index)), imag(root(max_index)), 'red', 'filled');
xlabel('Real Part');
ylabel('Imaginary Part');
title('Root Locus Plot');
  2 件のコメント
lateef
lateef 2023 年 7 月 18 日
yes thank you for the help
Image Analyst
Image Analyst 2023 年 7 月 21 日
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by