I have a function that inputs velocity and angle, and outputs the distance the ball travels. Function below:
function distance = DTask1_f (v, angle)h = 1.5;g = 9.8;t = linspace (0,10,1000);x=v*cos(angle*pi/180)*t;y=h+v*sin(angle*pi/180)*t-0.5*g*t.^2;ind = find (x == min(x(y<0)));fprintf ('The ball hits the ground at a distance of %5.4f meters.', x(ind));distance = x(ind);end
I now need to write a script that uses the function, and while using a set value for velocity, will graph angle and distance over a set of angles. My script so far:
for angle = 10:13 v = 4; y = DTask1_f (v, angle); x = [angle]; a = [x;y]endfigureplot(x,y)xlabel('Angle (deg)');ylabel('Distance (m)');title('Ball Trajectory');
I think I need to first make an array using the angle (input) and distance (output), and then graph the array, but im not sure how to make the array. At the moment, it only gives me the last two points.
Apologies if this is a simplistic question, but thanks for the help.
Best Answer