I am not sure if I am supposed to be using linspace or not to ensure that vectors are the same length.
Vectors must be the same length is the error I cannot figure out. Here is the code(A picture is also provided that looks much more readable)
CODE STARTS BELOW:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
clc
clear
close all
k = input('Enter the value of gain k = '); % (gain k = 9 is given in the que.)
wn = input('Enter the value of natural Frequency wn = '); % (natural frequency wn = 3 is given in the que)
% step response & pole plot for zeta = 3
zeta = 3;
num = [k*wn^2];
den = [1 6*zeta wn^2];
sys = tf(num,den);
%[y,t] = step(sys);
k= 9;
s= 0.1:0.1:2;
w= 3;
tiledlayout(1,2);
ax1 = nexttile;
ax2 = nexttile;
for i = 1:length(s)
y = stepResponse(k, s(i), w);
t = 0:0.05:6;
plot(ax1, t, y)
xlabel (ax1, 'Time (sec)'); ylabel(ax1, 'Amplitude');
title(ax1, 'Step Reponse');
all_roots = getPoles(k, s(i), w);
plot (ax2, all_roots(:, 1), all_roots(:, 2), 'o');
xlabel (ax2, 'Real Part'); ylabel(ax2, 'Imaginary Part');
title(ax2, 'Pole Locations in Complex Plane');
hold(ax2, 'on');
pause(0.25);
end
function y=stepResponse(a, b, c)
y=step(a, b, c);
end

 채택된 답변

VBBV
VBBV 2021년 4월 6일

0 개 추천

%if true
t = linspace(0,6,length(s));%0:0.05:6;
What is size of variable s in workspace ?

댓글 수: 7

VBBV
VBBV 2021년 4월 6일
Put the above code line outside of for loop
s= 0.1:0.1:2;
That is what s is defined to be. Is that what you are looking for? or the amount of elements in the array in s?
I am getting the same error. Although this does point me in the right direction so thank you!
VBBV
VBBV 2021년 4월 7일
편집: VBBV 2021년 4월 7일
The variables s and t are not of same size. They don't have same number of elements. Therefore y output of stepresponse is also different
VBBV
VBBV 2021년 4월 7일
편집: VBBV 2021년 4월 7일
Inside the loop modify the following lines of code
%if true
y(i) = stepResponse(k, s(i), w);
plot(ax1,t(1:i),y(1:i))
And change the defintion of variable t to
%f true
t = linspace(0,6,length(s));%0:0.05:6;
Error: Unable to perform assignment bc the indices on the left are not compatible with the size of the right side.
Did i place the code in the correct place? (2 pics below showing different placements of the code you provided). I get the same error in both cases.
I also tried doing this placement incase I misunderstood you:
I really appreciate the help. I just had a professor yell at me today for not remembering something he mentioned 11 weeks ago. Although it still isnt working yet, you gave me hope :)
%f
y = stepResponse(k, s(i), w);
K(i) = y;
plot(ax1,t(1:i),K(1:i))
Ok. In that case output of stepresponse is singular value. So, you can try above

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2021년 4월 6일

댓글:

2021년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by