Effacer les filtres
Effacer les filtres

Matlab code not computing

2 vues (au cours des 30 derniers jours)
lateef
lateef le 18 Juil 2023
Commenté : Image Analyst le 21 Juil 2023
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 commentaires
Stephen23
Stephen23 le 18 Juil 2023
Modifié(e) : Stephen23 le 18 Juil 2023
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 le 18 Juil 2023
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');

Connectez-vous pour commenter.

Réponse acceptée

Alan Stevens
Alan Stevens le 18 Juil 2023
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 commentaires
lateef
lateef le 18 Juil 2023
yes thank you for the help
Image Analyst
Image Analyst le 21 Juil 2023
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.

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by