Effacer les filtres
Effacer les filtres

simulate dynamic response to a state space differential equation

2 vues (au cours des 30 derniers jours)
Jerry Zhang
Jerry Zhang le 11 Nov 2015
Commenté : Jerry Zhang le 11 Nov 2015
Hi guys!
I am a beginner with MATLAB, forgive me for any stupid expression and this terrible formatting. I am trying to get a dynamic response for a state space differential equation in a matrix form: Xdot=A*x+B*u (A is 4by4, B is 4by2)
The input u is [1;0] between interval [0,1], and is 0 everywhere else. I have used a stupid way to construct my u, but I guess it should work. Here's the code I have:
A=[-2.6 0.25 -38 0; -0.075 -0.27 4.4 0; 0.078 -0.99 -0.23 0.052; 1.0 0.078 0 0];
B=[17 7; 0.82 -3.2; 0 0.046; 0 0];
w1=zeros(1,10000);
w3=zeros(1,10000);
w2=ones(1,10001);
t=-1:0.0001:2.000;
u1=[w1 w2 w3];
u2=zeros(1,30001);
u=[u1; u2];
lsim(sys1,u,t)
However, the plot seems to be u(1:) of t only, and I would like to get a response for x1, x2, x3, and x4.
I then tried the following code:
A=[-2.6 0.25 -38 0; -0.075 -0.27 4.4 0; 0.078 -0.99 -0.23 0.052; 1.0 0.078 0 0];
B=[17 7; 0.82 -3.2; 0 0.046; 0 0];
w1=zeros(1,10000);
w3=zeros(1,10000);
w2=ones(1,10001);
t=-1:0.0001:2.0001;
u1=[w1 w2 w3];
u2=zeros(1,30001);
u=[u1; u2];
x=zeros(4,30001);
for k=1:1:30001
x(:,k+1)=A*x(:,k)+B*u(:,k);
end
Then I have checked the values for x(:,10002) to x(:,11000) column by column, and found out that the values got too large that eventually MATLAB gave me NaN.
Is any of my approaches might work? Or either of them is correct...? Also, is there any more efficient way to solve this? Thanks!
  1 commentaire
Jerry Zhang
Jerry Zhang le 11 Nov 2015
I think I understand what I want to ask....
Its a stupid question. I should set C=[1 0 0 1; 0 1 0 0; 0 0 1 0; 0 0 0 1] to output all 4 variables I want. Method one is obviously more efficient.
@coffee Murun Thanks for your help!

Connectez-vous pour commenter.

Réponse acceptée

bio lim
bio lim le 11 Nov 2015
How about defining your input like this.
u = [t <= 1 & t >= 0; zeros(size(t));];
I also have few comments.
  • I don't understand why you would start your system with a 'negative' time. Why not simply start with 0?
  • Your input, u, as you defined is u = [w1, w2, w3]. However, the size of your w2 is different than the other two, which doesn't make much sense to me.
  3 commentaires
bio lim
bio lim le 11 Nov 2015
I see. Anyway, your entire expression could be simplified into a single one as shown above.
Jerry Zhang
Jerry Zhang le 11 Nov 2015
I got what I want! Thanks for your help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming 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!

Translated by