Home > Net >  how to replace the ode45 method with the runge-kutta in this matlab?
how to replace the ode45 method with the runge-kutta in this matlab?

Time:05-14

I tried everything and looked everywhere but can't find any solution for my question.

clc
clear all 


%% Solving the Ordinary Differential Equation 
G = 6.67408e-11; %Gravitational constant 
M = 10; %Mass of the fixed object 
r = 1; %Distance between the objects 

tspan = [0 100000]; %Time Progression from 0 to 100000s 
conditions = [1;0]; %y0= 1m apart, v0=0 m/s

F=@(t,y)var_r(y,G,M,r);

[t,y]=ode45(F,tspan,conditions); %ODE solver algorithm

%%part1: Plotting the Graph 
% plot(t,y(:,1)); %Plotting the Graph 
% xlabel('time (s)') 
% ylabel('distance (m)')

%% part2: Animation of Results 
plot(0,0,'b.','MarkerSize', 40); 
hold on    %to keep the first graph 
for i=1:length(t) 
k = plot(y(i,1),0,'r.','MarkerSize', 12); 
pause(0.05); 
axis([-1 2 -2 2])            
  • Related