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

조회 수: 2 (최근 30일)
Abdullah Irfan
Abdullah Irfan 2019년 7월 23일
댓글: Abdullah Irfan 2019년 7월 24일
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:
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.
SharedScreenshot.png
SharedScreenshot1.png

답변 (1개)

Raj
Raj 2019년 7월 24일
"I want to write my simulink model into state space model" - Your simulink model is pretty straightforward and already in standard form:
xdot=Ax+Bu
y=Cx+Du
You have your A,B & C matrices. D is zero in your case. There is no need to use the MATLAB function block to complicate things. Just use the Simulink State Space block. Feed in the matrices and you are done!!
  댓글 수: 1
Abdullah Irfan
Abdullah Irfan 2019년 7월 24일
"There is no need to use the MATLAB function block to complicate things. Just use the Simulink State Space block. Feed in the matrices and you are done!!"
I was doing the same. But then I needed to transmit data serially and take data from the other device while this model is working.
I tried to use serial send/receive blocks but they were complicating the things, so my last resort is to convert block parameters into matlab code. I think real problem is integration block, I don't know which command replicates simulink integration block (integral, trapz and cumtrapz aren't those at least)

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

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by