The mathematics of football free-kicks: MATLAB code

This Saturday two of the best teams in the world, Juventus FC and Real Madrid FC are playing the final of the best club competition in the world, the UEFA Champions League in Cardiff, UK.

This motivated me to write an online blog for Chalkdust magazine. The content of the article is the mathematics and the science behind, from my point of view, the most spectacular goal I have ever seen in my life, the famous free-kick taken by Roberto Carlos in 1997. The very first time I watched it, I was a kid and I was so impressed by this goal that I could not find an explanation to it: how it was possible that the ball bent drastically and landed in the goal, when it seemed that it was heading in a totally different direction. As a kid, you always try to do what your heroes do (in my case, Roberto Carlos was and still is one of my favourites football players), and I was not an exception: I tried to kick my football trying to replicate the “weird” effect seen in Roberto Carlos’ free kick. I never succeded (just in a few ocassions, but not quite good).

A picture I took during my visit to Spain: Champions League trophies, Madrid.

I grow up and my interest for science during my adolescence increased, which motivated me to begin to read scientific magazines. I remember that time when I was reading one of my very first magazines, I surprisingly found an article explaining the physics behind Roberto Carlos’ goal: my favourite sport and science combined in an excellent read. Unfortunately, the concepts involved there were still a bit complex for me in order to completely understand it. But I promised myself: one day, I have to be able to study in detail this goal. And now that I am a PhD student in mathematics and working in fluid mechanics, finally decided to do it. It was not easy though, but quite funny. A lot of information regarding this topic can be found in many scientific journals. I read some of them and managed to write my very own version of an article explaining the science and mathematics about free kicks (more specifically, Roberto Carlos’ one).

You can completely read it here. Here in this blog, I will show some stuff that could not be included in the original article.

Initial conditions

In the article, we mention that in order to solve our system of differential equations, we need six initial conditions. Three of them are the elements of the vector position. The other three are the components of the vector velocity, which have to be determined using the diagrams below:

Initial position and vector

The values of the angles shown in the diagram above were determined by the scientists. These values are used to calculate the components of the initial vector velocity:

Vector velocity

Using a bit of trigonometry and geometry, relations for the initial vector velocity are found:Screen Shot 2017-06-01 at 11.59.34


For any person interested in simulating their own football free kick, I provide the code I used to obtain the curves and plots shown in the original Chalkdust online article. I used the MATLAB software to introduce my equations, as shown below:


You only need to open a new script in MATLAB and write down all the equations. The text in green indicates what the symbols and the equations stand for.


Once that you have finished, just type in the command window the values of the variables required by the function rocarlosfk(t,y,d,p,m,w0):


You need to specify the interval of time you wish to calculate the solutions of the system of ODE’s. In this case, this is introduced in tspan. The initial value is at time t=0 and the final time is 1.34 s.

The initial conditions are introduced as y0 in vector form (see the picture). The first three elements are the components of the vector position and the last three are the components of initial vector velocity. Finally, you call the solver ode 45 as follows:

[t,y] = ode45(@(t,y) rocarlosfk(t,y,d,p,m,w0), tspan, y0)

To see the solutions of the system, you plot the results using the plot3 function. The code shown above is for the simulation of Roberto Carlos’ free kick. But you can simulate your own football free kicks using different conditions. Try changing the angles, the density of the air, the magnitude of the vector velocity. The only fundamental thing is that you have to satisfy the conditions mentioned on the online article and the equations shown here for the components of vector velocity.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s