Vectors Must be same length. Do I use Linspace or ?
19 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!