Most likely the culprits come from this part
and this part
u_dash = C*integral(@(tau) exp(A*(t-tau))*B.*u, 0, t) + D.*u;
Anyhow, this is what I would probably do to analyze the system in continuous-time domain.
Let's begin with your
function which can be simplified to
astf = minreal(tf(num, den))
astf =
1000 s + 10
-----------
s + 10
Continuous-time transfer function.
Note that the 1st-order transfer function
when converted to state-space form, it becomes
or
For some unknown reasons, since your P(s) transfer function is described by state-space
then we can combine both of them by first defining the state variables
,
,
and we have
.Thus, your original Q has to be modified to have the same size as the state matrix A, in order to determine the gain K from your icare() function
A = [0 1 0; -k/m -c/m 1/m; 0 0 -10];
B = [0; (1/m)*1000; -9990];
Q = [1 0 0; 0 1 0; 0 0 0];
fv2 = @(t, x, y, z) - (k/m)*x - (c/m)*y + (1/m)*z + (1/m)*1000*(- K(1)*x - K(2)*y - K(3)*z);
fv3 = @(t, x, y, z) - 10*z - 9990*(- K(1)*x - K(2)*y - K(3)*z);
opt = odeset('RelTol', 1e-4, 'AbsTol', 1e-6);
[t, v] = ode45(@(t, x) ([fv1(t, x(1), x(2), x(3)); fv2(t, x(1), x(2), x(3)); fv3(t, x(1), x(2), x(3))]), tspan, x0, opt);
plot(t, v(:,1:2), 'linewidth', 1.5)
xlabel({'$t$'}, 'Interpreter', 'latex')
ylabel({'$\mathbf{x}(t)$'}, 'Interpreter', 'latex')
legend({'$x(t)$', '$\dot{x}(t)$'}, 'Interpreter', 'latex', 'FontSize', 14)