## Learning quantum physics

December 7, 2013 at 2:51 PM

I just finished Coursera’s Exploring Quantum Physics. It was pretty good: the Coursera Web sites works well, both lectures and homework exercises were good and the discussion forums were helpful.

The course starts from the basics, but it is not an introductory course: it requires a decent mathematical background (linear algebra and calculus, Fourier transforms) and some previous knowledge of quantum physics is useful, although not strictly necessary.

The course is taught by two teachers with very different styles covering quite different material, this makes it a bit disjointed. I would have preferred a single teacher thorough the whole course.

The program covers various advanced subjects like the Feynman path integral, quantum localization, superconductivity, the Dirac equation, the time-dependent Schrodinger equation and so on. The problem is that having to start more or less from the basics it is impossible to cover any of these advanced subjects in any detail: they are just introduced but not explained enough to get a real understanding. I think it would be better to limit the course to the more ‘standard’ introductory stuff, with maybe just one or two advanced topics covered in more details.

Through a post in one of the Coursera’s forum I discovered the ‘Theoretical minimum’ Stanford lectures. It is not a course but just a collection of live lectures by the same professor. I watched a couple of them on quantum field theory, the first particle physics series and now I am watching the quantum entanglement ones.

The lectures are for a general audience, so they usually start from the very basics and then build the whole theory step by step. The teacher – professor Susskind – manages to introduce very complex stuff in an approachable way.

Being live lectures, there tend to be quite a lot of question from the audience, backtracking and interruptions – these makes them much longer that the recorded Coursera lectures, but I found that this makes the material more easily absorbed (by me at least).

They are very good introduction to modern physics for anyone with some scientific background and enough time to watch an entire series: watching individual lectures would probably not work.

Posted in: Opinion | Physics

## Billiard simulation–part 8: double collision

June 30, 2013 at 4:47 AM

As explained previously, the current algorithm does not handle collisions of multiple balls at the same time. I found a solution for a double collision, and I am pretty sure that there is no single solution for more complex cases using only conservation laws and the coefficient of restitution formula – but I still have to prove it. Of course there would be a solution modeling the actual physics of the collisions – a problem for another day.

### Double ball collision

..or more formally: elastic collision of three spheres in two dimensions

Ball 0 – with velocity $$(v_0,w_0)$$, hits at the same time ball 1 and ball 2 –  that have velocities $$(v_1, w_1)$$ and $$(v_2, w_2)$$ respectively.

Projecting the velocity $$(v_0,w_0)$$ onto the lines connecting the center of ball 0 with the centers of balls 1 and 2 gives the velocity components $$q_{01}$$ and $$q_{02}$$. Projecting the velocity $$(v_1,w_1)$$ onto the line connecting the center of ball 0 with the center of ball 1 and onto its perpendicular through the center of ball 1 gives the velocity components $$q_1$$ and $$p_1$$. Doing the same thing for ball 2 gives the velocity components $$q_2$$ and $$p_2$$.

Here is the drawing:

As usual, balls are not spinning and there is no ball-ball friction, so the forces between balls are only along the lines connecting the center of ball 0 with the centers of balls 1 and 2. This means that the velocity components perpendicular to those lines are the same before and after the collision:

$$p’_1 = p_1$$

$$p’_2 = o_2$$

(indicating with a prime the velocities after the collision), whereas the velocity components along those lines are related by the coefficient of restitution formula:

$$q’_{01} – q’_1 = c(q_1 – q_{01})$$

$$q’_{02} – q’_2 = c(q_2 – q_{02})$$

Let’s not use trigonometry this time. The projection of a velocity onto the line connecting the center of two ball is the scalar product of the velocity with the unit vector pointing from one center to the other. For balls 0 and 1 this unit vector is:

$$\left( \frac{x_{01}}{\sqrt{x_{01}^2 + y_{01}^2}}, \frac{y_{01}}{\sqrt{x_{01}^2 + y_{01}^2}} \right)$$

where $$x_{01} = x_1 – x_0$$ and $$y_{01}=y_1-y_0$$, hence:

