Knowlet

Unit 3: Advanced Numerical Methods (Lab: PHYDSC354P)

1. Laboratory Objectives

The objective of this final unit is to handle Dynamic Systems. You will learn to solve time-dependent physical equations, such as those describing radioactive decay, pendulum motion, or circuit transients, using advanced numerical algorithms.

2. Solving Ordinary Differential Equations (ODEs)

Most laws of physics are expressed as differential equations (e.g., F = m (d2x) / (dt2)). Numerical methods allow us to find the state of a system at any time t by stepping through time in small increments (h).

3. Euler and Modified Euler Methods

Euler's Method is the simplest numerical procedure for solving ODEs. It assumes the slope of the function is constant over the interval h.

Formula: yn+1 = yn + h · f(xn, yn)

Modified Euler improves accuracy by taking the average of the slopes at the beginning and the end of the interval.

4. Fourth-Order Runge-Kutta (RK4) Method

The RK4 method is the "gold standard" for solving ODEs in undergraduate physics. It provides high accuracy by calculating four different slopes (k1, k2, k3, k4) and taking their weighted average.

# RK4 Step implementation k1 = h * f(x, y) k2 = h * f(x + 0.5*h, y + 0.5*k1) k3 = h * f(x + 0.5*h, y + 0.5*k2) k4 = h * f(x + h, y + k3) y = y + (k1 + 2*k2 + 2*k3 + k4) / 6

5. Monte Carlo Simulations

Monte Carlo methods use random sampling to obtain numerical results. In physics, this is used to simulate stochastic processes or calculate complex integrals.

  • Example: Estimating π: Randomly "throwing darts" at a square containing a circle and calculating the ratio of hits inside the circle.

6. Curve Fitting and Least Squares Method

Experimental data points often have "noise." Least Squares Fitting finds the best-fit line (or curve) that minimizes the sum of the squares of the vertical deviations between each data point and the curve.

from scipy.optimize import curve_fit # Finds optimal parameters for a user-defined function popt, pcov = curve_fit(linear_func, x_data, y_data)

Lab Exam Focus Corner

Frequently Asked Questions

  • What is 'step size' (h) and how does it affect the result? A smaller step size reduces the truncation error but increases computation time and may lead to accumulated round-off errors.
  • When would you choose RK4 over Euler? Always, if accuracy is required. Euler is only used for very simple, non-critical educational demonstrations.

Common Mistakes

  • Global Variables: In C or Python, avoid using the same variable names for "time" and "step count." This often leads to infinite loops in ODE solvers.
  • Floating Point Errors: When checking if a time has reached a limit (e.g., while t < 1.0), use a small buffer like while t < 0.999 to avoid missing the final step due to precision issues.

Practical Tips

Tip: Always plot your numerical solution against the Analytical Solution (if it exists). This "Validation Step" is the only way to prove your code is working correctly.

Did this help you understand better?

Your feedback improves the quality of this resource for everyone.