Advertisement
Guest User

Spaceship Flight

a guest
Feb 5th, 2021
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. clc; clear all; close all;
  2.  
  3. %%%%%%%%%%%%%%%%
  4. %% Initialize %%
  5. %%%%%%%%%%%%%%%%
  6.  
  7. ShipMass = 75000; % kg
  8. OrbDist = 2000000; % meters
  9. FuelDensity = 4500; % N*s/kg
  10. FuelRate = [500:20:8000]; % kg/s
  11. N = length(FuelRate);
  12. dt = 2; % seconds
  13. g = 9.8; % m/s^2
  14.  
  15. %%%%%%%%%%%%%%%%%%%%%%
  16. %%%% Calculations %%%%
  17. %%%%%%%%%%%%%%%%%%%%%%
  18.  
  19. for i=1:N
  20.  
  21. %%%%%%%%%%%%%%%%%%%
  22. %% Non-Constants %%
  23. %%%%%%%%%%%%%%%%%%%
  24.  
  25. FuelMass = 5000000; % kg
  26. Position = 0; % meters
  27. Velocity = 0; % m/s
  28. Acceleration = 0; % m/s^2
  29. G = 0; % N
  30. GForce(i) = 0; % Stores value each trajectory
  31. OrbitTime(i) = 0; % Stores value each trajectory
  32.  
  33. while Position < OrbDist
  34.  
  35. TotalMass = ShipMass + FuelMass;
  36. PropForce = FuelRate(i).*FuelDensity;
  37. Acceleration = PropForce./TotalMass;
  38. Velocity = Velocity + ((1/2).*Acceleration.*dt.^2);
  39. Position = Position + Velocity.*dt;
  40. G = Acceleration./g;
  41.  
  42. if G > GForce(i)
  43.  
  44. GForce(i) = G;
  45.  
  46. end
  47.  
  48. FuelMass = FuelMass - FuelRate(i).*dt;
  49. OrbitTime(i) = OrbitTime(i)+dt;
  50.  
  51. end
  52. end
  53.  
  54. OrbitTime = OrbitTime./60 % Change time from seconds to minutes
  55.  
  56. figure(1)
  57. plot (GForce, FuelRate, 'b') % Shows what the Fuel Rate would be at
  58. % different g-forces
  59.  
  60. figure(2)
  61. plot (OrbitTime, GForce, 'g') % Shows g-force based on time
  62. % until orbit
  63.  
  64. figure(3)
  65. plot (OrbitTime,FuelRate, 'r') % Shows Fuel Rate based on time
  66. % until orbit
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement