Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use matlab to answer this question The Project: You are asked to use an iterativ

ID: 3757318 • Letter: U

Question

Use matlab to answer this question

The Project: You are asked to use an iterative method to solve the following problem: You are manning an anti-aircraft gun with a muzzle velocity, Vm. An enemy aircraft is approaching on a horizontal path at a range R, an altitude H, and a speed of Vt. What should be the elevation, 0 (angle above the horizontal) of your gun to hit the target? The problem is illustrated in the figure below. Since the projectile is accelerating downward under the influence of gravity, it follows a parabolic path. The aircraft is assumed to be following a straight-line, horizontal path at constant speed. The trajectories of the projectile and the target will intersect at some point (x,y), provided that the launch angle is high enough. For a successful intercept, the projectile and target must reach the intercept point simultaneously.

Explanation / Answer

%clear command window
clc;

%clear workspace
clear all;

%close all figures
close all;

%Targets
T = (1:5);

%Range
R = [10000; 8000; 11000; 14000; 12500];

%Altitudes
H = [3000; 4000; 2500; 3500; 1750];

%Target Velocities
V = [250; 325; 225; 350; 275];

%Muzzle Velocity
Vm = 1000;

%Accelearation due to gravity
g = 9.8;

%Tolerance of iterative scheme (in degree)
tol = 0.01;

%Tolerance of iterative scheme (in radian)
rtol = pi*tol/180;

%Calculated theta values container
theta = zeros(size(T'));

%Colors of the plots
colors = 'kbgmr';

%Legends container of the plots
legends = cell(5, 1);

%Create figure and hold on so that all plots are in same figure
hold on;

%Loop over the set of targets
for k = T
Rt = R(k); %Target Range
Ht = H(k); %Target Altitude
Vt = V(k); %Target Velocity
C = Rt/(Vm+Vt); %Constant for calculation
  
%initial value of thetat (theta for target)
thetat = asin((Ht + 0.5*g*C^2)/(Vm*C));
  
%Steps of iterative scheme
steps = 0;
while(true)
%append next step
steps = [steps; steps(end)+1]; %#ok<AGROW>
  
%Constant for calculation
C = Rt/(Vm*cos(thetat(end))+Vt);
  
%append next theta for target
thetat = [thetat; asin((Ht + 0.5*g*C^2)/(Vm*C))]; %#ok<AGROW>
  
%Check theta for convergence
if(abs(thetat(end)-thetat(end-1))<rtol)
break;
end
end
%Theta to degree
thetat = 180*thetat/pi;
  
%Plots steps vs theta
plot(steps, thetat, ['-', colors(k), '*']);
  
%Store legend
legends(k) = {sprintf('Target %d', k)};
  
%Store theta
theta(k) = thetat(end);
end
%Apply legends
legend(legends,4);

filename = 'Table.txt';
%Open file for writing data
f = fopen(filename,'w');

%Write header
fprintf(f, 'Target Range(km) Altitude(km) Velocity(m/s) Launch Angle(%s) ',char(176));

%Write targets
for k = T
Rt = R(k);
Ht = H(k);
Vt = V(k);
fprintf(f, '%3d %9.2f %12.2f %13d %15.2f ',k,Rt/1000, Ht/1000, Vt, theta(k));
end

%Close (save) file
fclose(f);

%Read file
type(filename);