필터 지우기
필터 지우기

simulate dynamic response to a state space differential equation

조회 수: 2 (최근 30일)
Jerry Zhang
Jerry Zhang 2015년 11월 11일
댓글: Jerry Zhang 2015년 11월 11일
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.
Jerry Zhang
Jerry Zhang 2015년 11월 11일
I got what I want! Thanks for your help!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by