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!