ODE 45 solution copying initial condition
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Steven Lord
2021년 5월 13일
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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!