ODE 45 solution copying initial condition

조회 수: 1 (최근 30일)
Ji Hwan Park
Ji Hwan Park 2021년 5월 13일
댓글: Ji Hwan Park 2021년 5월 13일
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?

답변 (1개)

Steven Lord
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?
  댓글 수: 1
Ji Hwan Park
Ji Hwan Park 2021년 5월 13일
Evaluating as if like this:
vec = String(0, X0, M, K, N)
Then, it gives me 600 x 1 vector where 301th row has a value of -6.64283192090396 and 600th row has a value of -1.65381707574374.
By the way, Matrix M is a diagonal matrix with mass of string segment as its element, and K is shown below.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by