Multi-input state space solution using ODE45

1 次查看(过去 30 天)
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

采纳的回答

Torsten
Torsten 2015-10-6
K is (2x6) and x is (8x1), thus K*x is not defined.
Best wishes
Torsten.
  2 个评论
savvas
savvas 2015-10-6
编辑:savvas 2015-10-6
I don't understand how x is defined. Can you elaborate?
Edit: Figured it out! Thanks a lot. The iniCon vector is defined wrong; (8x1) instead of (6x1).
Torsten
Torsten 2015-10-6
iniCon = [-1; -1; 0; 0; 0; 0; 0; 0];
Best wishes
Torsten.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by