hw11problem3

# hw11problem3 - Distance Calculation h = v*sin(Theta_rad*t...

This preview shows page 1. Sign up to view the full content.

%This script prompts the user for an initial velocity and angle. The %script then calculates the portion of the velocity that is vertical, and %reports the height of the projectile every second until the projectile %returns to the ground. % ---- Input Section ---- V = input('Please enter an initial velocity (m/s): '); Theta = input('Please enter an angle from the horizontal (degrees): '); h = 0; % initial height is 0 t = 0; % initial time is 0 grav = 9.81; %Gravity (m/s) % ---- Calculations & Output Section ---- Theta_rad = Theta*pi/180; %Convert degrees to radians for (h > 0) % While the projectile is in the air d = v*cos(Theta_rad)*t;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % Distance Calculation h = v*sin(Theta_rad)*t - 0.5*grav*t^2; % Height Calculation fprintf('%i seconds, the height is %5.2f m and distance is %5.2f m \n',t,h,d); end % Line #: 17 % Error: using a for loop structure as an indefinite loop % Fix: change for to while % Line #: 17 % Error: the conditional statement is always false % Fix: change to h >= 0 % Line #: 7, 19/20 % Error: the user inputs a value for V, lines 19 and 20 reference v % Fix: change line 7 to v or lines 19/20 to V % Line #: 17-24 % Error: currently an infinite loop % Fix: add a counter to line 23 t = t + 1...
View Full Document

## This note was uploaded on 02/12/2012 for the course ENGR 126 taught by Professor Oakes during the Fall '08 term at Purdue.

Ask a homework question - tutors are online