Regarding Loops and Control theory .

1 次查看(过去 30 天)
syms s
% Define the values of omega and zeta respectively
omega = [2 2 1 1];
zeta = [0 0.1 0 0.2];
t = 0:0.2:16;
for n = 1: size(zeta)
for m = 1: size(omega)
% Formula
num = tf( [0 0 omega(m)^2] );
den = tf( [ 1 2*omega(m)*zeta(n)*s omega(m)^2] );
% Impulse response of the system
y = impulse(num,den,t);
end
end
plot(t,y)
% The error that i am getting is
% Error using tf (line 299) In the "tf(M)" command, M must be a numeric array.

采纳的回答

Star Strider
Star Strider 2019-2-26
If you want to use ‘s’ in a control system definition, define it as:
s = tf('s');
then you can use it to define your transfer function.
This runs without error, however it does not give you any useful information:
% Define the values of omega and zeta respectively
omega = [2 2 1 1];
zeta = [0 0.1 0 0.2];
t = 0:0.2:16;
s = tf('s');
for n = 1: size(zeta,2)
for m = 1: size(omega,2)
% Impulse response of the system
H = tf([0 0 omega(m)^2], [ 1 2*omega(m).*zeta(n)*s omega(m)^2]);
y{m,n} = squeeze(impulse(H,t));
end
end
figure
hold all
for n = 1: size(zeta,2)
for m = 1: size(omega,2)
plot(t,y{m,n})
end
end
hold off
Using the size function is good, however the default is to return only the row size when you call it without outputs or with only one output. You want the number of elements in your ‘omega’ and ‘zeta’ vectors, and here that is the column size (the second dimension). I made your code a bit more efficient as well, eliminating the separate ‘num’ and ‘den’ assignments. Just put them into one tf call. The plot loop is at the end, however it simply shows a straight horizontal line at 0. Using a cell array for ‘y’ makes the coding easier.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by