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

2 visualizaciones (últimos 30 días)
Mj
Mj el 10 de Nov. de 2020
Comentada: Mj el 10 de Nov. de 2020
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

Respuestas (1)

Mathieu NOE
Mathieu NOE el 10 de Nov. de 2020
hello
attached a zip for fixed time steps ODE solvers - compare with your own implementation
  4 comentarios
Mj
Mj el 10 de Nov. de 2020
thanks. but i dont want to use ode45 function. i want to solve this by rung kutta method.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by