Manual Linear System Simulation - Matlab (Aka Lsim)
I Am Trying to Write the Lsim() Function from Matlab Manually to Avoid Having to Use the Control Library (Which Needs to Be Purchased). the Lsim() Function Is...
I am trying to write the lsim() function from Matlab manually to avoid having to use the control library (which needs to be purchased).
The lsim() function is quite straightforward and all the docs are available on Matlab to understand what it does. Nonetheless, I am multiplying by x5/10 the time it takes. You can find my code below, it is a for loop that iterates explicitly over each time step of the simulation.
I am certain there must be ways to speed this up but I am not too good at this. Maybe someone out here can help me out?
Thanks!
Marco
[~, x_size] = size(A);
xm = [];
xm(1,:) = zeros(1,x_size);
xm(2,:) = A*xm(1,:)' + B*u_kf(1,:)';
ym(1,:) = C*xm(1,:)' + D*u_kf(1,:)';
i = 1;
for tslsim = turbu.time
xm(i+1,:) = A*xm(i,:)' + B*u_kf(i,:)';
ym(i,:) = C*xm(i,:)' + D*u_kf(i,:)';
i = i + 1;
end
y = ym;
x = xm;