Problem using ode23, must return a column vector.
8 次查看(过去 30 天)
显示 更早的评论
Hi, im trying to simulate 2 mass MDS system step response using ode23.
this is my state space:
K1, K2, M1, M2, C1, C2 are all known constants
global A B u
A = [0, 1, 0, 0; (-K1-K2)/M1, (-C1-C2)/M1, K2/M1, C2/M1;
0, 0, 0, 1; K2/M2, C2/M2, -K2/M2, -C2/M2];
B = [0; 1/M1; 0; 0];
C = [1, 0, 0, 0; 0, 0, 1, 0];
D = [0; 0];
and this is my ode23 call:
T_end = 10;
u = [1,1,1,1]; %(1, because step response)
x0 = [0, 0, 0, 0]; %(initial conditions)
[t,y] = ode23('racsimsemODE',[0,T_end],x0)
and my ode23 function:
function [dy] = racsimsemODE(t,x)
global A B u
dy = A*x + B*u;
end
however, this doesent work and I dont know why...
1 个评论
Matt J
2021-7-1
It doesn't sound like you've actually checked whether racsimsemODE is returning a column vector...
采纳的回答
Star Strider
2021-7-1
Multiply ‘dy’ by an appropriate vector of ones and it works.
You need to determine if it produces the correct result.
% K1, K2, M1, M2, C1, C2 are all known constants
vv = num2cell(rand(6,1)); % Define Constants
[K1, K2, M1, M2, C1, C2] = vv{:}; % Assign Constants
A = [0, 1, 0, 0; (-K1-K2)/M1, (-C1-C2)/M1, K2/M1, C2/M1;
0, 0, 0, 1; K2/M2, C2/M2, -K2/M2, -C2/M2];
B = [0; 1/M1; 0; 0];
C = [1, 0, 0, 0; 0, 0, 1, 0];
D = [0; 0];
% and this is my ode23 call:
T_end = 10;
u = [1,1,1,1]; % (1, because step response)
x0 = [0, 0, 0, 0]; % (initial conditions)
[t,y] = ode23(@(t,x)racsimsemODE(t,x,A,B,u),[0,T_end],x0);
figure
plot(t,y)
grid
legend(compose('$x_{%d}$',1:4), 'Location','best', 'Interpreter','latex')
% and my ode23 function:
function [dy] = racsimsemODE(t,x,A,B,u)
dy = A*x + B*u;
dy = dy*ones(4,1);
end
.
6 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

