How can I represent this state space in MATLAB Code?

% Code
A=[ 0 1 0 0 ;
0 0 -7sin(0.05) 0;
0 0 0 1;
0 0 0 -38;];
B=[ 0 0 0 71]';
c=[1 0 0 0];
f=ss(A,B,C,D);
close loop=feedback(f,1)
Is this representation of the state space with sine in it is true ?

 Accepted Answer

You need to replace 7sin(0.05) with 7*sin(0.05).
Also, Matlab variable names can't have a space in them so close loop is not a valid variable name.
And your definition of C was in lower case.
And you didn't define D;
A = [ 0 1 0 0 ;
0 0 -7*sin(0.05) 0;
0 0 0 1;
0 0 0 -38;];
B = [0 0 0 71]';
C = [1 0 0 0];
D = 0; % Assuming no direct effect of the input on the output
f=ss(A,B,C,D);
closed_loop=feedback(f,1)
closed_loop = A = x1 x2 x3 x4 x1 0 1 0 0 x2 0 0 -0.3499 0 x3 0 0 0 1 x4 -71 0 0 -38 B = u1 x1 0 x2 0 x3 0 x4 71 C = x1 x2 x3 x4 y1 1 0 0 0 D = u1 y1 0 Continuous-time state-space model.

8 Comments

Thank you very much, I want to sure, is that mean there is no problem in write sine in state space because x2dot =-7sin(0.05x3)?
Yes, -7*sin(0.05) is just a number, so it is perfectly valid as an element of a numeric matrix which is all that the A matrix in a linear time invariant state space model is.
-7*sin(0.05)
ans = -0.3499
Now, if you expect, as I think you are implying in this comment, x2dot to be -7*sin(0.05*x3), that is a different thing entirely. You can't express that non-linear relationship in a linear time invariant statespace model, xdot = A*x + B*u where A and B are constant numeric matrices of appropriate size, and x and u are the state vector and input vector, respectively.
You could simulate such a non-linear model in Simulink, however.
Ok, thank you very much
You are welcome.
I just noticed the .png file attached to your question. Was that always there?
Are you sure that is the correct model? I don't see the input u anywhere and x4 is repeated in your equation for x4dot. Is that supposed to be x4dot = -38*x4 + 71*u perhaps? That would be consistent with your B matrix.
Yes, sir. I made a mistake. X4dot==-38*x4+71*u. I still have problems. I must represent this system in Matlab code, not in Simulink, but I have no idea. How can I do that? Please, could you give me any ideas?
If you don't have Simulink, you should be able do this using ode45.
Look at the "Solve Nonstiff Equation" example on that doc page.
Also try Googling for "matlab ode45 system of equations" to find some examples in Matlab Answers of solving systems of equations using ode45.
I will try to do it by ode45. I am so grateful.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!