Courses / Physics I
Computer Science

Integrated computational problem solving

Physics I 260 words Free to read

This lesson combines algorithms, data structures, numerical methods, and visualisation into complete scientific workflows.

Typical computational physics pipeline

Define problem → Model equations → Implement code
    → Validate → Run simulation → Analyse & visualise

Example: projectile with drag

import numpy as np
import matplotlib.pyplot as plt

g, b = 9.8, 0.1          # gravity, drag coefficient
dt, t_max = 0.01, 10.0
N = int(t_max / dt)

x = np.zeros(N); y = np.zeros(N)
vx = np.full(N, 20.0); vy = np.full(N, 30.0)

for i in range(1, N):
    speed = np.sqrt(vx[i-1]**2 + vy[i-1]**2)
    vx[i] = vx[i-1] - b * speed * vx[i-1] * dt
    vy[i] = vy[i-1] - (g + b * speed * vy[i-1]) * dt
    x[i]  = x[i-1] + vx[i] * dt
    y[i]  = y[i-1] + vy[i] * dt
    if y[i] < 0:
        break

plt.plot(x[:i], y[:i])
plt.xlabel("x (m)"); plt.ylabel("y (m)")
plt.title("Projectile with Air Resistance")
plt.grid(True); plt.show()

Workflow checklist

  1. Model — Write the governing equations (here: Newton's second law with drag).
  2. Discretise — Choose a numerical method and time step.
  3. Code — Implement with clear variable names and modular functions.
  4. Validate — Check limiting cases (e.g., b=0b=0 should give parabolic trajectory).
  5. Visualise — Plot results and compare with expectations.
Strategy: Start simple (no drag, no friction) and add complexity incrementally. Each addition should be validated before proceeding to the next.
Common pitfall: Premature optimization wastes more effort than slow code ever did: first make it correct and clear, then measure, and only then speed up the part the measurement actually indicts.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

13practice questions
2interactive scenes
Start Physics I free

Computer Science