User Tools

Site Tools


gibson:teaching:fall-2013:math445:lab11

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gibson:teaching:fall-2013:math445:lab11 [2013/12/05 08:33]
szeto
gibson:teaching:fall-2013:math445:lab11 [2013/12/05 09:10] (current)
szeto
Line 37: Line 37:
 Hints: It's probably easiest to answer (a)-%%(c)%% if you turn your script into a function ''​xdistance = projectile(v0,​ theta)''​ that returns the distance the projectile travels as a function of the initial velocity and angle. ​ Hints: It's probably easiest to answer (a)-%%(c)%% if you turn your script into a function ''​xdistance = projectile(v0,​ theta)''​ that returns the distance the projectile travels as a function of the initial velocity and angle. ​
 In other words, create a new function ​ "​projectile.m"​ In other words, create a new function ​ "​projectile.m"​
-%%%%%%%%%%%%+<​code>​
 function xdistance = projectile(v0,​theta) function xdistance = projectile(v0,​theta)
  
Line 45: Line 45:
 g = 9.81;        % m/s^2, acceleration due to gravity g = 9.81;        % m/s^2, acceleration due to gravity
  
-.  +
-.  +. 
-[t,x]= ode45(....   [ 0,​0,​v0*cos(theta),​ v0*sin(theta) );+f = @(t,x) [ ....]; 
 + 
 +[t,x]= ode45(f,[0:0.1:200] ,[ 0,​0,​v0*cos(theta),​ v0*sin(theta) ); 
 + 
 +xdistance = interp1(x(50:​end,​2),​ x(50:​end,​1),​ 0);  % This is how you can compute ''​xdistance''​ 
 +% accurately from an ''​x,​y''​ trajectory using interpolation.  
 +% It will return the value of $x$ for which $y=0$, i.e.  
 +% where the cannonball hits the ground.  
 end end
-%%%%%%%%%%%%%%%%%%% +</​code>​ 
-Do plotting and interpolating in another script or on the command line. + 
 +Once your function works, play around with the parameters ''​v0,​ theta''​ to answer the questions. ​  
 +On the command line, you can USE this function like this 
 +<​code>​ 
 +  xdistance = projectile(100,​pi/​2) 
 +  xdistance = projectile(100,​pi/​4) 
 +  xdistance = projectile(100,​pi/​8) 
 +</​code>​
  
-You can compute ''​xdistance''​ accurately from an ''​x,​y''​ trajectory using interpolation:​ 
  
-  ​xdistance ​= interpolate(x(50:end,2), x(50:end,1), 0); +If your xdistance ​is a NaN, you may have to increase the number ​50 in the interp1 function ​(1000 might be goodthat is roughly half the length ​of [0:0.1:200])
-   +
-That will return ​the value of $x$ for which $y=0$, i.e. where the cannonball hits the ground. Once your function works, play around with the parameters ''​v0,​ theta''​ to answer the questions+
  
   ​   ​
gibson/teaching/fall-2013/math445/lab11.1386261210.txt.gz · Last modified: 2013/12/05 08:33 by szeto