フィルターのクリア

How do i fix my Runge Kutta (4th order) method to solve a 2nd order ODE?

1 回表示 (過去 30 日間)
Mj
Mj 2020 年 11 月 10 日
コメント済み: Mj 2020 年 11 月 10 日
Hi,
I have a code for a Runge Kutta 2th order analysis of a 2nd order ODE but it has not give me the right answer.
% d2a/dt2=(16*a^(1/2))/35 - 18/(35*a) - (6*a^3)/35
%initial condition: da/dt(x=-∞)=0 و a(x=0)=0.705
Here is my code below:
clear all
clc
h=0.2;
t=-2:h:0;
Nt=numel(t);
A=zeros(2,Nt);
A(:,1)=[0.705,0];
f = @(t, A) [A(2);(16*A(1).^(1./2))./35 - 18./(35.*A(1)) - (6.*A(1).^3)./35];
for i=1:Nt-1
k1 = h.*f(t(i), A(:,i));
k2 = h.*f(t(i) + 0.5.*h, A(:,i) + 0.5.*k1);
A(:,i+1) = A(:,i) + (1.0./6.0).*(k1 + 2.*k2 );
end
figure(1)
plot(t, A, '-o');
xlabel('x/hu')
ylabel('h/hu')
grid on

回答 (1 件)

Mathieu NOE
Mathieu NOE 2020 年 11 月 10 日
hello
attached a zip for fixed time steps ODE solvers - compare with your own implementation
  4 件のコメント
Mj
Mj 2020 年 11 月 10 日
thanks. but i dont want to use ode45 function. i want to solve this by rung kutta method.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by