$$q_1 = \frac{v_1x_{01} + w_1y_{01}}{\sqrt{x_{01}^2 + y_{01}^2}}$$

$$q_01 = \frac{v_0x_{01} + w_0y_{01}}{\sqrt{x_{01}^2 + y_{01}^2}}$$

Similarly, the projection on the perpendicular of that line is the scalar product of the velocity with the perpendicular unit vector:

$$\left( -\frac{y_{01}}{\sqrt{x_{01}^2 + y_{01}^2}} , \frac{x_{01}}{\sqrt{x_{01}^2 + y_{01}^2}} \right)$$

hence:

$$p_1 = \frac{-v_1y_{01} + w_1x_{01}}{\sqrt{x_{01}^2 + y_{01}^2}}$$

Replacing these values in the four initial equations gives:

$$–v’_1y_{01} + w’_1x_{01} = -v_1y_{01} + w_1x_{01}$$

$$–v’_2y_{02} + w’_2x_{02} = -v_2y_{02} + w_2x_{02}$$

$$v’_0x_{01} + w’_0y_{01} – v’_1x_{01} – w’_1y_{01} = c(v_1x_{01} + w_1y_{01} - v_0x_{01} - w_0y_{01})$$

$$v’_0x_{02} + w’_0y_{02} – v’_1x_{02} – w’_2y_{02} = c(v_2x_{02} + w_2y_{02} - v_0x_{02} - w_0y_{02})$$

The conservation of momentum gives two additional equations:

$$m_0v’_0 + m_1v’_1 + m_2v’_2 = m_0v_0 + m_1v_1 + m_2v_2$$

$$m_0w’_0 + m_1w’_1 + m_2w’_2 = m_0w_0 + m_1w_1 + m_2w_2$$

- where $$m_0$$, $$m_1$$ and $$m_2$$ are the masses of the balls, resulting in a system of 6 linear equations for the 6 unknowns $$v’_0, w’_0, v’_1, w’_1, v’_2, w’_2$$. Introducing new unknowns $$u_j$$ defined as:

$$u_0 = v’_0 – v_0,\quad u_1 = w’_0 – w_0,\quad u_2 = v’_1 – v_1,\quad u_3 = w’_1 – w_1,\quad u_4 = v’_2 – v_2,\quad u_5 = w’_2 – w_2$$

the system becomes a bit simpler:

$$x_{01} u_3 – y_{01} u_2 = 0$$

$$x_{02} u_5 – y_{02} u_4 = 0$$

$$x_{01} (u_0-u_2) + y_{01}(u_1-u_3) = B_{01}$$

$$x_{02} (u_0-u_4) + y_{02}(u_1-u_5) = B_{02}$$

$$m_0u_0 + m_1u_2 + m_2u_4 = 0$$

$$m_0u_1 + m_1u_3 + m_2u_5 = 0$$

with

$$B_{01} = (1+c)[x_{01}(v_1 – v_0) + y_{01}(w_1-w_0)]$$

$$B_{02} = (1+c)[x_{02}(v_2 – v_0) + y_{02}(w_2-w_0)]$$

After quite a lot of substitutions and simplification the result is

$$u_0 = v’_0 – v_0 = –\frac{1}{\Delta}[B_{01}m_1(x_{02}m_2P – x_{01}(m_0+m_2)S_{02}) + B_{02}m_2(x_{01}m_1P-x_{02}(m_0+m_1)S_{01})]$$

$$u_1= w’_0 – w_0 = –\frac{1}{\Delta}[B_{01}m_1(y_{02}m_2P – y_{01}(m_0+m_2)S_{02}) + B_{02}m_2(y_{01}m_1P-y_{02}(m_0+m_1)S_{01})]$$

$$u_2 = v’_1 – v_1 = \frac{x_{01}m_0}{\Delta}[B_{02}m_2P-B_{01}(m_0+m_2)S_{02})]$$

$$u_3= w’_1 – w_1 = \frac{y_{01}m_0}{\Delta}[B_{02}m_2P-B_{01}(m_0+m_2)S_{02})]$$

