필터 지우기
필터 지우기

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