Four particles moving in a plane have masses and velocity components ,

PHYSICS · Subjective · Fermi University Physics · Computational Physics · Scientific programming for physicists · Scientific programming for physicists

Computational Physics, Ch Arrays: a field is a rectangle of numbers

Problem

Four particles moving in a plane have masses m=(1.0,2.0,0.5,3.0) kg\texttt{m} = (1.0, 2.0, 0.5, 3.0)\,\mathrm{kg} and velocity components vx=(2.0,−1.0,4.0,0.0) m s−1\texttt{vx} = (2.0, -1.0, 4.0, 0.0)\,\mathrm{m\,s^{-1}}, vy=(0.0,3.0,−2.0,5.0) m s−1\texttt{vy} = (0.0, 3.0, -2.0, 5.0)\,\mathrm{m\,s^{-1}}, each stored as an array of shape (4,)(4,). The total kinetic energy is currently found by total = 0.0\texttt{total = 0.0} for i in range(4): total += 0.5*m[i]*(vx[i]**2 + vy[i]**2)\texttt{for i in range(4): total += 0.5*m[i]*(vx[i]**2 + vy[i]**2)} (a) Write a single array expression, using no loop, that gives the same total kinetic energy. (b) Evaluate the loop and your array expression for the data above, and state their difference.

Browse the problem library