$$u_4 = v’_2 – v_2 = \frac{x_{02}m_0}{\Delta}[B_{01}m_1P-B_{02}(m_0+m_1)S_{01})]$$

$$u_5 = w’_2 – w_2 = \frac{y_{02}m_0}{\Delta}[B_{01}m_1P-B_{02}(m_0+m_1)S_{01})]$$

with

$$P = x_{01}x_{02}+y_{01}y_{02}$$

$$S_{01} = x_{01}^2 + y_{01}^2$$

$$S_{02} = x_{02}^2 + y_{02}^2$$

$$\Delta = (m_0 + m_1)(m_0 + m_2) S_{01}S_{02}-m_1m_2P^2$$

The corresponding code is:

  /**
* Updates the velocities of this ball and two other balls after a double collisions
* with both balls at the exact same time
* The coordinate of the balls must be at the collision point.
* @param otherBall1 second colliding ball
* @param otherBall2 third colliding ball
* @param restitution coefficient of restitution for a ball-ball collision
*/
collide2(otherBall1: Ball, otherBall2: Ball, restitution: number) {
var m0 = Math.pow(this.radius, 3);
var m1 = Math.pow(otherBall1.radius, 3);
var m2 = Math.pow(otherBall2.radius, 3);
var x01 = otherBall1.x - this.x;
var y01 = otherBall1.y - this.y;
var x02 = otherBall2.x - this.x;
var y02 = otherBall2.y - this.y;
var p = x01 * x02 + y01 * y02;
var s01 = x01 * x01 + y01 * y01;
var s02 = x02 * x02 + y02 * y02;
var delta = (m0 + m1) * (m0 + m2) * s01 * s02 - m1 * m2 * p * p;
var v01 = otherBall1.v - this.v;
var w01 = otherBall1.w - this.w;
var b01 = (1 + restitution) * (x01 * v01 + y01 * w01);
var v02 = otherBall2.v - this.v;
var w02 = otherBall2.w - this.w;
var b02 = (1 + restitution) * (x02 * v02 + y02 * w02);
this.v = -(b01 * m1 * (x02 * m2 * p - x01 * (m0 + m2) * s02) + b02 * m2 * (x01 * m1 * p - x02 * (m0 + m1) * s01)) / delta + this.v;
this.w = -(b01 * m1 * (y02 * m2 * p - y01 * (m0 + m2) * s02) + b02 * m2 * (y01 * m1 * p - y02 * (m0 + m1) * s01)) / delta + this.w;
var r1 = m0 * (b02 * m2 * p - b01 * (m0 + m2) * s02) / delta;
otherBall1.v = x01 * r1 + otherBall1.v;
otherBall1.w = y01 * r1 + otherBall1.w;
var r2 = m0 * (b01 * m1 * p - b02 * (m0 + m1) * s01) / delta;
otherBall2.v = x02 * r2 + otherBall2.v;
otherBall2.w = y02 * r2 + otherBall2.w;
} // collide2

As a verification, when $$m_2 = 0$$ the first four equations become:

$$u_0 = v’_0 – v_0 = x_{01} \frac{m_1}{m_0+m_1} \frac{B_{01}}{S_{01}}$$

$$u_1 = w’_0 – w_0 = y_{01} \frac{m_1}{m_0+m_1} \frac{B_{01}}{S_{01}}$$

$$u_2 = v’_1 – v_1 = -x_{01} \frac{m_0}{m_0+m_1} \frac{B_{01}}{S_{01}}$$

$$u_3 = w’_1 – w_1 = -y_{01} \frac{m_0}{m_0+m_1} \frac{B_{01}}{S_{01}}$$

if $$\alpha$$ is the angle between the vector from ball 0 to ball 1 and the horizontal, then:

$$\cos\alpha = \frac{x_{01}}{\sqrt{x_{01}^2 + y_{01}^2}}$$

$$\sin\alpha = \frac{y_{01}}{\sqrt{x_{01}^2 + y_{01}^2}}$$

hence

$$\frac{B_{01}}{S_{01}} = -\frac{1+c}{\sqrt{x_{01}^2 + y_{01}^2}}[\cos\alpha(v_0 – v_1) + \sin\alpha(w_0-w_1)]$$

and the result is the same as in the two balls case.

Posted in: Physics | Programming

## Billiard simulation–part 5: friction

May 26, 2013 at 9:03 AM

The velocity of the balls progressively decreases due to three different effects: loss of energy during collisions, friction with the table (rolling friction or rolling resistance) and friction with the air (drag).

The loss of energy during collisions is already accounted for by the coefficient of restitution used in the collisions formulas.

The general formula for the rolling friction is:

$$F_{rr} = c_{rr}N$$

where $$F_{rr}$$ is the resulting rolling friction force, $$c_{rr}$$ is the coefficient of rolling friction – that depends on the materials of the ball and the table – and $$N$$ is the downward force exerted by the ball on the table. $$N$$ is equal to the mass $$m$$ of the ball times the gravitational acceleration $$g$$: $$N = mg$$. The deceleration $$a_{rr}$$ of the ball due to the rolling friction is the friction force divided by the mass of the ball: $$a_{rr}=F_{rr}/m$$. Combining these two equation the rolling friction deceleration is:

$$a_{rr} = c_{rr}g$$

The formula for the air drag is:

$$F_d = \frac{1}{2}\rho_a v^2 c_d A$$

where $$F_d$$ is the resulting drag force, $$\rho_a$$ is the air density, $$v$$ is the ball speed, $$c_d$$ is the drag coefficient and $$A$$ is the cross-sectional area of the ball. The deceleration $$a_{d}$$ of the ball due to the air drag is the air drag force divided by the mass of the ball:

$$a_d = \frac{F_d}{m} = \frac{F_d}{\frac{4}{3}\pi\rho_b r^3}$$

where $$\rho_b$$ is the density of the ball and $$r$$ is its radius. The cross-sectional area of the ball is $$A=\pi r^2$$ – putting all this together the air drag deceleration is:

$$a_d = f_d \frac{v^2}{r}$$

where the air drag factor $$f_d$$ is defined as

$$f_d = \frac{3\rho_a c_d}{8\rho_b}$$

The drag coefficient $$c_d$$ for a sphere varies quite a bit with the velocity of the object – see here for example, but overall the air drag is quite small, so even using a constant would not change the result much; hence given the air density and the ball density $$f_d$$ can be considered a constant as well.

Assuming that the time interval used to update the simulation is small compared with the rate of change of the ball velocities, the speed after the interval is simply the original speed decremented by the deceleration times the interval:

$$v_t = v_0 – (a_{rr}+a_d)t$$

The resulting code is:

  /**
* Updates the ball velocity, applying rolling resistance and air drag for a specified time interval
* @param t the time interval to use. Only first-order effects are considered, so the time interval
* must be small compared to the rate of change of the velocity
* @param airDragFactor total air drag factor computed from the ball and air densities and the
* air drag coefficient (assumed to be constant)
* @param rollingResistanceDeceleration total rolling resistance deceleration computed from the
* rolling resistance coefficient and the gravitational acceleration
*/
updateVelocity(t: number, airDragFactor: number, rollingResistanceDeceleration: number) {
var speed2 = this.v * this.v + this.w * this.w;
if (speed2 > 0) {
var airResistanceDeceleration = airDragFactor * speed2 / this.radius;
var totalDeceleration = airResistanceDeceleration + rollingResistanceDeceleration;
var speed = Math.sqrt(speed2);
var newSpeed = speed - totalDeceleration * t;
if (newSpeed <= 0) {
// The ball stopped
this.v = 0;
this.w = 0;
} else {
// Update the speed, keeping the velocity direction the same (the air drag and rolling resistance
// forces are in the exact opposite direction of the velocity)
this.v = this.v * newSpeed / speed;
this.w = this.w * newSpeed / speed;
}
}
} // updateVelocity

Posted in: Physics | Programming