3. An artillery officer needs to determine the angle at which to aim the cannon
ID: 3168103 • Letter: 3
Question
3. An artillery officer needs to determine the angle at which to aim the cannon to a target d meters away. He knows that the cannonball will leave the muzzle of the gun at an initial speed of vo m/s. Neglecting air resistance, the only force acting on the cannonball is then gravity, which imparts a downward acceleration of g = 9.8m/s2 The desired is a solution to the nonlinear equation 2 sin cos Given that to = 126 m/s and d = 1200 m. (a) Use Newton's method to find a proper to within 2 decimal places. As an initial guess, use 0-/6 (b) Use Secant method to find a proper to within 2 decimal places. As initial guesses, use 0 and ,-/6 present your results in the form of the following table Iteration 1 | | error ei where error is defined as e,-0,-1Explanation / Answer
a)
%%% Matlab code %%%%%%%%
clc;
clear all;
close all;
format short
%%% restoredefaultpath %%%
syms x;
v0=126;
g=9.8;
d=1200;
f=sin(2*x)*v0^2/g-d;
%%% Newton raphson method
s(1)=pi/6; %%% initial guess
tol=10^(-2);
disp(' Iteration Roots error ');
for n=1:50;
l1=subs(f,s(n));
l2=subs(diff(f),s(n));
s(n+1)=s(n)-l1/l2;
err(n)=abs(s(n+1)-s(n));
fprintf(' %d %f %f ',n,s(n+1),err(n));
if err(n) < tol
break;
end
end
OUTPUT:
Iteration Roots error
1 0.398314 0.125285
2 0.416721 0.018407
3 0.417086 0.000365
b)
%%%% Matlab code %%%%%%%
v0=126;
g=9.8;
d=1200;
f=@(x) sin(2*x)*v0^2/g-d;
% %%% Secant method
y(1)=0;
y(2)=pi/6;
tol=0.01;
disp(' Iteration Roots error ');
for n=2:4
f1=feval(f,y(n));
f2=feval(f,y(n-1));
y(n+1)=y(n)-f1*(y(n)-y(n-1))/(f1-f2);
err=abs(y(n+1)-y(n));
fprintf(' %d %f %f ',n,y(n+1),err);
if ( err < tol)
break;
end
end
OUTPUT:
Iteration Roots error
1 0.447852 0.075747
2 0.412445 0.035407
3 0.417251 0.004806
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.