hosseinniri
/
Simulation-of-State-Space-Models-of-Dynamical-Systems-in-Cpp--Eigen-Matrix-Library-Tutorial
Public
forked from AleksandarHaber/Simulation-of-State-Space-Models-of-Dynamical-Systems-in-Cpp--Eigen-Matrix-Library-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_matrices.m
More file actions
33 lines (27 loc) · 687 Bytes
/
Copy pathgenerate_matrices.m
File metadata and controls
33 lines (27 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
%csvwrite(filename,M)
clear,pack,clc
A=0.06*randn(100,100);
B=0.1*randn(100,10);
C=ones(10,100);
input=rand(10,1000);
x0=randn(100,1);
[m,sampleTime]=size(input);
[r,~]=size(C);
[n,~]=size(A)
MATLAB_state=zeros(n,sampleTime);
MATLAB_output=zeros(r,sampleTime);
for i=1:sampleTime
if i==1
MATLAB_state(:,i)=x0;
MATLAB_output(:,i)=C*x0;
else
MATLAB_state(:,i)=A*MATLAB_state(:,i-1)+B*input(:,i-1);
MATLAB_output(:,i)=C*MATLAB_state(:,i);
end
end
plot(MATLAB_output(1,:),'r')
csvwrite("AFile.csv",A)
csvwrite("BFile.csv",B)
csvwrite("CFile.csv",C)
csvwrite("x0File.csv",x0)
csvwrite("inputFile.csv",input);