====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
gibson:teaching:summer-2017:techcamp:numerical-baseball [2017/07/18 06:21] gibson [Solving the equations of motion numerically] |
gibson:teaching:summer-2017:techcamp:numerical-baseball [2017/07/18 09:09] (current) gibson [Running the Matlab code to see the results] |
||
---|---|---|---|
Line 28: | Line 28: | ||
<code matlab> | <code matlab> | ||
function dudt = f_nodrag(t, u) | function dudt = f_nodrag(t, u) | ||
+ | % equations of motion for baseball in flight without air resistance | ||
g = 9.8; % acceleration of gravity m/s^2 | g = 9.8; % acceleration of gravity m/s^2 | ||
+ | % extract components of vector u into variables x, y, vx, vy | ||
x = u(1); | x = u(1); | ||
y = u(2); | y = u(2); | ||
Line 36: | Line 38: | ||
vy = u(4); | vy = u(4); | ||
+ | % compute rates of change of those components | ||
dxdt = vx; | dxdt = vx; | ||
dydt = vy; | dydt = vy; | ||
Line 41: | Line 44: | ||
dvydt = -g; | dvydt = -g; | ||
+ | % pack rates of change back into vector dudt, return value of function | ||
dudt = [dxdt; dydt; dvxdt; dvydt]; | dudt = [dxdt; dydt; dvxdt; dvydt]; | ||
end | end | ||
Line 65: | Line 69: | ||
<code matlab> | <code matlab> | ||
function dudt = f_withdrag(t,u) | function dudt = f_withdrag(t,u) | ||
- | rho_air = 1.196; % kg/m^3, density of dry air, 21 C, sea level (Fenway) | + | % equations of motion for baseball in flight with turbulent air resistance |
- | + | ||
- | C = 0.3; % drag coefficient for baseball (rough sphere) | + | rho_air = 1.196; % kg/m^3, density of dry air, 21 C, sea level (Fenway) |
- | g = 9.81; % acceleration due to gravity in m/s^2 | + | C = 0.3; % drag coefficient for baseball (rough sphere) |
- | r = 0.0375; % radius of baseball in m (3.75 cm) | + | g = 9.81; % acceleration due to gravity in m/s^2 |
- | A = pi*r^2; % cross-sectional area of baseball in m^2 | + | r = 0.0375; % radius of baseball in m (3.75 cm) |
- | m = 0.145; % mass of baseball in kg (145 gm | + | A = pi*r^2; % cross-sectional area of baseball in m^2 |
- | + | m = 0.145; % mass of baseball in kg (145 gm) | |
mu = rho_air*C_D*A/2; % coefficient of nonlinear |v|^2 term, in mks units | mu = rho_air*C_D*A/2; % coefficient of nonlinear |v|^2 term, in mks units | ||
+ | % extract components of vector u into variables x, y, vx, vy | ||
x = u(1); | x = u(1); | ||
y = u(2); | y = u(2); | ||
Line 80: | Line 85: | ||
vy = u(4); | vy = u(4); | ||
+ | % compute rates of change of those components | ||
dxdt = vx; | dxdt = vx; | ||
dydt = vy; | dydt = vy; | ||
Line 85: | Line 91: | ||
dvydt = -mu/m * vy * sqrt(vx^2 + vy^2) - g; | dvydt = -mu/m * vy * sqrt(vx^2 + vy^2) - g; | ||
+ | % pack rates of change back into vector dudt, return value of function | ||
dudt = [dxdt; dydt; dvxdt; dvydt] | dudt = [dxdt; dydt; dvxdt; dvydt] | ||
end | end | ||
Line 91: | Line 98: | ||
==== Solving the equations of motion numerically ==== | ==== Solving the equations of motion numerically ==== | ||
+ | |||
The file ``baseballsolve.m`` solves the above equations with some numerical solution methods, given | The file ``baseballsolve.m`` solves the above equations with some numerical solution methods, given | ||
Line 97: | Line 105: | ||
<code matlab> | <code matlab> | ||
+ | % Compute the trajectory of a baseball in flight, with and without | ||
+ | % air resistance and plot results | ||
+ | |||
x = 0.0; % horizontal position of home plate, meters | x = 0.0; % horizontal position of home plate, meters | ||
y = 1.0; % height of ball over strike zone | y = 1.0; % height of ball over strike zone | ||
Line 149: | Line 160: | ||
The thick black line shows the outfiled fence at 390 ft or 120 m, and 17 ft or 5.2 m high. | The thick black line shows the outfiled fence at 390 ft or 120 m, and 17 ft or 5.2 m high. | ||
- | **Questions** | + | ==== Question ==== |
* How important is the effect of air resistance? | * How important is the effect of air resistance? | ||
- | * Air density at Fenway park (sea level) is 1.196 kg/m^3. At one mile high in Denver, it's 0.986 kg/m^3. How much does the change in density affect the path of the ball at different angles and speeds? Try to change the above codes to find out. See if you can find a speed and angle that gives a home run in Denver but not at Fenway. | + | * Air density at Fenway park (sea level) is 1.196 kg/m^3. At one mile high in Denver, it's 0.986 kg/m^3. How much does the change in density affect the path of the ball at different angles and speeds? Try to change the above codes to show the path of the ball for both Fenway and Denver conditions. See if you can find a speed and angle that gives a home run in Denver but not at Fenway. |
* Play around with the parameters in the functions, like the speed and angle of the ball. Can you figure out the minimum speed and optimal angle to just clear the outfiled fence and hit a home run? | * Play around with the parameters in the functions, like the speed and angle of the ball. Can you figure out the minimum speed and optimal angle to just clear the outfiled fence and hit a home run? | ||
+ | ==== Next ==== | ||
+ | [[gibson:teaching:summer-2017:techcamp:computer-homerun | Hitting a home run]] | ||