Is there a typo in the documentation for n4sid?

3 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Anjaneyulu Bairi
Anjaneyulu Bairi il 11 Gen 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 Commenti
Alex
Alex il 13 Gen 2025
I am leaving this open in the hopes it is seen by matlab support.
Steven Lord
Steven Lord il 13 Gen 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.]

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by