Lab 07 - Jay1337/computational_physics GitHub Wiki

Goal

For this lab our goal was to learn the technique for implementing numerical integration so that we could write a code to implement the trapezoid method of integration. We then wanted to use this in order to design and implement a Monte Carlo integrator to estimate the half‑circle area, including a visualization of sampled points. Through this lab we would be able to understand integrations like half‑circle area, and gaussian distribution

Overview

This lab takes has us code a basic integrator in order to validate it against both analytic results and a scientific library. This introduces us to and helps us understand a probabilistic integration strategy. In the end, we learned how to implement these methods, and understood why they work, how their errors behave, and why one approach might be over another.

Part 1

In part 1 we wrote a function to implement the trapezoid integration method which looped over each x_i and x_i+1 pair in order to compute the area of the trapezoid with heights y_i and y_i+1 and sum them. This established a basic general-purpose integrator which we applied in the later parts of this lab. image

Part 2

In part 2 we defined a function in order to get the y values for our half circle so that we could use the x and y values to calculate the integral so that we get the area under the half circle. image

Part 3

This part involves defining a function that can integrate/calculate the gaussian distribution, and our code and its accuracy in this show that even a simple trapezoid method can handle smoothly varying functions like gaussian distribution. image

Part 4

Here we use python built in functions to complete the half circle area integration and gaussian distribution integral we computed earlier. Doing so proved how possible and plausible it is using these functions we created compared to the trusted optimized tools inside python. image

Part 5

This last part uses code to show randomly generated points colored by whether they lie inside or outside the half‑circle, plus the true boundary curve. This shows how randomness can approximate an area, and how the quality improves as you draw more samples. image image