Problem in writing MATLAB code of Simulink model (state space)
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231035/SharedScreenshot.png)
![SharedScreenshot1.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231036/SharedScreenshot1.png)
Réponses (1)
Raj
le 24 Juil 2019
"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!!
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!