# Problem in writing MATLAB code of Simulink model (state space)

#### abdullah8391

Joined Sep 6, 2015
80
Hi, I want to write my simulink model into state space model.
Pictures of my simulink model are attached. What I tried so far (and isn't working) is:

Code:
dt=0.01;
t=0:dt:10;
for i=1:length(t)
x=A*x+B*u;
u=(G*ref-K*x);
x = cumtrapz(x);
% fun = @(x) x;
% x = integral(fun,0,Inf);
pause;
end
But its results are way different than that of simulink model. Kindly guide me how should I do it.

#### Attachments

• 388.9 KB Views: 2
• 408.8 KB Views: 2
Last edited: