cyruswachong

most recent

Mar 4th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.52 KB | None | 0 0
  1. %% ENSC180-Assignment2
  2.  
  3. % Student Name 1: Jose Lopez
  4.  
  5. % Student 1 #: 301317479
  6.  
  7. % Student 1 userid (email): jlopezsa@sfu.ca
  8.  
  9. % Student Name 2: Cyrus WaChong
  10.  
  11. % Student 2 #: 301306459
  12.  
  13. % Student 2 userid (email): cwachong@sfu.ca
  14.  
  15. % Below, edit to list any people who helped you with the assignment,
  16.  
  17. % Helpers: Selikem Kwaznadovia, Sterling Smith, Yutaka Yen, Tal Kazakov, Rameshwar
  18. % Kannan, Santhosh Nandakumar, Sirpreet Kaur Dhillon
  19.  
  20. %% Instructions:
  21. % * Put your name(s), student number(s), userid(s) in the above section.
  22. % * Edit the "Helpers" line.
  23. % * Your group name should be "A2_<userid1>_<userid2>" (eg. A2_stu1_stu2)
  24. % * Form a group
  25. % as described at: https://courses.cs.sfu.ca/docs/students
  26. % * Replace "% <place your work here>" below, or similar, with your own answers and work.
  27. % * You can copy your work from your other functions and (live) scripts and as needed.
  28. % * Nagvigate to the "PUBLISH" tab (located on top of the editor)
  29. % * Choose pdf as "Output file format" under "Edit Publishing Options..."
  30. % * Click "Publish" button. Ensure a report is automatically generated
  31. % * You will submit THIS file (assignment2.m),
  32. % and the PDF report (assignment2.pdf).
  33. % Craig Scratchley, Spring 2017
  34.  
  35. %% main
  36.  
  37. function main
  38.  
  39. clf
  40.  
  41. % constants -- you can put constants for the program here
  42. %MY_CONST = 123;
  43.  
  44. % variables -- you can put variables for the program here
  45. %myVar = 456;
  46.  
  47. % prepare the data
  48. % <place your work here>
  49. X=xlsread('data_clean_more_fixed_simplest.xlsx', 'data_clean_more_fixed_label', 'B1:B15348');
  50. X=X(isfinite(X(:, 1)), :);
  51. V=xlsread('data_clean_more_fixed_simplest.xlsx', 'data_clean_more_fixed_label', 'C1:C15348');
  52. V=V(isfinite(V(:, 1)), :);
  53. T=xlsread('data_clean_more_fixed_simplest.xlsx', 'data_clean_more_fixed_label', 'A1:A15348');
  54. T=T(isfinite(T(:, 1)), :);
  55.  
  56. % myVector(isnan(myVector))=[];
  57.  
  58. % <put here any conversions that are necessary>
  59.  
  60. %% Part 1
  61. % Answer some questions here in these comments...
  62. % How accurate is the model for the first portion of the minute?
  63. % They appear to be almost identical, therefore rendering the accuracy
  64. % quite high.
  65.  
  66. % How accurate is the model for the last portion of that first minute?
  67. % it diminishes as time continues; accuracy is less than the first portion.
  68.  
  69. % Comment on the acceleration calculated from the measured data.
  70. % Is there any way to smooth the acceleration calculated from the data?
  71. % We could use the smooth function, which we found through Sirpreet, or we
  72. % could take more info from an increment in time, which would smooth the
  73. % graph.
  74.  
  75. part = 1;
  76. endtime=60
  77. starttime=0
  78. %[t1,x1] = ode45(@fall, [starttime,endtime], [38969.4, 0]);
  79. %plotter(X,V,T,'Part1 - Freefall')
  80. % <call here your function to create your plots>
  81.  
  82.  
  83. %% Part 2
  84. % Answer some questions here in these comments...
  85. % Estimate your uncertainty in the mass that you have chosen (at the
  86. % beginning of the jump).
  87. % between 1- 3% of the total mass, due to small things, like food in his
  88. % sytems, liquids, equipment on him, and many other small differences.
  89.  
  90. % How sensitive is the velocity and altitude reached after 60 seconds to
  91. % changes in the chosen mass?
  92. % so after a bit of testing, small changes such as 2 to 3 kilos, change
  93. % your altitude from the surface by around 5x10^3 m in the 60 second interval,
  94. % and around an increase in 8-11 m/s at 60 seconds after the jump.
  95.  
  96. part = 2;
  97. endtime=60
  98. starttime=0
  99. %[t1,x1] = ode45(@fall, [starttime,endtime], [38969.4, 0]);
  100.  
  101. % <call here your function to create your plots>
  102. %plotter(X,V,T,'Part2 - Simple Air Resistance' )
  103.  
  104. %% Part 3
  105. % Answer some questions here in these comments...
  106. % Felix was wearing a pressure suit and carrying oxygen. Why?
  107. % What can we say about the density of air in the stratosphere?
  108. % How is the density of air different at around 39,000 meters than it
  109. % is on the ground?
  110. %
  111. % The density of the air in the stratosphere is less than the surface of
  112. % the earth, meaning there is less molecules per specified area, and
  113. % without the tank of oxygen and suit, he would die from lack of oxygen,
  114. % dangerous radiation, and the cold. The density is about 272 times
  115. % stronger on the crust compared to 39.000 feet up, on earth, stdatmo
  116. % returns a value of 1.225, while up at 39.000, it returns 0.0045, and
  117. % looking at standard graphs for air pressure at atmospheres ( I’m aware
  118. % they are not accurate due to all the factors that affect it) is ~250 times
  119. % also.
  120.  
  121. % What are the factors involved in calculating the density of air?
  122. % How do those factors change when we end up at the ground but start
  123. % at the stratosphere? Please explain how calculating air density up
  124. % to the stratosphere is more complicated than say just in the troposphere.
  125.  
  126. % There are quite a few factors, like temperature, air pressure, altitude and
  127. % weather (and humidity). The air pressure will increase significantly, the
  128. % weather would change quite a bit, altitude would obviously drop, and
  129. % temperature would decrease, due to the ozone layer absorbing the UV rays creating heat energy.
  130. % and leading to a higher overall density of air. The troposphere has the
  131. % most density, due to all layers on top pushing on it, squeezing molecules
  132. % closer together.
  133.  
  134.  
  135. % What method(s) can we employ to estimate [the ACd] product?
  136. % We can take the drag force and divide by air density (rho), divide by
  137. % velocity squared, and all multiplied by 2. This is the exact way to get
  138. % it. We can also use newton's second law to find the ACd.
  139.  
  140. % What is your estimated [ACd] product?
  141. % 0.12
  142. %
  143. % [Given what we are told in the textbook about the simple drag constant, b,]
  144. % does the estimate for ACd seem reasonable?
  145. % <put your answer here in these comments>
  146.  
  147. part = 3;
  148. endtime=270
  149. starttime=0
  150. % <place your work here>
  151. %[t1,x1] = ode45(@fall, [starttime,endtime], [38969.4, 0]);
  152. %plotter(X,V,T,'Part3 - Simple Air Resistance' )
  153.  
  154. %% Part 4
  155. % Answer some questions here in these comments...
  156. % What is the actual gravitational field strength around 39,000 meters?
  157. % (See Tipler Volume 1 6e page 369.)
  158.  
  159. % Using the gravitational Field Strength Formula, we can calculate that
  160. % (6.67*10^-11)*(5.972*10^24)/(6371000+39000)^2=9.69 m/s^2
  161.  
  162. % How sensitive is the altitude reached after 4.5 minutes to simpler and
  163. % more complicated ways of modelling the gravitational field strength?
  164. %
  165. % Since the acceleration at 39,000 meters is 9.69 m/s^2 and at the surface
  166. % of the earth is 9.81, we can conclude that a more complicated way of
  167. % calculating the gravitiational field strength would not affect the value
  168. % that much since the difference between the two is only 0.1m/s^2
  169.  
  170. % What other changes could we make to our model? Refer to, or at least
  171. % attempt to explain, the physics behind any changes that you propose.
  172. %
  173.  
  174. % What is a change that we could make to our model that would result in
  175. % insignificant changes to the altitude reached after 4.5 minutes?
  176. % <put your answer here in these comments>
  177.  
  178. % How can we decide what change is significant and what change is
  179. % insignificant?
  180. % <put your answer here in these comments>
  181.  
  182. % [What changes did you try out to improve the model? (Show us your changes
  183. % even if they didn't make the improvement you hoped for.)]
  184. % <put your answer here in these comments>
  185.  
  186. part = 4;
  187.  
  188. % <place your work here>
  189. %plotter(X,V,T,'Part 4')
  190. %% Part 5
  191. % Answer some questions here in these comments...
  192. % At what altitude does Felix pull the ripcord to deploy his parachute?
  193. % <put your answer here in these comments>
  194.  
  195. % Recalculate the ACd product with the parachute open, and modify your
  196. % code so that you use one ACd product before and one after this altitude.
  197. % According to this version of the model, what is the maximum magnitude
  198. % of acceleration that Felix experiences?
  199. % <put your answer here in these comments>
  200.  
  201. % How safe or unsafe would such an acceleration be for Felix?
  202. % <put your answer here in these comments>
  203.  
  204. part = 5;
  205.  
  206. %Make a single acceleration-plot figure that includes, for each of the
  207. %model and the acceleration calculated from measurements, the moment when
  208. %the parachute opens and the following 10 or so seconds. If you have
  209. %trouble solving this version of the model, just plot the acceleration
  210. %calculated from measurements.
  211. % <place your work here>
  212.  
  213. %% Part 6
  214. % Answer some questions here in these comments...
  215. % How long does it take for Felix’s parachute to open?
  216. % 5.6 seconds, measured by looking at the video
  217.  
  218. part = 6;
  219.  
  220. %Redraw the acceleration figure from the previous Part but using the new
  221. % model. Also, using your plotting function from Part 1, plot the
  222. % measured/calculated data and the model for the entire jump from
  223. % stratosphere to ground.
  224. % <place your work here>
  225. endtime = 450
  226. starttime =400
  227. [t1,x1] = ode45(@fall, [starttime,endtime], [38969.4, 0]);
  228. plotter(X,V,T,'Part6' )
  229. %% nested functions
  230. % nested functions below are required for the assignment.
  231. % see Downey Section 10.1 for discussion of nested functions
  232.  
  233. function res = fall(t, X)
  234. %FALL <Summary of this function goes here>
  235. % <Detailed explanation goes here>
  236.  
  237. % do not modify this function unless required by you for some reason!
  238.  
  239. p = X(1); % the first element is position
  240. v = X(2); % the second element is velocity
  241.  
  242. dpdt = v; % velocity: the derivative of position w.r.t. time
  243. dvdt = acceleration(t, p, v); % acceleration: the derivative of velocity w.r.t. time
  244.  
  245. res = [dpdt; dvdt]; % pack the results in a column vector
  246. end
  247.  
  248. function res = acceleration(t, p, v)
  249. % <insert description of function here>
  250. % input...
  251. % t: time
  252. % p: position
  253. % v: velocity
  254. % output...
  255. % res: acceleration
  256.  
  257. % do not modify this function unless required by you for some reason!
  258.  
  259. a_grav = gravityEst(p);
  260.  
  261. if part == 1 % variable part is from workspace of function main.
  262. res = -a_grav;
  263.  
  264. elseif part == 6
  265. G=6.67*10^(-11);
  266. if t<263
  267. A=0.7
  268. end
  269. if t>263
  270. A=25
  271. end
  272. C=1.15
  273. m=118;
  274. M=5.98*10^(24);
  275. r=6370000+p;
  276. R=6370000;
  277. g=-9.81;
  278. res1=g*(R)^2/r^2;
  279. res2=0.5*C*v^2*A*stdatmo(p);
  280. res2=res2/m
  281. res=res1+res2;
  282.  
  283. else
  284. m = mass(t, v);
  285. b = drag(t, p, v, m);
  286.  
  287. f_drag = b * v^2;
  288. a_drag = f_drag / m;
  289. res = -a_grav + a_drag;
  290. end
  291. end
  292.  
  293. % Please paste in or type in code into the below functions as may be needed.
  294.  
  295. function a_grav = gravityEst(p)
  296. % estimate the acceleration due to gravity as a function of altitude, p
  297. A_GRAV_SEA = 9.807; % acceleration of gravity at sea level in m/s^2
  298.  
  299. if part <= 3 % fill in
  300. a_grav = A_GRAV_SEA;
  301. else
  302. a_grav= 3.98866*10^14/(p+6.77*10^6)^2
  303. end
  304. end
  305.  
  306. function res = mass(t, v)
  307. % mass in kg of Felix and all his equipment
  308. res = 118
  309. end
  310.  
  311. function res = drag(t, p, v, m)
  312. % <insert description of function here>
  313.  
  314. if part == 2
  315. res = 0.2;
  316. else
  317. %air resistance drag = 1/2*rho*A*Cd
  318. %%%%%%%%%%% input your code here %%%%%%%%%%%%%%%%
  319. m=118
  320. g=9.80665
  321. rho=stdatmo(p)
  322. a=0.5
  323. cd=0.2
  324. acd=(rho*a*cd)/2
  325. res=acd
  326.  
  327.  
  328. %ACd =2mg/rho*v*v
  329.  
  330. end
  331. end
  332.  
  333. function res = plotter(X,V,T,tit)
  334. V=abs(V)*(1/3.6);
  335. alt=x1(:,1);
  336. vel=abs(x1(:,2));
  337.  
  338.  
  339.  
  340. dv=diff(vel);
  341. dt=diff(t1);
  342. acc=abs(dv./dt);
  343.  
  344.  
  345.  
  346. DV=diff(V)
  347. DT=diff(T)
  348. A=abs(DV./DT)
  349. A=smooth(A)
  350.  
  351. hold on
  352. grid on
  353. plot(t1,alt,'bo');
  354. plot(T,X,'go');
  355. xlim([starttime,endtime]);
  356. title(tit)
  357. xlabel({'Time','(in Seconds)'})
  358. ylabel({'Altitude','in meters'})
  359. legend('Calculated','Excel')
  360.  
  361. figure
  362. hold on
  363. grid on
  364. plot(t1,vel,'bo');
  365. plot(T,V,'go');
  366. xlim([starttime,endtime]);
  367. title(tit)
  368. xlabel({'Time','(in Seconds)'})
  369. ylabel({'Velocity','in m/s'})
  370. legend('Calculated','Excel')
  371.  
  372. figure
  373. hold on
  374. grid on
  375. finalt1=t1(1:end-1);
  376. finalT=T(1:end-1);
  377. plot(finalt1,acc,'bo');
  378. plot(finalT,A,'go');
  379. xlim([starttime,endtime]);
  380. title(tit)
  381. xlabel({'Time','(in Seconds)'})
  382. ylabel({'Acceleration','in m/s^2'})
  383. legend('Calculated','Excel')
  384. end
  385.  
  386.  
  387. %% Additional nested functions
  388. % Nest any other functions below.
  389. %Do not put functions in other files when you submit.
  390.  
  391. % end of nested functions
  392. end % closes function main.
Add Comment
Please, Sign In to add comment