Is there a typo in the documentation for n4sid?
조회 수: 2 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
채택된 답변
Anjaneyulu Bairi
2025년 1월 11일
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
Steven Lord
2025년 1월 13일
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.]
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!