Is there a typo in the documentation for n4sid?

3 visualizaciones (últimos 30 días)
Alex
Alex el 11 de En. de 2025
Comentada: Steven Lord el 13 de En. de 2025
The documentation for n4sid contains the following code snippet. I believe the line u(k-1) = -K*y(k-2) + w(k); should read u(k-2) = -K*y(k-2) + w(k);.
N = 1000;
K = 0.5;
rng('default');
w = randn(N,1);
z = zeros(N,1);
u = zeros(N,1);
y = zeros(N,1);
e = randn(N,1);
v = filter([1 0.5],[1 1.5 0.7],e);
for k = 3:N
u(k-1) = -K*y(k-2) + w(k);
u(k-1) = -K*y(k-1) + w(k);
z(k) = 1.5*z(k-1) - 0.7*z(k-2) + u(k-1) + 0.5*u(k-2);
y(k) = z(k) + 0.8*v(k);
end
dat = iddata(y, u, 1);

Respuesta aceptada

Anjaneyulu Bairi
Anjaneyulu Bairi el 11 de En. de 2025
Hi,
The first line in for loop should not be u(k-1). It should be u(k-2).
Please use below code to generate close loop data.
N = 1000;
K = 0.5;
rng('default');
w = randn(N,1);
z = zeros(N,1);
u = zeros(N,1);
y = zeros(N,1);
e = randn(N,1);
v = filter([1 0.5],[1 1.5 0.7],e);
for k = 3:N
u(k-2) = -K*y(k-2) + w(k-2);
u(k-1) = -K*y(k-1) + w(k-1);
z(k) = 1.5*z(k-1) - 0.7*z(k-2) + u(k-1) + 0.5*u(k-2);
y(k) = z(k) + 0.8*v(k);
end
dat = iddata(y, u, 1);
Hope it helps!
  2 comentarios
Alex
Alex el 13 de En. de 2025
I am leaving this open in the hopes it is seen by matlab support.
Steven Lord
Steven Lord el 13 de En. de 2025
Please contact Technical Support directly using this link rather than simply waiting and hoping it is seen by Technical Support. [Yes, I am a MathWorks staff member. But no, I am not familiar with System Identification Toolbox and so cannot answer the question.]

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by