ODE 45 solution copying initial condition
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to solve second order ODE equation:
Mx'' = -Kx (where M and K are mass and stiffness matrices that are 300 x 300)
X0 = [x0; xdot0]; (each x0 and xdot0 are 300 x 1 vector) (X0: 600 x 1 vector)
f = @(t, x) String(t, x, M, K, N);
function dydt = String(t, X, M, K, N)
x1 = X(1:N);
x2 = X(N+1:end);
dydt1 = x2;
dydt2 = M \ (-K*x1)
% A = -K.*x1;
% A = sum(A, 2);
% dydt2 = M\A;
dydt = [dydt1
dydt2];
end
tSpan = linspace(0 100, 1000)
[~,X] = ode45(f, tSpan, X0);
Issue that I am facing is I am not sure why rows of X are filled with the initial condition X0.
Given function String and using ode45 method, shouldn't it solve the ode and fill the rows with the soltuion accordingly?
Is there any key parts that I am missing?
0 comentarios
Respuestas (1)
Steven Lord
el 13 de Mayo de 2021
Rather than handling M yourself in your ODE function consider specifying it as the Mass option using odeset. See this documentation example for how to use a mass matrix.
What happens if you evaluate your ODE function String (which you may want to rename to avoid potential confusion) with the first element of your tspan vector, 0, as the t input and your initial condition vector as the x input? Are all the elements of the output either 0 or very, very small?
1 comentario
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!