필터 지우기
필터 지우기

why lsim return empty states?

조회 수: 1 (최근 30일)
Mahmoud Elzouka
Mahmoud Elzouka 2023년 7월 28일
댓글: Paul 2023년 7월 28일
I have build a sparse state space system, and solved using lsim. According to the documentation, the third output represent the state trajectory.
When I run this example, the third output is empty.
Is there anything wrong I am doing? how can I get the states with time?
Thanks!
% inputs defining sparse state space system size
N_inputs = 41;
N_outputs = 240;
N_states = 2400;
N_time_steps = 10;
% defining the sparse state space system
G = sprand(N_states, N_states, 0.01);
B = sprand(N_states, N_inputs, 0.01);
E = sprand(N_outputs, N_states, 0.01);
D = 0;
C = sprand(N_states, N_states, 0.01);
sys = sparss(G, B, E, D, C);
% solving
t = linspace(0,1,N_time_steps);
[y,tOut,x] = lsim( ...
sys, ...
rand(N_inputs, length(t)), ...
t);
% check the size of each output
disp(size(y))
10 240
disp(size(tOut))
10 1
disp(size(x)) % why this is empty? how can I force lsim to return it?
0 0

채택된 답변

Paul
Paul 2023년 7월 28일
편집: Paul 2023년 7월 28일
According to the lsim doc page, the output x is returned when the input sys is a state-space model. The doc page further distinguishes between the input sys being a sparss model and an ss model. So I think that state trajectories are just returned as empty for sparss input. You can also see a comment that says exactly this if you drill down far enough into lsim in the debugger.
dbtype(fullfile(matlabroot,'toolbox/shared/controllib/engine/+ltipack/@spssdata/lsim.m'),'1:8')
1 function [y,x] = lsim(D,u,t,x0,~) 2 % Linear response simulation of state-space model with real coefficients. 3 % RE: Assume U is Ns x Nu and T has Ns samples. 4 5 % Author: P. Gahinet 6 % Copyright 2020 The MathWorks, Inc. 7 [ny,nu] = iosize(D); 8 x = []; % never compute X for sparse
In theory, at least, we can augment the output equation to include the states.
rng(100)
N_inputs = 41;
N_outputs = 240;
N_states = 2400;
N_time_steps = 10;
% defining the sparse state space system
G = sprand(N_states, N_states, 0.01);
B = sprand(N_states, N_inputs, 0.01);
E = sprand(N_outputs, N_states, 0.01);
D = 0;
C = sprand(N_states, N_states, 0.01);
% augment
E = [E; sparse(eye(N_states))];
sys = sparss(G, B, E, D, C);
% solving
t = linspace(0,1,N_time_steps);
[y,tOut,x] = lsim( ...
sys, ...
rand(N_inputs, length(t)), ...
t);
% collect states and outputs
x = y(:,N_outputs+1:end);
y = y(:,1:N_outputs);
size(y)
ans = 1×2
10 240
size(x)
ans = 1×2
10 2400
  댓글 수: 2
Mahmoud Elzouka
Mahmoud Elzouka 2023년 7월 28일
Thanks!
I wish matlab write in the docs at the output `x` that it will be empty is the system is sparse.
Paul
Paul 2023년 7월 28일
The doc could definitely be more clear in this regard. If you feel motivated, you can click on a star rating at the bottom of the doc page, after which I think that a window will pop-up where you can provide feedback to the doc writers.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse State-Space Models에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by