Problem using ode23, must return a column vector.

8 views (last 30 days)
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 Comment
Matt J
Matt J on 1 Jul 2021
It doesn't sound like you've actually checked whether racsimsemODE is returning a column vector...

Sign in to comment.

Accepted Answer

Star Strider
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

Sign in to comment.

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!