simulate dynamic response to a state space differential equation

2 次查看(过去 30 天)
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 个评论
Jerry Zhang
Jerry Zhang 2015-11-11
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!

请先登录,再进行评论。

采纳的回答

bio lim
bio lim 2015-11-11
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 个评论
bio lim
bio lim 2015-11-11
I see. Anyway, your entire expression could be simplified into a single one as shown above.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by