# How to plot state space variables against time on unit step input?

I have a system defined in state space model with the following matrices

A =

$$\begin{matrix} 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ -1280 & -254 & -26 & 3400 \\ -1 & 0 & 0 & 0 \\ \end{matrix}$$

B =

$$\begin{matrix} 0 \\ 0 \\ 1 \\ 0 \\ \end{matrix}$$

C = $$\begin{matrix} 1 & 0 & 0 & 0 \\ \end{matrix}$$

D= 0

As you see I have 4 state variables , I want to plot them against time with step input in matlab.

• The simplest way would be to run a simulation. – Eugene Sh. May 24 '17 at 19:11
• @EugeneSh. Sorry but can you elaborate more ? – Shady Atef May 24 '17 at 19:12
• You have the initial state. You have the state-space equation. These two are giving you the momentary change in the state (it's time derivative at time 0). You multiply it by time step and add to the current state to obtain the next one. The smaller time steps, the more accurate it is. – Eugene Sh. May 24 '17 at 19:15

Looks like matlab step function can already do that

I have solved it using the following equations:

[y,t,x] = step(ss_model,1) % X here will have trajectories for the
x1 = [ 1 0 0 0]*x';
x2 = [ 0 1 0 0]*x';
x3 = [ 0 0 1 0]*x';
x4 = [ 0 0 0 1]*x';


There is a better way:

close all; clear all; clc;

A = [0 1 0 0; 0 0 1 0; -1280 -254 -26 3400; -1 0 0 0];
B = [0;0;1;0];
C = [1 0 0 0];
D = ;

sys = ss(A,B,C,D);
[y,t,x] = step(sys);
plot(t,x);
legend('x1','x2','x3','x4');