You are on page 1of 5

# Uttara

Kumar
48009120
26/11/14

## EOSC 211 Assignment #3

Figure 3: Top subplot shows the percentage error in the closest approach altitude
as a function of 1/Time, bottom subplot shows percentage error vs. Time

We use the time stepping method to speed up things, all the while retaining the
accuracy needed. We know that the force and acceleration are proportional, since they
just differ by the constant mass, so both force and acceleration increase by 1/s2. We can
use a decrease in time of s2, which means that the time increments are smaller as the
distance to the planet decreases.

Uttara Kumar
48009120
26/11/14

## Figure 4: Contour Map showing closest approach altitude as a function of

Initial Position and Initial Velocity

sy0.txt
Initial y-position (km)
-7320
-14640
-29280
-58560
-117120
-234240
-468480
-936960
-1873920
-3747840

assign3c.m
clear; clc;

%parameters
totalt=1280*60;
massp=3.3*10^23;
atarget = 195*10^3;

## Closest Approach (km)

365
301
267
249
239
238
235
228
229
228

Uttara Kumar
48009120
26/11/14
v0=[0, 7*10^3];
deltat=60;

error = [];
delta = [];
percenterror = 100;
while percenterror > 2

%tic
% get array for acc, vel, and pos
[acc, vel, pos] = get_traj(s0, v0, deltat, totalt, massp, radiusp);
%toc
ca_alt = min(altitude)*1000;
percenterror = 100*(ca_alt-atarget)/atarget;
error = [error percenterror];
delta = [delta deltat];
deltat = deltat/2;
end

% plot error percentage against 1/deltat
figure(3); clf;
subplot(211);
plot(1./delta, error, '*-');
title('Percentage error in closest approach against per time increment');
xlabel('per time increment (per second)');
ylabel('Percentage error (%)');

subplot(212);
plot(delta, error, '*-');
text(6,10,sprintf('Final delta time is %.2fs', delta(end)));
title('Percentage error in closest approach against time increment');
xlabel('time increment (seconds)');
ylabel('Percentage error (%)');

get_traj.m

function [acc, vel, pos] = get_traj(s0, v0, deltat, totalt, massp, radiusp)

%get_traj calculates trajectory of the object that is in the middle of a fly-by. The function
shows 3 arrays acc, vel and pos. This is true if the initial position is not inside the
planet, and the object is flying towards the planet. Otherwise, an error message shows.

nt = totalt/deltat;
acc = nan(nt, 2);
vel = nan(nt, 2);
pos = nan(nt, 2);
instp = s0;
instv = v0;

Uttara Kumar
48009120
26/11/14

for i = 1:nt
instA = gravacc(instp, massp);
[deltap, deltav] = scvelpos(instA, instv, deltat);
instp = instp + deltap;
instv = instv + deltav;
acc(i,:) = instA;
vel(i,:) = instv;
pos(i,:) = instp;
end

%Functions
function [] = checkinit(s0, radiusp, v0)
px = s0(1);
py = s0(2);
sorigin = sqrt(px^2+py^2);
error('Initial position is inside the planet.');
elseif v0 <= 0;
error(Object is not moving towards the planet.');
end

function instA = gravacc(instp, massp)
G = 6.67*10^(-11);
px = instp(1);
py = instp(2);
sorigin = sqrt(px^2+py^2);
aM = (G*massp)/sorigin^2;

function [deltap, deltav] = scvelpos(instA, instv, deltat)
vx = instv(1);
vy = instv(2);
ax = instA(1);
ay = instA(2);

sinbeta = -px/sorigin;
cosbeta = -py/sorigin;
ax = aM*sinbeta;
ay = aM*cosbeta;
instA = [ax ay];

posdeltaX = vx*deltat + 0.5*ax*deltat^2;
posdeltaY = vy*deltat + 0.5*ay*deltat^2;
deltap = [posdeltaX posdeltaY];
veldeltaX = ax*deltat;
veldeltaY = ay*deltat;
deltav = [veldeltaX veldeltaY];

assign3d.m
clear; clc;

Uttara Kumar
48009120
26/11/14

v0=[0, 7*10^3];
atarget = 195*10^3;
massp=3.3*10^23;
totalt=1280*60;
deltat=5;

position = {};
xlabel = [];
ylabel = [];

for i = 1:9
v0(2)=4000+(i-1)*500;
ylabel = [ylabel v0(2)/1000];

for j = 1:4
s0(1) = -(radiusp + 4*atarget) + (j-1)*atarge
xlabel = [xlabel s0(1)/1000]
[acc, vel, pos] = get_traj(s0, v0,...
deltat, totalt,...
position{i,j} = pos;
end
end

ca_array = nan(size(position));
for i = 1:9
for j = 1:4
A = position{i,j};
end
end

figure(1); clf;
[c,h]=contour(ca_array, 0:25:500); hold on;
clabel(c,h);
[contour,altitude]=contour(ca_array, 195-25:5:195+25, '--'); hold on;
clabel(contour,170:25:220,'FontSize', 10);
set(gca,'XTickLabel',xlabel);
set(gca,'YTickLabel',ylabel);
title ('Contour Map of Flyby Parameters that were Successful);
xlabel('The Initial x-position in (km)');
ylabel('The Initial velocity in (km/s)');
grid on;

%Worked with Sarangadev Krishnan for ~5 hours