I think your question has been successfully solved out by me. I might not have sufficient time to wait for you to give me your mail address and send you quietly. Since your question is not included any key word to allow your school mates to find out, it should be safe to leave my solution over here.
You should note that I wrote a function file called sol4poly.m to calucation the initial dislocation of x and y in any valuable, including zero as your question suggests.
Please pay a special attention in the following sentense!
*/ My function code must be exactly the same name as "sol4poly.m" to get the code worked!!!! /*
"main.m"
clear all
% initial parameter
x0 = 0.0; % [m]
y0 = 0.0; % [m]
v0 = 20; % [m/s]
g = 9.81; % [m/s2]
j = 5:10:85;
cc = jet(length(j));
nu = 1;
xM = 0;
iM = 0;
for i = 0:1:90
theta = i/180*pi;
vx0 = v0*cos(theta); % [m/s]
vy0 = v0*sin(theta); % [m/s]
% time elapse
[t] = sol4poly(-.5*g,vy0,y0);
if ~isempty(t)
tx = 0:1E-4:t;
yh = y0+vy0*tx-.5*g*tx.^2;
xt = x0+vx0*tx;
if (i == j(nu))
plot(xt,yh,'color',cc(nu,:));
hold on, grid on;
nu = 1*(nuend
if (xt(length(tx)) > xM)
xM = xt(length(tx));
iM = i;
end
end
end
hold off;
legend({'5','15','25','35','45','55','65','75','85'},'FontSize',16)
fprintf('The maximum angle of prejection is %5.2f Deg\n', iM)
And the function code "sol4poly.m"
function [time] = sol4poly (a,b,c)
delta = b^2-4*a*c;
if (delta == 0 && a~=0)
time = -b/(2*a);
elseif (delta < 0)
time = [];
else
x1 = (-b+sqrt(delta))/(2*a);
x2 = (-b-sqrt(delta))/(2*a);
if (x1 > 0 && x2 <= 0)
time = x1;
elseif (x1 <= 0 && x2 > 0)
time = x2;
else
time = [];
end
end
end
The result is
The maximum angle of prejection is 45.00 Deg and the plotted graph is