CodeCodeCode

ENGR132: HW05 - model_rocket_name

May 1st, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.50 KB | None | 0 0
  1. function [] = model_rocket_name(vel_ini, angle)
  2.  
  3. % FUNCTION: Calculates the height of the rocket and distance the
  4. % rocket travels for each second until it hits the water.
  5. %
  6. % INPUTS:
  7. % 1) vel_ini: The initial velocity of the rocket. (m/s)
  8. % 2) angle: The angle of the rocket. (degrees)
  9. %  
  10. % OUTPUTS:
  11. % Will print: The current height and distance at each second.
  12.  
  13. %Set G constant to 9.81 m/s^2
  14. G = 9.81;
  15. %Sets vertical distance (m) to 1.
  16. dist_v = 1;
  17. %Sets horizontal distance to 0.
  18. dist_h = 0;
  19. %Sets the current time (second) to 0
  20. time = 0;
  21.  
  22. %Loops until the vertical distance is less than 0 (rocket in the water);
  23. %loops while horizontal distance is 0 in order to continue loop upon
  24. %calculation with time 0 and loops while distance is more than 1 for all
  25. %regular calculations.
  26. while dist_h == 0 || dist_v > 1
  27.     %Calculates horizontal distance. (m)
  28.     dist_h = (vel_ini * cosd(angle)) * time;
  29.     %Calculates vertical distance. (m)
  30.     dist_v = (vel_ini * sind(angle)) * time - (0.5 * G * time^2);
  31.    
  32.     %If the vertical distance is less than 0, exit the loop; boundary set
  33.     %to less than 0 in order to print values if the horizontal
  34.     %distance has reached 0.
  35.     if dist_v < 0
  36.         break
  37.     %If above water, print values.
  38.     else
  39.         fprintf('At %d seconds, the height is %0.2f m and distance is %0.2f m\n',time,dist_v,dist_h);
  40.         %Increments time by 1.
  41.         time = time + 1;
  42.     end %If (break) end
  43. end %While end
  44.  
  45. % model_rocket_name(87,61)
  46. % At 0 seconds, the height is 0.00 m and distance is 0.00 m
  47. % At 1 seconds, the height is 71.19 m and distance is 42.18 m
  48. % At 2 seconds, the height is 132.56 m and distance is 84.36 m
  49. % At 3 seconds, the height is 184.13 m and distance is 126.54 m
  50. % At 4 seconds, the height is 225.89 m and distance is 168.71 m
  51. % At 5 seconds, the height is 257.83 m and distance is 210.89 m
  52. % At 6 seconds, the height is 279.97 m and distance is 253.07 m
  53. % At 7 seconds, the height is 292.30 m and distance is 295.25 m
  54. % At 8 seconds, the height is 294.82 m and distance is 337.43 m
  55. % At 9 seconds, the height is 287.52 m and distance is 379.61 m
  56. % At 10 seconds, the height is 270.42 m and distance is 421.78 m
  57. % At 11 seconds, the height is 243.51 m and distance is 463.96 m
  58. % At 12 seconds, the height is 206.78 m and distance is 506.14 m
  59. % At 13 seconds, the height is 160.25 m and distance is 548.32 m
  60. % At 14 seconds, the height is 103.91 m and distance is 590.50 m
  61. % At 15 seconds, the height is 37.75 m and distance is 632.68 m
Advertisement
Add Comment
Please, Sign In to add comment