Problem using ode23, must return a column vector.

8 visualizaciones (últimos 30 días)
Nino Dragicevic
Nino Dragicevic el 1 de Jul. de 2021
Comentada: Star Strider el 2 de Jul. de 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];
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 comentario
Matt J
Matt J el 1 de Jul. de 2021
It doesn't sound like you've actually checked whether racsimsemODE is returning a column vector...

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 1 de Jul. de 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 comentarios
Nino Dragicevic
Nino Dragicevic el 2 de Jul. de 2021
Thanks alot, you just saved my semester!
Star Strider
Star Strider el 2 de Jul. de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by