MATLAB: Multi-input state space solution using ODE45

control systemsode45state-space

I have the linear dynamics set up as follows:
function dx = sys(t,x)
global c m g r J
A = [0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 0 -g -c/m 0 0
0 0 0 0 -c/m 0
0 0 0 0 0 0];
B = [0 0
0 0
0 0
1/m 0
0 1/m
r/J 0];
K = [-3.1623 0.0000 20.1673 -4.7754 0.0000 4.4257
0.0000 3.1623 0.0000 0.0000 5.8914 0.0000];
u = K*x;
dx = A*x + B*u;
end
And the call to the solution:
global c m g r J
m = 4;
J = 0.0475;
r = 0.055;
g = 9.8;
c = 0.05;
tspan = [0 10];
iniCon = [-1; -1; 0; 0; 0; 0; 0; 0];
[t,y] = ode45(@(t,x) sys(t,x),tspan,iniCon);
plot(t,y)
When I run the solution I get an error saying that the inner dimensions of u = K*x do not match. Does anyone know where the mistake is?
Thanks

Best Answer

K is (2x6) and x is (8x1), thus K*x is not defined.
Best wishes
Torsten.