MateLab + Latex

profileDLLM
cs111_midterm.pdf

CS 111 - Introduction to Computational Science Fall 2017

Midterm

Rules: You cannot work in groups for the Midterm, i.e. each student must turn in their own work.

The goal of this exercise is to score a goal to study the motion of spinning sport balls. The skill of launching a ball in a curved trajectory to deceive an opponent and/or to avoid hitting an obstacle is very important in many games such as soccer, football, tennis, baseball, etc. The particular situation you consider is a direct free kick from soccer. A direct free kick is a method of restarting a soccer game and is awarded to a team when the opposing team violates the rules of the game. In case when the place of a foul is close enough to the defending team goal the attacking team may choose to attempt to score a goal by kicking the ball directly into the opponent’s goal. To prevent it the defending team usually places a wall formed by several players between the goal and the ball at some distance from the ball1. However, skilled free-kick takers can give a very precise amount of spin to the ball to “bend” it around or over the wall and score impressive goals.

Let us direct the coordinates axes as shown in the figure above, that is, the x-axis goes parallel to the goal line, the y-axis points towards the center of the field and the z-axis points upwards, while the origin is in the center of the goal. Denote as (x0, y0, z0) the initial location of the ball and as (v0x, v

0 y, v

0 z )

its velocity right after the strike. Three forces influence the ball trajectory: the gravitational force, the drag force due to the air resistance and the lift force due to the Magnus effect. According to the Newton’s second law the motion of the ball in this situation is described by the equation

m~a = m~g︸︷︷︸ Gravity

−cdrag|v|~v︸ ︷︷ ︸ Drag

+ clift|v|~s×~v︸ ︷︷ ︸ Magnus effect

(1)

where m = 0.437 kg is the ball’s mass, ~a =

 axay az

  and ~v =

 vxvy vz

  are its acceleration and velocity,

g ≈ 9.81 m/s2 is the free-fall acceleration, , ~s =

 sxsy sz

  is the spin direction, cdrag and clift are the drag

and lift coefficients. 1According to the rules players of the defending team cannot be within the distance of 9.15 m to the ball when a

direct free kick is taken

1

CS 111 - Introduction to Computational Science Fall 2017

In the component notation equation (1) has the form 

m d2x

dt2 = −cdrag|v|vx + clift|v|(syvz −szvy)

m d2y

dt2 = −cdrag|v|vy + clift|v|(szvx −sxvz)

m d2z

dt2 = −g − cdrag|v|vz + clift|v|(sxvy −syvx)

(2)

Recall that |v| = √

v2x + v 2 y + v

2 z and vx =

dx

dt , vy =

dy

dt , vz =

dz

dt .

The starting position and velocity of the ball constitute initial conditions for the system above 

x(0) = x0, y(0) = y0, z(0) = z0,

dx

dt (0) = v0x,

dy

dt (0) = v0y,

dz

dt (0) = v0z.

(3)

Model the defensive wall as a rectangle, one corner of which is located at (xwallstart, y wall start, 0) and the

opposite corner is at (xwallend , y wall end , h

wall). The length and height of the goal are Lgoal = 7.32 m and hgoal = 2.44 m.

1. Write system of equations (2) as a system of first-order ODEs.

2. Write a MATLAB function for solving a general system of first-order ODEs of size m (you can assume m = 6) 

 dy(1)

dt = f (1)(t, y(1), . . . , y(m))

. . .

dy(m)

dt = f (m)(t, y(1), . . . , y(m))

using the fourth-order accurate Runge-Kutta Method (RK4). Your function should take in as

input parameters a vector-valued function ~f =

 f (1). . . f (m)

 , a vector of initial conditions ~y0 =

y (1) 0

. . .

y (m) 0

 , initial and final times tstart and tfinal and time-step ∆t. The output of the function

should be an array t containing all instants of time t0 = tstart, t1 = t0 + ∆t, . . ., tntotal = tfinal and a matrix y of size m×ntotal containing numerical solutions at corresponding instants of time as columns. For example,

function [t, y] = name_of_your_function(f, y0, t_start, t_final, dt)

...

end

2

CS 111 - Introduction to Computational Science Fall 2017

3. Test your MATLAB function using the system of equations 

dy(1)

dt = y(2)

dy(2)

dt = sin

( 1 − exp

( y(3) ))

dy(3)

dt =

1

1 − ln ( y(5) − 1

) dy(4)

dt =

( 1

2 t2 + t

) y2 + exp

( y(3) ) y(1)

dy(5)

dt = 1 −y(5)

dy(6)

dt = −3

( exp

( y(3) ) − 1

1 + t3

)2 with the initial conditions

y(1)(0) = 0, y(2)(0) = 1, y(3)(0) = 0, y(4)(0) = 0, y(5)(0) = 2, y(6)(0) = 1

The exact solution to this test problem is 

y (1) exact(t) = sin(t)

y (2) exact(t) = cos(t)

y (3) exact(t) = ln(1 + t)

y (4) exact(t) =

( 1

2 t2 + t

) sin(t)

y (5) exact(t) = 1 + exp(−t)

y (6) exact(t) =

1

1 + t3

Take tstart = 0, tfinal = 1. Compute the order of accuracy using time-steps ∆t = 0.1, 0.05, 0.025, 0.0125 and 0.00625 and make sure that your ODE solver produces the expected order of accuracy. Use the following formula to calculate the error of a numerical solution

E = max 1≤n≤ntotal

(√( y

(1) exact(tn) −y

(1) n

)2 + . . . +

( y

(6) exact(tn) −y

(6) n

)2) 4. Use your function to solve the system of equations describing the motion of a spinning ball and

obtain trajectories of the ball for each of the cases presented in Table 1 (in all cases cdrag = 0.0057, clift = 0.0061, h

wall = 2). Take tstart = 0, tfinal = 2 and ∆t = 0.02. You can use function plot_trajectory.m to visualize your results.

5. Write a code that analyzes the trajectories of the ball and determines whether the ball hits the defensive wall and whether the ball goes into the goal. Determine the outcome of the free kick for each of the cases in Table 1.

What to turn in: your code and a professional report should be uploaded to Gauchospace.

3

CS 111 - Introduction to Computational Science Fall 2017

Location Velocity Spin Wall

case no. x0 y0 z0 v0x v 0 y v

0 z sx sy sz x

wall start y

wall start x

wall end y

wall end

1 −15 23 0 18 −23 8.5 0.10 0.10 0.99 −11.2 14.7 −8.6 16.0 2 25.5 15 0 −28 −11 7.5 0 0 1 18.1 9.7 17 11.3 3 −4 35 0 −8 −36 5 −0.32 0 0.95 −4.3 25.9 −0.8 25.9 4 16 28 0 −25 −20 8 0.10 0.15 0.98 12.6 19.6 9.9 20.8

Table 1: Direct free kick examples

4