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];
Unrecognized function or variable 'K1'.
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
Matt J 2021-7-1
It doesn't sound like you've actually checked whether racsimsemODE is returning a column vector...

请先登录,再进行评论。

采纳的回答

Star Strider
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 CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by