How do i plot x1(t) and x2(t) from a state space model

Hi i think this is fairly easy to do but i am pretty new to boh matlab and system modelling so hopefully you guys can help me, I have constructed a state space model from a system consisting of two water tanks that are connected to each other, x1 is the water level in tank 1, x2 is the water level in tank 2. I want to plot x1 as a function of time as well as x2 as a function of time. My input signal is a step with a amplitude of 0.1, thank you in advance.
syms a g A h10 h20 opt;
a = 0.1;
A = 1;
h10 = 1;
h20 = 1;
g = 9.81;
Am = [-(a*(2*g)^(1/2))/(2*A*(h10^(1/2))) 0; (a*(2*g)^(1/2))/(2*A*(h10^(1/2))) -(a*(2*g)^(1/2))/(2*A*(h20^(1/2)))]
Bm = [1/A ; 0]
Cm = [1 0; 0 1; (a*(2*g)^(1/2))/(2*A*(h10^(1/2))) 0]
Dm = [0; 0; 0]
tank = ss(Am, Bm, Cm, Dm, 'Inputname', 'U', 'Outputname','q2', 'Statename',{'h1(t)', 'h2(t)'})
opt = stepDataOptions;
opt.StepAmplitude = 0.1;

Answers (1)

See this
a = 0.1;
A = 1;
h10 = 1;
h20 = 1;
g = 9.81;
Am = [-(a*(2*g)^(1/2))/(2*A*(h10^(1/2))) 0; (a*(2*g)^(1/2))/(2*A*(h10^(1/2))) -(a*(2*g)^(1/2))/(2*A*(h20^(1/2)))];
Bm = [1/A ; 0];
Cm = [1 0; 0 1; (a*(2*g)^(1/2))/(2*A*(h10^(1/2))) 0];
Dm = [0; 0; 0];
tank = ss(Am, Bm, Cm, Dm, 'Inputname', 'U', 'Outputname','q2', 'Statename',{'h1(t)', 'h2(t)'});
opt = stepDataOptions('StepAmplitude', 0.1);
step(tank, opt)
Note that your ss model have 3 outputs. First two are x1 and x2. The third is same as you defined in last row of Cm.

Categories

Find more on Control System Toolbox in Help Center and File Exchange

Products

Release

R2019a

Asked:

on 4 May 2020

Commented:

on 7 May 2020

Community Treasure Hunt

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

Start Hunting!