Repository navigation
Expand file tree
/
Copy pathfailure_rate_plot.m
More file actions
54 lines (40 loc) · 1.57 KB
/
Copy pathfailure_rate_plot.m
File metadata and controls
54 lines (40 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
clear
clc
orbit_params.m_sun = 1;
orbit_params.m_planet = 1;
orbit_params.G = 40;
% eccentric orbit initial condition
V0 = [8; 0; 0; 1];
% orbital period from Kepler's third law, simulate three periods
mu = orbit_params.G*orbit_params.m_sun;
E = 0.5*norm(V0(3:4))^2 - mu/norm(V0(1:2));
a_orbit = -mu/(2*E);
T = 2*pi*sqrt(a_orbit^3/mu);
tspan = [0, 3*T];
rate_func = @(t,V) gravity_rate_func(t,V,orbit_params);
Bogacki.A = [0,0,0,0; 1/2,0,0,0; 0,3/4,0,0; 2/9,1/3,4/9,0];
Bogacki.B = [2/9,1/3,4/9,0; 7/24,1/4,1/3,1/8];
Bogacki.C = [0; 1/2; 3/4; 1];
p = 3;
error_desireds = logspace(-9,-2,15);
fail_rates = zeros(length(error_desireds),1);
step_sizes = zeros(length(error_desireds),1);
for j = 1:length(error_desireds)
[~,~,h_avg,~,fail_rate] = explicit_RK_variable_step_integration(rate_func,tspan,V0,0.1,Bogacki,p,error_desireds(j));
fail_rates(j) = fail_rate;
step_sizes(j) = h_avg;
end
figure('Color','w','Position',[100 100 1100 650])
loglog(step_sizes,fail_rates,'o','Color',lines(1),'MarkerFaceColor',lines(1),'MarkerSize',8,'LineWidth',1.5)
grid on
box on
set(gca,'FontSize',16,'TickLabelInterpreter','latex')
title('Step Failure Rate vs. Average Step Size, Bogacki-Shampine 3(2)','Interpreter','latex','FontSize',22)
xlabel('Average step size, $h_{avg}$','Interpreter','latex','FontSize',20)
ylabel('Step failure rate','Interpreter','latex','FontSize',20)
exportgraphics(gcf,'failure_rate_plot.png','Resolution',300)
function dVdt = gravity_rate_func(t,V,orbit_params)
r = V(1:2);
mu = orbit_params.G*orbit_params.m_sun;
dVdt = [V(3:4); -mu*r/norm(r)^3];
end