Vectors Must be same length. Do I use Linspace or ?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zack Hawkins
el 6 de Abr. de 2021
Comentada: VBBV
el 7 de Abr. de 2021
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 comentarios
Respuesta aceptada
VBBV
el 6 de Abr. de 2021
%if true
t = linspace(0,6,length(s));%0:0.05:6;
What is size of variable s in workspace ?
7 comentarios
VBBV
el 7 de Abr. de 2021
%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
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!