Problem using ode23, must return a column vector.
8 views (last 30 days)
Show older comments
Nino Dragicevic
on 1 Jul 2021
Commented: Star Strider
on 2 Jul 2021
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 Comment
Matt J
on 1 Jul 2021
It doesn't sound like you've actually checked whether racsimsemODE is returning a column vector...
Accepted Answer
Star Strider
on 1 Jul 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
